RPG项目01_UI面板Game

基于“RPG项目01_技能释放”,将UI包导入Unity场景中,

将图片放置

拖拽

取消勾选(隐藏攻击切片)

对技能添加蒙版

调节父子物体大小一致

将子类蒙版复制

执行5次

运行即可看到技能使用完的冷却条

在Scripts下创建UI文件夹

写代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class UIBase : MonoBehaviour
{
    public Transform btnParent;
    public GameObject prefab;
    public UnityAction<int> funClickHandle;
    public UITween tween;
    protected List<RectTransform> childRect = new List<RectTransform>();
    protected Button btnBack;
    protected Text text;

    protected void Init()
    {
        tween = GetComponent<UITween>();
        btnBack = GameManager.FindType<Button>(transform, "BtnX");
        btnBack.onClick.AddListener(tween.UIBack);
    }
    protected void ClearBtn(Transform parent) {
        foreach (Transform t in parent) {
            Destroy(t.gameObject);
        }
    }
    public virtual void UpdateValue() {
    
    }
    public virtual void MenuStart(params UITween[] uis) {
        foreach (UITween item in uis) { 
            item.UIStart();
        }
    }
}
再UI文件夹下创建PlayerPanel代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerPanel : UIBase
{
    [Header("==============子类变量================")]
    public UIBase panelMsn;
    public UIBase panelBag;
    Button btnMsn;
    Button btnBag;
    static Image hpImage;
    static Image mpImage;
    void Start()
    {
        hpImage = GameManager.FindType<Image>(transform, "MainUI/Hp");
        mpImage = GameManager.FindType<Image>(transform, "MainUI/Mp");
        btnMsn = GameManager.FindType<Button>(transform, "BtnMission");
        btnBag = GameManager.FindType<Button>(transform
            , "BtnBag");
        btnMsn.onClick.AddListener(delegate
        {
            panelMsn.MenuStart(panelMsn.GetComponent<UITween>());
        });
        btnBag.onClick.AddListener(delegate
        {
            //获取全部挂在UITween脚本的组件形成数组不定参数
            panelBag.MenuStart(panelBag.GetComponentsInChildren<UITween>());
        });
        for (int i = 0; i < btnParent.childCount; i++)
        {
            Button btn = GameManager.FindType<Button>(btnParent, "BtnSkill" + i);
            int n = i;
            btn.onClick.AddListener(delegate {
                MainGame.player.SkillClick(n + 1);
            });
        }
    }

    //刷新血量
    public static void UpdateHpUI(float hpValue, float mpValue)
    {
        hpImage.fillAmount = hpValue;
        mpImage.fillAmount = mpValue;
    }
}
将PalyerPanel挂载在MainPanel上

新增MaPlayer代码:

protected override void UpdateUI()
    {
        PlayerPanel.UpdateHpUI(GetHpRation(), (float)Mp/MpMax);
    }

将初始mp/最大mp调少一点:

运行E拔刀后F1释放技能即可看到mp蓝条减少

添加代码:

public void SkillClick(int num)
    {
        if (!Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight"))
        {
            return;
        }
        SkillBase skill = skills[num];
        if (!skill.MayRelease())
        {
            return;
        }
        Anim.SetTrigger("CSkill" + num);
        ReleaseSkill(skill);
    }

选中技能1-6添加Button组件

新增PlayerPanel代码:(找到按钮)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++点击技能释放技能缺少button事件+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

加入新按钮,

删除旧按钮,

新增两个到Bag包下

删除两个

delete

挪动Text位置

复制道具框,

在Content上增加尺寸适配器组件(自动计算)通常和Grid Layout Group配合使用

设置自动隐藏(当需要滚动条的时候显示,不需要时隐藏)

此时,两侧面板基本完成

新建代码BagPanel

代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BagPanel : UIBase{
    Transform canvas;
    Transform bagTran;
    Transform equipTran;
    Button btnTakeOff;
    Text textHp;
    Text textMp;
    Text textLv;
    Text textExp;
    Text textAtt;
    Text textDef;
    Text textSpd;
    Text textMdf;
    private void Start(){  
    }
    public void InitText(){
        canvas = MainGame.canvas;
        bagTran = transform.Find("Bag");
        equipTran = transform.Find("Equip");
        text = GameManager.FindType<Text>(bagTran, "TextGold");
        Transform temp = equipTran.Find("TextParent");
        textHp = GameManager.FindType<Text>(temp, "TextHp");
        textMp = GameManager.FindType<Text>(temp, "TextMp");
        textLv = GameManager.FindType<Text>(temp, "TextLv");
        textExp = GameManager.FindType<Text>(temp, "TextExp");
        textAtt = GameManager.FindType<Text>(temp, "TextAtt");
        textDef = GameManager.FindType<Text>(temp, "TextDef");
        textSpd = GameManager.FindType<Text>(temp, "TextSpd");
        textMdf = GameManager.FindType<Text>(temp, "TextMdf");
    }
}
新增MainPanel代码类段代码:


 Message.CheckMessage();

修改Text为TextGold

在Canvas下创建Image

选一张图片

添加组件

添加组件

添加事件类型

再做一下鼠标移动到图标就会消失功能:

鼠标到图标位置,图标就会消失

知识点:如果用Selectable和Event Trigger就可以替代Button按钮做更复杂的UI

新建脚本道具类GameObj

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//药品,装备
public enum ObjType { None, Drug, Equip };
//装备包含:
public enum EquipType { None, Helmet, Armor, Boots, Weapon, Shield };
//装备数据
public class GameObj{
    public string oname;
    public string msg;
    public int idx;
    public string type;
    public int _hp;
    public int _mp;
    public int _def;
    public int _mdf;
    public int _att;
    public int _spd;
    public bool isTakeOn;//判断是否穿上
    public virtual void UseObjValue(){

    }
    public virtual void TakeOff(){

    }
    public virtual void TakeOn(){

    }
}
修改BagPanel代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class BagPanel : UIBase{
    Transform canvas;
    Transform bagTran;
    Transform equipTran;
    Button btnTakeOff;
    Text textHp;
    Text textMp;
    Text textLv;
    Text textExp;
    Text textAtt;
    Text textDef;
    Text textSpd;
    Text textMdf;
    void Start(){  
    }
    public void InitText(){
        canvas = MainGame.canvas;
        bagTran = transform.Find("Bag");
        equipTran = transform.Find("Equip");
        text = GameManager.FindType<Text>(bagTran, "TextGold");
        Transform temp = equipTran.Find("TextParent");
        textHp = GameManager.FindType<Text>(temp, "TextHp");
        textMp = GameManager.FindType<Text>(temp, "TextMp");
        textLv = GameManager.FindType<Text>(temp, "TextLv");
        textExp = GameManager.FindType<Text>(temp, "TextExp");
        textAtt = GameManager.FindType<Text>(temp, "TextAtt");
        textDef = GameManager.FindType<Text>(temp, "TextDef");
        textSpd = GameManager.FindType<Text>(temp, "TextSpd");
        textMdf = GameManager.FindType<Text>(temp, "TextMdf");
    }
    void AddEvent(GameObj obj, GameObject btn)
    {
        Image image = btn.GetComponent<Image>();
        EventTrigger et = btn.GetComponent<EventTrigger>();
        if (!et)
        {
            et = btn.AddComponent<EventTrigger>();
        }
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.BeginDrag;//开始拖拽
        entry.callback.AddListener(delegate
        {
            image.raycastTarget = false;
            btn.transform.SetParent(canvas);
        }
        );
        et.triggers.Add(entry);
        //
        entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.Drag;//拖拽中
        entry.callback.AddListener(delegate (BaseEventData arg)
        {
            PointerEventData ped = (PointerEventData)arg;//将基础数据变成鼠标数据
            Vector3 newPos;
            RectTransformUtility.ScreenPointToWorldPointInRectangle(
                btn.GetComponent<RectTransform>(), Mouse.current.position.ReadValue(),//在摄像机视角下鼠标当前坐标转换过去
                ped.enterEventCamera, out newPos);
            btn.transform.position = newPos;
        }
        );
        et.triggers.Add(entry);
        /;
        entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.EndDrag;//结束拖拽
        entry.callback.AddListener(delegate (BaseEventData arg)
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                btn.transform.parent = btnParent;
                image.raycastTarget = true;
                return;
            }
            PointerEventData ped = (PointerEventData)arg;
            Transform target = ped.pointerEnter.transform;
            if (target)
            {
                if (target.tag == obj.GetType().ToString())
                {
                    obj.TakeOn();
                    //交换装备
                    ChangeGameObj(target.parent, btn);
                    //刷新数值
                    UpdatePlayerValue();
                }
                else if (target.name == obj.GetType().ToString() || target.name == obj.type)
                {
                    //交换药品
                    ChangeGameObj(target, btn);
                }
                else
                {
                    obj.isTakeOn = false;
                    btn.transform.parent = btnParent;
                }
            }
            image.raycastTarget = true;
        }
        );
        et.triggers.Add(entry);
        /
        entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;//拖拽中
        entry.callback.AddListener(delegate (BaseEventData arg)
        {
            if (btn.tag != ObjType.Drug.ToString())
            {
                return;
            }
            //MainGame.player.UseDrugObj(btn.transform);
        }
        );
        et.triggers.Add(entry);
    }
    //刷新玩家数据
    public void UpdatePlayerValue()
    {
        textHp.text = "生命:" + MainGame.player.Hp + "/" + MainGame.player.HpMax;
        textMp.text = "魔力:" + MainGame.player.Mp + "/" + MainGame.player.MpMax;
        textAtt.text = "攻击:" + MainGame.player.Att;
        textDef.text = "防御:" + MainGame.player.Def;
        textMdf.text = "魔抗:" + MainGame.player.Mdf;
        textSpd.text = "速度:" + MainGame.player.Spd;
        textLv.text = "等级:" + MainGame.player.lv;
        textExp.text = "经验:" + MainGame.player.Exp;
    }
    void ChangeGameObj(Transform target, GameObject btn)
    {
        GameObj temp = new GameObj();
        if (target.childCount >= 2)
        {
            //temp = GameManager.GetGameObj(target.GetChild(0).name);
            //SetBtnTakeOff(target.GetChild(0), temp);
        }
        btn.transform.parent = target.transform;
        btn.transform.SetAsFirstSibling();
        btn.transform.localPosition = Vector3.zero;
        btn.GetComponent<RectTransform>().sizeDelta = target.GetComponent<RectTransform>().sizeDelta;
        //temp = GameManager.GetGameObj(btn.name);
        if (temp != null)
        {
            temp.isTakeOn = true;
        }

    }
    void SetBtnTakeOff(Transform btn, GameObj obj)
    {
        if (obj != null)
        {
            btn.parent = btnParent;
            obj.isTakeOn = false;
            btn.GetComponent<Image>().raycastTarget = true;
        }
    }
}
修改GameManager类:

using System.Collections.Generic;
using System.Xml;
using Unity.VisualScripting;
using UnityEngine;
public enum GameState { Play,Menu };
public class GameManager
{
    //当只需要一个的时候使用静态类
    public static GameState gameState = GameState.Play;
    //物品库
    public static Dictionary<string, GameObj> goods = new Dictionary<string, GameObj>();
    public static void Init()
    {

    }
    public static T FindType<T>(Transform t, string n)
    {
        return t.Find(n).GetComponent<T>();
    }
    public static T ParseEnum<T>(string value)
    {
        return (T)System.Enum.Parse(typeof(T), value, true);
    }
    #region 添加物品库
    //读取XML文件
    public static void SetGoods()
    {
        TextAsset t = LoadManager.LoadXml("XML");
        XmlDocument xml = new XmlDocument();
        xml.LoadXml(t.ToString().Trim());
        XmlElement root = xml.DocumentElement;
        XmlElement oInfo = (XmlElement)root.SelectSingleNode("DrugInfo");
        //节点列表 获取所有子节点
        XmlNodeList nodeList = oInfo.ChildNodes;
        foreach (XmlElement item in nodeList)
        {
            //Drug drug = new Drug();
            //drug.oname = item.GetAttribute("Name");
            //drug.msg = item.GetAttribute("Msg");
            //drug.idx = int.Parse(item.GetAttribute("Idx"));
            //drug.type = item.GetAttribute("Type");
            //drug._hp = int.Parse(item.GetAttribute("Hp"));
            //drug._mp = int.Parse(item.GetAttribute("Mp"));
            //AddGoodDict(drug);
        }
       
        //    oInfo = (XmlElement)root.SelectSingleNode("EquipInfo");
        //    nodeList = oInfo.ChildNodes;//每一个节点
        //    foreach (XmlElement item in nodeList)
        //    {
        //        Equip eq = new Equip();
        //        eq.oname = item.GetAttribute("Name");
        //        eq.msg = item.GetAttribute("Msg");
        //        eq.idx = int.Parse(item.GetAttribute("Idx"));
        //        eq.type = item.GetAttribute("Type");
        //        eq._att = int.Parse(item.GetAttribute("Att"));
        //        eq._def = int.Parse(item.GetAttribute("Def"));
        //        eq._mdf = int.Parse(item.GetAttribute("Mdf"));
        //        eq._spd = int.Parse(item.GetAttribute("Spd"));
        //        AddGoodDict(eq);
        //    }
        //}
        //public static void AddGoodDict(GameObj obj)
        //{
        //    if (obj == null)
        //    {
        //        return;
        //    }
        //    goods.Add(obj.oname, obj);
        //}
        //public static GameObj GetGameObj(string name)
        //{
        //    if (goods.ContainsKey(name))
        //    {
        //        return goods[name];
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}
        //public static GameObj GetGameObj(int idx)
        //{
        //    foreach (GameObj item in goods.Values)
        //    {
        //        if (item.idx == idx)
        //        {
        //            return item;
        //        }
        //    }
        //    return null;
        //}
        #endregion
    }
}
新建脚本药品类Drug

代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Drug : GameObj
{
    public override void UseObjValue()
    {
        MainGame.player.AddHp(_hp);
        MainGame.player.AddMp(_mp);
    }
}
继续修改GameManager代码:

using System.Collections.Generic;
using System.Xml;
using Unity.VisualScripting;
using UnityEngine;
public enum GameState { Play,Menu };
public class GameManager
{
    //当只需要一个的时候使用静态类
    public static GameState gameState = GameState.Play;
    //物品库
    public static Dictionary<string, GameObj> goods = new Dictionary<string, GameObj>();
    public static void Init()
    {

    }
    public static T FindType<T>(Transform t, string n)
    {
        return t.Find(n).GetComponent<T>();
    }
    public static T ParseEnum<T>(string value)
    {
        return (T)System.Enum.Parse(typeof(T), value, true);
    }
    #region 添加物品库
    //读取XML文件
    public static void SetGoods()
    {
        TextAsset t = LoadManager.LoadXml("XML");
        XmlDocument xml = new XmlDocument();
        xml.LoadXml(t.ToString().Trim());
        XmlElement root = xml.DocumentElement;
        XmlElement oInfo = (XmlElement)root.SelectSingleNode("DrugInfo");
        //节点列表 获取所有子节点
        XmlNodeList nodeList = oInfo.ChildNodes;
        foreach (XmlElement item in nodeList)
        {
            Drug drug = new Drug();
            drug.oname = item.GetAttribute("Name");
            drug.msg = item.GetAttribute("Msg");
            drug.idx = int.Parse(item.GetAttribute("Idx"));
            drug.type = item.GetAttribute("Type");
            drug._hp = int.Parse(item.GetAttribute("Hp"));
            drug._mp = int.Parse(item.GetAttribute("Mp"));
            AddGoodDict(drug);
        }
       
        //oInfo = (XmlElement)root.SelectSingleNode("EquipInfo");
        //nodeList = oInfo.ChildNodes;//每一个节点
        //foreach (XmlElement item in nodeList)
        //{
        //    Equip eq = new Equip();
        //    eq.oname = item.GetAttribute("Name");
        //    eq.msg = item.GetAttribute("Msg");
        //    eq.idx = int.Parse(item.GetAttribute("Idx"));
        //    eq.type = item.GetAttribute("Type");
        //    eq._att = int.Parse(item.GetAttribute("Att"));
        //    eq._def = int.Parse(item.GetAttribute("Def"));
        //    eq._mdf = int.Parse(item.GetAttribute("Mdf"));
        //    eq._spd = int.Parse(item.GetAttribute("Spd"));
        //    AddGoodDict(eq);
        //}
    }
    public static void AddGoodDict(GameObj obj)
        {
            if (obj == null)
            {
                return;
            }
            goods.Add(obj.oname, obj);
        }
        //public static GameObj GetGameObj(string name)
        //{
        //    if (goods.ContainsKey(name))
        //    {
        //        return goods[name];
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}
        //public static GameObj GetGameObj(int idx)
        //{
        //    foreach (GameObj item in goods.Values)
        //    {
        //        if (item.idx == idx)
        //        {
        //            return item;
        //        }
        //    }
        //    return null;
        //}
        #endregion
    
}
再创建Equip道具类

代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Equip : GameObj
{
    public override void TakeOff()
    {
        //
    }
}
继续修改GameManager类:

using System.Collections.Generic;
using System.Xml;
using Unity.VisualScripting;
using UnityEngine;
public enum GameState { Play,Menu };
public class GameManager
{
    //当只需要一个的时候使用静态类
    public static GameState gameState = GameState.Play;
    //物品库
    public static Dictionary<string, GameObj> goods = new Dictionary<string, GameObj>();
    public static void Init()
    {
        SetGoods();
    }
    public static T FindType<T>(Transform t, string n)
    {
        return t.Find(n).GetComponent<T>();
    }
    public static T ParseEnum<T>(string value)
    {
        return (T)System.Enum.Parse(typeof(T), value, true);
    }
    #region 添加物品库
    //读取XML文件
    public static void SetGoods()
    {
        TextAsset t = LoadManager.LoadXml("XML");
        XmlDocument xml = new XmlDocument();
        xml.LoadXml(t.ToString().Trim());
        XmlElement root = xml.DocumentElement;
        XmlElement oInfo = (XmlElement)root.SelectSingleNode("DrugInfo");
        //节点列表 获取所有子节点
        XmlNodeList nodeList = oInfo.ChildNodes;
        foreach (XmlElement item in nodeList)
        {
            Drug drug = new Drug();
            drug.oname = item.GetAttribute("Name");
            drug.msg = item.GetAttribute("Msg");
            drug.idx = int.Parse(item.GetAttribute("Idx"));
            drug.type = item.GetAttribute("Type");
            drug._hp = int.Parse(item.GetAttribute("Hp"));
            drug._mp = int.Parse(item.GetAttribute("Mp"));
            AddGoodDict(drug);
        }
       
        oInfo = (XmlElement)root.SelectSingleNode("EquipInfo");
        //节点列表 获取所有子节点
        nodeList = oInfo.ChildNodes;
        foreach (XmlElement item in nodeList)
        {
            //alt + 回车 一键全改错误eq
            Equip eqq = new Equip();
            eqq.oname = item.GetAttribute("Name");
            eqq.msg = item.GetAttribute("Msg");
            eqq.idx = int.Parse(item.GetAttribute("Idx"));
            eqq.type = item.GetAttribute("Type");
            eqq._att = int.Parse(item.GetAttribute("Att"));
            eqq._def = int.Parse(item.GetAttribute("Def"));
            eqq._mdf = int.Parse(item.GetAttribute("Mdf"));
            eqq._spd = int.Parse(item.GetAttribute("Spd"));
            AddGoodDict(eqq);
        }
    }
    public static void AddGoodDict(GameObj obj)
        {
            if (obj == null)
            {
                return;
            }
            goods.Add(obj.oname, obj);
        }
    public static GameObj GetGameObj(string name)
    {
        if (goods.ContainsKey(name))
        {
            return goods[name];
        }
        else
        {
            return null;
        }
    }
    public static GameObj GetGameObj(int idx)
    {
        foreach (GameObj item in goods.Values)
        {
            if (item.idx == idx)
            {
                return item;
            }
        }
        return null;
    }
    #endregion

}
修改BagPanel类:

修改背包面板BagPanel代码,在Start下加内容:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class BagPanel : UIBase{
    Transform canvas;
    Transform bagTran;
    Transform equipTran;
    Button btnTakeOff;
    Text textHp;
    Text textMp;
    Text textLv;
    Text textExp;
    Text textAtt;
    Text textDef;
    Text textSpd;
    Text textMdf;
    void Start(){
        InitText();
        btnTakeOff = GameManager.FindType<Button>(equipTran, "BtnTakeOff");
        btnTakeOff.onClick.AddListener(delegate
        {
            foreach (Transform item in equipTran.Find("Eq"))
            {
                if (item.childCount >= 2)
                {
                    GameObj temp = GameManager.GetGameObj(item.GetChild(0).name);
                    temp.TakeOff();
                    UpdatePlayerValue();
                    SetBtnTakeOff(item.GetChild(0), temp);
                }
            }
        });
        tween = bagTran.GetComponent<UITween>();
        tween.AddEventStartHandle(UpdateValue);
        btnBack = GameManager.FindType<Button>(bagTran, "BtnX");
        btnBack.onClick.AddListener(delegate
        {
            tween.UIBack();
            equipTran.GetComponent<UITween>().UIBack();
        });
    }
    public void InitText(){
        canvas = MainGame.canvas;
        bagTran = transform.Find("Bag");
        equipTran = transform.Find("Equip");
        text = GameManager.FindType<Text>(bagTran, "TextGold");
        Transform temp = equipTran.Find("TextParent");
        textHp = GameManager.FindType<Text>(temp, "TextHp");
        textMp = GameManager.FindType<Text>(temp, "TextMp");
        textLv = GameManager.FindType<Text>(temp, "TextLv");
        textExp = GameManager.FindType<Text>(temp, "TextExp");
        textAtt = GameManager.FindType<Text>(temp, "TextAtt");
        textDef = GameManager.FindType<Text>(temp, "TextDef");
        textSpd = GameManager.FindType<Text>(temp, "TextSpd");
        textMdf = GameManager.FindType<Text>(temp, "TextMdf");
    }
    void AddEvent(GameObj obj, GameObject btn)
    {
        Image image = btn.GetComponent<Image>();
        EventTrigger et = btn.GetComponent<EventTrigger>();
        if (!et)
        {
            et = btn.AddComponent<EventTrigger>();
        }
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.BeginDrag;//开始拖拽
        entry.callback.AddListener(delegate
        {
            image.raycastTarget = false;
            btn.transform.SetParent(canvas);
        }
        );
        et.triggers.Add(entry);
        //
        entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.Drag;//拖拽中
        entry.callback.AddListener(delegate (BaseEventData arg)
        {
            PointerEventData ped = (PointerEventData)arg;//将基础数据变成鼠标数据
            Vector3 newPos;
            RectTransformUtility.ScreenPointToWorldPointInRectangle(
                btn.GetComponent<RectTransform>(), Mouse.current.position.ReadValue(),//在摄像机视角下鼠标当前坐标转换过去
                ped.enterEventCamera, out newPos);
            btn.transform.position = newPos;
        }
        );
        et.triggers.Add(entry);
        /;
        entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.EndDrag;//结束拖拽
        entry.callback.AddListener(delegate (BaseEventData arg)
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                btn.transform.parent = btnParent;
                image.raycastTarget = true;
                return;
            }
            PointerEventData ped = (PointerEventData)arg;
            Transform target = ped.pointerEnter.transform;
            if (target)
            {
                if (target.tag == obj.GetType().ToString())
                {
                    obj.TakeOn();
                    //交换装备
                    ChangeGameObj(target.parent, btn);
                    //刷新数值
                    UpdatePlayerValue();
                }
                else if (target.name == obj.GetType().ToString() || target.name == obj.type)
                {
                    //交换药品
                    ChangeGameObj(target, btn);
                }
                else
                {
                    obj.isTakeOn = false;
                    btn.transform.parent = btnParent;
                }
            }
            image.raycastTarget = true;
        }
        );
        et.triggers.Add(entry);
        /
        entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;//拖拽中
        entry.callback.AddListener(delegate (BaseEventData arg)
        {
            if (btn.tag != ObjType.Drug.ToString())
            {
                return;
            }
            //MainGame.player.UseDrugObj(btn.transform);
        }
        );
        et.triggers.Add(entry);
    }
    //刷新玩家数据
    public void UpdatePlayerValue()
    {
        textHp.text = "生命:" + MainGame.player.Hp + "/" + MainGame.player.HpMax;
        textMp.text = "魔力:" + MainGame.player.Mp + "/" + MainGame.player.MpMax;
        textAtt.text = "攻击:" + MainGame.player.Att;
        textDef.text = "防御:" + MainGame.player.Def;
        textMdf.text = "魔抗:" + MainGame.player.Mdf;
        textSpd.text = "速度:" + MainGame.player.Spd;
        textLv.text = "等级:" + MainGame.player.lv;
        textExp.text = "经验:" + MainGame.player.Exp;
    }
    void ChangeGameObj(Transform target, GameObject btn)
    {
        GameObj temp = new GameObj();
        if (target.childCount >= 2)
        {
            temp = GameManager.GetGameObj(target.GetChild(0).name);
            SetBtnTakeOff(target.GetChild(0), temp);
        }
        btn.transform.parent = target.transform;
        btn.transform.SetAsFirstSibling();
        btn.transform.localPosition = Vector3.zero;
        btn.GetComponent<RectTransform>().sizeDelta = target.GetComponent<RectTransform>().sizeDelta;
        temp = GameManager.GetGameObj(btn.name);
        if (temp != null)
        {
            temp.isTakeOn = true;
        }

    }
    void SetBtnTakeOff(Transform btn, GameObj obj)
    {
        if (obj != null)
        {
            btn.parent = btnParent;
            obj.isTakeOn = false;
            btn.GetComponent<Image>().raycastTarget = true;
        }
    }
}
新增BagPanel代码:

public override void UpdateValue()
    {
        ClearBtn(btnParent);
        //暂时写不了,需要新增MyPlayer代码的函数
    }

新增MyPlayer代码:

添加一个方法

修改MyPlayer代码,利用xml文档的函数添加两个道具

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;

public class MyPlayer : People
{

    [Header("=================子类变量=================")]
    public Transform toolPanel;//道具面板
    public Transform skillPanel;//技能面板
    public BagPanel bag;//包

    CharacterController contro;
    Controls action;

    float rvalue;
    float spdFast = 1;
    bool isHold;//握住刀
    GameObject sword;
    GameObject swordBack;
    public Image imageHp;
    public Image imageMp;
    //bagTools = 背包工具
    Dictionary<GameObj, int> bagTools = new Dictionary<GameObj, int>();
    Dictionary<EquipType, Equip> equips = new Dictionary<EquipType, Equip>();
    void Start()
    {
        //base.Start();
        InitValue();
        InitSkill();
        //获取自身角色控制器
        contro = GetComponent<CharacterController>();
        SetInput();
        sword = transform.Find("Sword_Hand").gameObject;
        swordBack = transform.Find("Sword_Back").gameObject;
        bag.InitText();
        // AddTool(GameManager.GetGameObj("大还丹"), 5);
        //3.5.7.6是xml文档里的道具(数字是编号)
        //作用是利用xml文档里添加两个道具
        AddTool(GameManager.GetGameObj(3), 5);
        AddTool(GameManager.GetGameObj(7), 6);
    }
    void Update()
    {
        if (GameManager.gameState != GameState.Play)
        {
            return;
        }
        Ctrl();
        UpdateSkillTime();
    }
    void SetInput()
    {
        action = new Controls();
        action.Enable();
        action.MyCtrl.Move.started += Move;
        action.MyCtrl.Move.performed += Move;
        action.MyCtrl.Move.canceled += StopMove;
        action.MyCtrl.Jump.started += Jump;
        action.MyCtrl.Rotate.started += Rotate;
        action.MyCtrl.Rotate.performed += Rotate;
        action.MyCtrl.Fast.started += FastSpeed;
        action.MyCtrl.Fast.performed += FastSpeed;
        action.MyCtrl.Fast.canceled += FastSpeed;
        action.MyCtrl.GetTool.started += ClickNpcAndTool;
        action.MyCtrl.HoldRotate.performed += Hold;
        action.MyCtrl.HoldRotate.canceled += Hold;
        action.MyAtt.Att.started += Attack;
        action.MyAtt.SwordOut.started += SwordOut;
        action.Skill.F1.started += SkillAtt;
        action.Skill.F2.started += SkillAtt;
        action.Skill.F3.started += SkillAtt;
        action.Skill.F4.started += SkillAtt;
        action.Skill.F5.started += SkillAtt;
        action.Skill.F6.started += SkillAtt;
       // action.Tools._1.started += GetkeyClick;
       // action.Tools._2.started += GetkeyClick;
       // action.Tools._3.started += GetkeyClick;
      //  action.Tools._4.started += GetkeyClick;
        //action.Tools._5.started += GetkeyClick;
        //action.Tools._6.started += GetkeyClick;
        //action.Tools._7.started += GetkeyClick;
        //action.Tools._8.started += GetkeyClick;
    }

    private void GetkeyClick(InputAction.CallbackContext context)
    {
        string[] str = context.control.ToString().Split('/');
        int num = int.Parse(str[2]) - 1;
     // UseObj(num);
    }

    private void SwordOut(InputAction.CallbackContext context)
    {
        if (GameManager.gameState != GameState.Play)
        {
            return;
        }
        Anim.SetBool("SwordOut", !Anim.GetBool("SwordOut"));
    }
    #region 攻击
    void SetSwordVisible(int n)
    {
        sword.SetActive(n != 0);
        swordBack.SetActive(n == 0);
    }
    private void Attack(InputAction.CallbackContext context)
    {
        if (GameManager.gameState != GameState.Play)
        {
            return;
        }
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }
        if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight"))
        {
            Anim.SetInteger("Att", 1);
            Anim.SetTrigger("AttTrigger");

        }
        else
        {
            int num = Anim.GetInteger("Att");
            if (num == 6)
            {
                return;
            }
            if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Light_Attk_" + num))
            {
                Anim.SetInteger("Att", num + 1);
            }
        }
    }
    public void PlayerAttack(string hurt)
    {
        Collider[] cs = Physics.OverlapBox(attPoint.position, Vector3.one * 0.5f,
            attPoint.rotation, LayerMask.GetMask("Enemy"));
        if (cs.Length <= 0)
        {
            return;
        }
        int value = (int)(Att * Anim.GetInteger("Att") * 0.5f);
        foreach (Collider c in cs)
        {
            print(value);
        }
    }

    public void PlayerAttackHard(string hurt)
    {
        Collider[] cs = Physics.OverlapBox(attPoint.position, Vector3.one * 0.5f,
  
           attPoint.rotation, LayerMask.GetMask("Enemy"));
        if (cs.Length <= 0)
        {
            return;
        }
        int value = (int)(Att * Anim.GetInteger("Att") * 0.5f);
        foreach (Collider c in cs)
        {
            print(value);
            print("让敌人播放击倒特效");
        }
    }
    #endregion

    #region 人物控制
    void Ctrl()
    {
        if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") || Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace") || Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle")
            || Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight"))
        {
            float f = action.MyCtrl.Move.ReadValue<float>();
            contro.Move(transform.forward * f * Time.deltaTime * spdFast * Spd);
            contro.Move(transform.up * -9.8f * Time.deltaTime);
            if (isHold)
            {
                transform.Rotate(transform.up * rvalue * 0.3f);
            }

        }
    }
    private void Hold(InputAction.CallbackContext context)
    {
        if (GameManager.gameState != GameState.Play)
        {
            return;
        }
        if (context.phase == InputActionPhase.Canceled)
        {
            isHold = false;
        }
        else
        {
            isHold = true;
        }
    }
    private void ClickNpcAndTool(InputAction.CallbackContext context)
    {
        //throw new NotImplementedException();
    }

    private void FastSpeed(InputAction.CallbackContext context)
    {
        if (GameManager.gameState != GameState.Play)
        {
            return;
        }
        if (Anim.GetCurrentAnimatorStateInfo(0).IsName("Run") || Anim.GetCurrentAnimatorStateInfo(0).IsName("Run_Inplace"))
        {
            if (context.phase == InputActionPhase.Canceled)
            {
                spdFast = 1;
            }
            else
            {
                spdFast = 2;
            }
        }
    }

    private void Rotate(InputAction.CallbackContext context)
    {
        if (GameManager.gameState != GameState.Play)
        {
            return;
        }
        rvalue = context.ReadValue<float>();
    }

    private void Jump(InputAction.CallbackContext context)
    {
        if (GameManager.gameState != GameState.Play)
        {
            return;
        }
        Anim.SetTrigger("Jump");
    }

    private void StopMove(InputAction.CallbackContext context)
    {
        Anim.SetBool("IsRun", false);
    }

    private void Move(InputAction.CallbackContext context)
    {
        if (GameManager.gameState != GameState.Play)
        {
            return;
        }
        Anim.SetBool("IsRun", true);
    }


    #endregion

    #region 技能
    protected override void InitSkill()
    {
        SphereSkill thunderBombCut = new SphereSkill(this, "雷爆斩", SkillType.Magic, 3, Att * 10, -100, 20, 0.3f, 0);
        skills.Add(1, thunderBombCut);

        SphereSkill windCircleCut = new SphereSkill(this, "旋风斩", SkillType.Physics, 3, Att * 8, -50, 20, 0.2f, 0);
        skills.Add(2, windCircleCut);

        StraightSkill thunderLightCut = new StraightSkill(this, "雷光斩", SkillType.Physics, 7, 0.5f, Att * 7, -50, 20, 0.2f, 0);
        skills.Add(3, thunderLightCut);

        SphereSkill oneCut = new SphereSkill(this, "归一斩", SkillType.Physics, 7, Att * 7, -30, 8, 0.2f, 0);
        skills.Add(4, oneCut);

        StraightSkill crossCut = new StraightSkill(this, "十字斩", SkillType.Physics, 25, 0.5f, Att * 3, -40, 20, 0.2f, 0);
        skills.Add(5, crossCut);


        SphereSkill thunderLargeCut = new SphereSkill(this, "轰雷斩", SkillType.Magic, 7, Att * 15, -120, 25, 0.35f, 0);
        skills.Add(6, thunderLargeCut);
    }
    private void SkillAtt(InputAction.CallbackContext context)
    {
        if (!Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight"))
        {
            return;
        }
        string[] str = context.control.ToString().Split('/');
        int num = int.Parse(str[2][1].ToString());
        SkillBase skill = skills[num];
        if (!skill.MayRelease())
        {
            return;
        }
        Anim.SetTrigger("CSkill" + num);
        ReleaseSkill(skill);
    }

    public void SkillClick(int num)
    {
        if (!Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle_Fight"))
        {
            return;
        }
        SkillBase skill = skills[num];
        if (!skill.MayRelease())
        {
            return;
        }
        Anim.SetTrigger("CSkill" + num);
        ReleaseSkill(skill);
    }

    void UpdateSkillTime()
    {
        for (int i = 0; i < skillPanel.childCount; i++)
        {
            if (skills[i + 1].IsRelease)
            {
                continue;
            }
            Image image = skillPanel.GetChild(i).GetChild(0).GetComponent<Image>();
            image.fillAmount = skills[i + 1].GetFillTime();
        }
    }
    #endregion

    protected override void UpdateUI()
    {
        PlayerPanel.UpdateHpUI(GetHpRation(), (float)Mp/MpMax);
    }

    #region 物品道具
    public Dictionary<GameObj, int> GetTools()
    {
        return bagTools;
    }
    public void AddTool(GameObj gObj, int num)
    {
        if (gObj == null)
        {
            return;
        }
        GameObj temp = GameManager.GetGameObj(gObj.oname);
        if (bagTools.ContainsKey(temp))
        {
            bagTools[temp] += num;
        }
        else
        {
            // bagTools[temp] = num;
            bagTools.Add(gObj, num);
        }
        bag.UpdateValue();
    }
    //public void UseDrugObj(Transform t)
    //{
    //    GameObj obj = GameManager.GetGameObj(t.name);
    //    obj.UseObjValue();
    //    bag.UpdatePlayerValue();
    //    bagTools[obj]--;
    //    t.GetComponentInChildren<Text>().text = bagTools[obj].ToString();
    //    if (bagTools[obj] == 0)
    //    {
    //        bagTools.Remove(obj);
    //        Destroy(t.gameObject);
    //    }
    //}
    //private void UseObj(int num)
    //{
    //    Transform temp = toolPanel.GetChild(num);
    //    if (temp.childCount < 2)
    //    {
    //        return;
    //    }
    //    Transform t = temp.GetChild(0);
    //    UseDrugObj(t);
    //}
    #endregion
}
再次修改BagPanel代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class BagPanel : UIBase{
    Transform canvas;
    Transform bagTran;
    Transform equipTran;
    Button btnTakeOff;
    Text textHp;
    Text textMp;
    Text textLv;
    Text textExp;
    Text textAtt;
    Text textDef;
    Text textSpd;
    Text textMdf;
    void Start(){
        InitText();
        btnTakeOff = GameManager.FindType<Button>(equipTran, "BtnTakeOff");
        btnTakeOff.onClick.AddListener(delegate
        {
            foreach (Transform item in equipTran.Find("Eq"))
            {
                if (item.childCount >= 2)
                {
                    GameObj temp = GameManager.GetGameObj(item.GetChild(0).name);
                    temp.TakeOff();
                    UpdatePlayerValue();
                    SetBtnTakeOff(item.GetChild(0), temp);
                }
            }
        });
        tween = bagTran.GetComponent<UITween>();
        tween.AddEventStartHandle(UpdateValue);
        btnBack = GameManager.FindType<Button>(bagTran, "BtnX");
        btnBack.onClick.AddListener(delegate
        {
            tween.UIBack();
            equipTran.GetComponent<UITween>().UIBack();
        });
    }
    public override void UpdateValue()
    {
        ClearBtn(btnParent);
        Dictionary<GameObj, int>.KeyCollection keys = MainGame.player.GetTools().Keys;
        foreach (GameObj item in keys)
        {
            if (item.isTakeOn)
            {
                continue;
            }

            GameObject btn = Instantiate(prefab, btnParent);
            btn.GetComponent<Image>().sprite = LoadManager.LoadSprite("Obj/" + item.oname);
            btn.name = item.oname;
            btn.tag = item.GetType().ToString();
            btn.GetComponentInChildren<Text>().text = MainGame.player.GetTools()[item].ToString();
            AddEvent(item, btn);
        }
    }
    public void InitText(){
        canvas = MainGame.canvas;
        bagTran = transform.Find("Bag");
        equipTran = transform.Find("Equip");
        text = GameManager.FindType<Text>(bagTran, "TextGold");
        Transform temp = equipTran.Find("TextParent");
        textHp = GameManager.FindType<Text>(temp, "TextHp");
        textMp = GameManager.FindType<Text>(temp, "TextMp");
        textLv = GameManager.FindType<Text>(temp, "TextLv");
        textExp = GameManager.FindType<Text>(temp, "TextExp");
        textAtt = GameManager.FindType<Text>(temp, "TextAtt");
        textDef = GameManager.FindType<Text>(temp, "TextDef");
        textSpd = GameManager.FindType<Text>(temp, "TextSpd");
        textMdf = GameManager.FindType<Text>(temp, "TextMdf");
    }
    void AddEvent(GameObj obj, GameObject btn)
    {
        Image image = btn.GetComponent<Image>();
        EventTrigger et = btn.GetComponent<EventTrigger>();
        if (!et)
        {
            et = btn.AddComponent<EventTrigger>();
        }
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.BeginDrag;//开始拖拽
        entry.callback.AddListener(delegate
        {
            image.raycastTarget = false;
            btn.transform.SetParent(canvas);
        }
        );
        et.triggers.Add(entry);
        //
        entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.Drag;//拖拽中
        entry.callback.AddListener(delegate (BaseEventData arg)
        {
            PointerEventData ped = (PointerEventData)arg;//将基础数据变成鼠标数据
            Vector3 newPos;
            RectTransformUtility.ScreenPointToWorldPointInRectangle(
                btn.GetComponent<RectTransform>(), Mouse.current.position.ReadValue(),//在摄像机视角下鼠标当前坐标转换过去
                ped.enterEventCamera, out newPos);
            btn.transform.position = newPos;
        }
        );
        et.triggers.Add(entry);
        /;
        entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.EndDrag;//结束拖拽
        entry.callback.AddListener(delegate (BaseEventData arg)
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                btn.transform.parent = btnParent;
                image.raycastTarget = true;
                return;
            }
            PointerEventData ped = (PointerEventData)arg;
            Transform target = ped.pointerEnter.transform;
            if (target)
            {
                if (target.tag == obj.GetType().ToString())
                {
                    obj.TakeOn();
                    //交换装备
                    ChangeGameObj(target.parent, btn);
                    //刷新数值
                    UpdatePlayerValue();
                }
                else if (target.name == obj.GetType().ToString() || target.name == obj.type)
                {
                    //交换药品
                    ChangeGameObj(target, btn);
                }
                else
                {
                    obj.isTakeOn = false;
                    btn.transform.parent = btnParent;
                }
            }
            image.raycastTarget = true;
        }
        );
        et.triggers.Add(entry);
        /
        entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;//拖拽中
        entry.callback.AddListener(delegate (BaseEventData arg)
        {
            if (btn.tag != ObjType.Drug.ToString())
            {
                return;
            }
            //MainGame.player.UseDrugObj(btn.transform);
        }
        );
        et.triggers.Add(entry);
    }
    //刷新玩家数据
    public void UpdatePlayerValue()
    {
        textHp.text = "生命:" + MainGame.player.Hp + "/" + MainGame.player.HpMax;
        textMp.text = "魔力:" + MainGame.player.Mp + "/" + MainGame.player.MpMax;
        textAtt.text = "攻击:" + MainGame.player.Att;
        textDef.text = "防御:" + MainGame.player.Def;
        textMdf.text = "魔抗:" + MainGame.player.Mdf;
        textSpd.text = "速度:" + MainGame.player.Spd;
        textLv.text = "等级:" + MainGame.player.lv;
        textExp.text = "经验:" + MainGame.player.Exp;
    }
    void ChangeGameObj(Transform target, GameObject btn)
    {
        GameObj temp = new GameObj();
        if (target.childCount >= 2)
        {
            temp = GameManager.GetGameObj(target.GetChild(0).name);
            SetBtnTakeOff(target.GetChild(0), temp);
        }
        btn.transform.parent = target.transform;
        btn.transform.SetAsFirstSibling();
        btn.transform.localPosition = Vector3.zero;
        btn.GetComponent<RectTransform>().sizeDelta = target.GetComponent<RectTransform>().sizeDelta;
        temp = GameManager.GetGameObj(btn.name);
        if (temp != null)
        {
            temp.isTakeOn = true;
        }

    }
    void SetBtnTakeOff(Transform btn, GameObj obj)
    {
        if (obj != null)
        {
            btn.parent = btnParent;
            obj.isTakeOn = false;
            btn.GetComponent<Image>().raycastTarget = true;
        }
    }
}

挂载脚本

将content拖拽

修改unity场景中TxtParent为TextParent

拖拽Text预制体

添加图片作为一件脱装备,设置正常尺寸

修改Button名为BtnTakeOff

将UITween代码分别挂载在Bag和Equip上

拖拽背包面板BagPanel

添加标签

拖拽

增加两个页面的偏移值

接下来需要做下侧道具栏的层级显示

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/199299.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

4、类和对象、this指针、常对象和常函数

类和对象 类的一般形式 访问控制限定符 public 公有成员&#xff0c;谁都可以访问protected 保护成员&#xff0c;只有类自己和子类可以访问private 私有成员&#xff0c;只有类自己可以访问 类和结构的访问控制限定符区别 类的缺省访问控制限定为私有(private)结构的缺省访…

弱引用能指针 weak_ptr

弱引用智能指针 概述 弱引用智能指针std::weak_ptr可以看做是shared_ptr的助手&#xff0c;它不管理shared_ptr内部的指针。std::weak_ptr没有重载操作符*和->&#xff0c;因为它不共享指针&#xff0c;不能操作资源&#xff0c;所以它的构造不会增加引用计数&#xff0c;…

离散化 Discretization

离散化 **离散化有一个很重要的前提:**只关心数据之间的相对大小关系,不用关心绝对大小。 离散化,把无限空间中有限的个体映射到有限的空间中去。离散化是在不改变数据相对大小的条件下,对离散的数据进行相应的范围缩小。 离散化过程,将一组实数转换为一组整数,使得原始…

gimagereader安装在windows环境的方法

​ 首先github下载.exe的安装包&#xff0c; gtk或者qt5都可以。推荐gtk。 https://github.com/manisandro/gImageReader/releases 直接下载的地址&#xff1a; ​ https://github.com/manisandro/gImageReader/releases/download/master/gImageReader_latest_gtk_x86_64.ex…

前端知识笔记(二十一)———浏览器的缓存策略

浏览器缓存的策略主要分为两种&#xff1a;过期机制和验证机制。 过期机制&#xff1a;是指浏览器根据资源的过期时间&#xff0c;判断是否可以直接使用缓存中的副本&#xff0c;而无需向服务器发起请求。过期时间可以通过以下两种方式设置&#xff1a; Cache-Control&#xf…

Java基础数据类型

Java有八种基础的数据类型&#xff0c;它们被分为两个主要的类别&#xff1a;原始类型和引用类型。原始类型又被分为四类&#xff1a;整型、浮点型、字符型和布尔型。 整型&#xff08;Integral Types&#xff09;&#xff1a; 这些类型用于存储整数。它们包括&#xff1a; ○…

最高性能、最低错误率!一年沉寂,IBM王者归来

周一&#xff0c;国际商业机器公司&#xff08;IBM&#xff09;发布了首台量子计算机&#xff0c;它拥有1000多个量子比特&#xff08;相当于普通计算机中的数字比特&#xff09;。但该公司表示&#xff0c;现在它将转变思路&#xff0c;专注于提高机器的抗错能力&#xff0c;而…

羊大师提问鲜羊奶冷冻还好喝吗?

羊大师提问鲜羊奶冷冻还好喝吗&#xff1f; 在当今追求健康、养生的时代背景下&#xff0c;各种新奇的饮食趋势层出不穷。鲜羊奶冷冻成为了备受追捧的美食新潮流。不仅具备饮食的功能&#xff0c;更是一种享受。本文小编羊大师将从鲜羊奶冷冻的制作工艺、营养价值和市场前景等…

第2章 知识抽取:概述、方法

&#x1f497;&#x1f497;&#x1f497;欢迎来到我的博客&#xff0c;你将找到有关如何使用技术解决问题的文章&#xff0c;也会找到某个技术的学习路线。无论你是何种职业&#xff0c;我都希望我的博客对你有所帮助。最后不要忘记订阅我的博客以获取最新文章&#xff0c;也欢…

『时间之外』这个不得不思考的问题,还是要说一下

还记得当初自己为什么选择计算机&#xff1f; 当初你问我为什么选择计算机&#xff0c;我笑着回答&#xff1a;“因为我梦想成为神奇的码农&#xff01;我想像编织魔法一样编写程序&#xff0c;创造出炫酷的虚拟世界&#xff01;”谁知道&#xff0c;我刚入门的那天&#xff0…

Ruff智能物联网网关助力工厂数智化运营,实现产量提升5%

数字化转型是大势所趋&#xff0c;以工业互联网为代表的数实融合是发展数字经济的重要引擎&#xff0c;也是新质生产力的一大助力。工业互联网是新工业革命的重要基石&#xff0c;加快工业互联网规模化应用&#xff0c;是数字技术和实体经济深度融合的关键支撑&#xff0c;是新…

12.5_黑马数据结构与算法Java

目录 001 二分查找 算法描述 002 二分查找 算法实现 003 二分查找 问题1 循环条件 004 二分查找 问题2 中间索引 thinking&#xff1a;反码补码原码&#xff1f; thinking&#xff1a;二进制转十进制&#xff1f; thinking&#xff1a;无符号右移&#xff1f; 005 二分…

SpringBoot 集成Netty、WebSocket,5分钟搭建聊天通信系统

文章目录 前言Netty简介使用Netty开发WebSocket应用程序开始项目一、添加依赖二、自定义处理器三、初始化通道加载器四、配置启动器五、添加启动监听器六、启动项目七、演示效果1. 客户端1看到其他客户端上线2. 客户端3收到客户端1发送的消息3. 客户端1收到客户端2下线前言 在…

出海风潮:中国母婴品牌征服国际市场的机遇与挑战!

近年来&#xff0c;中国母婴品牌在国内市场蓬勃发展的同时&#xff0c;也逐渐将目光投向国际市场。这一趋势不仅受益于中国经济的崛起&#xff0c;还得益于全球市场对高质量母婴产品的不断需求。然而&#xff0c;面对国际市场的机遇&#xff0c;中国母婴品牌同样面临着一系列挑…

学习MYSQL

DDL 建表 DML增删改 DQL查询 DCL控制用户权限 存储引擎 MYSQL体系结构 *连接层 *服务层&#xff08;DML DDL &#xff09; *引擎层&#xff08;可插拔&#xff09;&#xff08;索引在这里&#xff0c;不通的引擎 索引结构不同&#xff09; *存储层&#xff0c; 外键&#xff…

java springboot简单了解数据源实现 与 springboot内置数据源

之前 我们讲到的项目 数据库管理 用了三种技术 数据源管理方式 我们选择了: DruidDataSource 持久化技术: MyBatis-Plus / MyBatis 数据库: MySql 那么 我们在刚接触数据库连接时 是没用配置Druid的 那它有没有用数据源呢&#xff1f; 我们接触过的配置Druid的方式有两种 用…

【发布小程序配置服务器域名,不配置发布之后访问就会报错request:fail url not in domain list】

小程序在本地开发的时候大家通常会在微信开发者工具中设置“不校验合法域名、web-view (业务域名)、TLS 版本以及HTTPS证书”&#xff0c;久而久之可能会忘掉这个操作&#xff0c;然后打包直接上线发布&#xff0c;结果发现访问会报错request:fail url not in domain list&…

Chat-GPT原理

Chat-GPT原理核心:基于Transformer 架构 ​ 以下是参考文献的部分截图原文说明&#xff1a; ​ Transformers are based on the “attention mechanism,” which allows the model to pay more attention to some inputs than others, regardless of where they show up in t…

热门好用的核验类API,含免费次数

信息核验类 实人认证&#xff08;人像三要素&#xff09;&#xff1a;输入姓名、身份证号码和一张人脸照片&#xff0c;与公安库身份证头像进行权威比对&#xff0c;返回比对分值。实名认证&#xff08;身份证二要素&#xff09;&#xff1a;核验身份证二要素&#xff08;姓名…

2023年甘肃省职业院校技能大赛(中职教师组)网络安全竞赛样题(三)

2023年甘肃省职业院校技能大赛&#xff08;中职教师组&#xff09; 网络安全竞赛样题&#xff08;三&#xff09; &#xff08;总分1000分&#xff09; 目录 模块A 基础设施设置与安全加固 模块B 网络安全事件响应、数字取证调查和应用安全 B-1任务一&#xff1a;主机发现…