项目02《游戏-09-开发》Unity3D

news2024/9/24 3:26:35

基于      项目02《游戏-08-开发》Unity3D      ,

本次任务是做抽卡界面,获取的卡片增添在背包中,并在背包中可以删除卡片,

首先在Canvas下创建一个空物体,命名为LotteryPanel,作为抽卡界面,

在右上角的锚点处设置为拉伸模式,这样他的宽高就变成1920 * 1080,

首先给这个界面添加一个关闭按钮,

十连抽按键,

ctrl + d 复制一份按钮改为单抽,

然后创建一个Image子物体命名为LotteryItem并复制十份,

拖拽星级预制体,

修改位置,

添加颜色,

然后将其余9个LotteryItem删除,重新复制到10个,

再创建一个文件夹Lottery用来存放关于抽卡的预制体,

此时我们已经有了两个界面,一个是抽卡界面,一个是背包界面,

为了将这个两个界面联系起来,再做个主界面,

接下来调整位置,

添加好主界面之后,找到MainGame.cs脚本进行修改:

在PackageLocalData.cs脚本中增添方法:

using System.Collections.Generic;
using UnityEngine;
public class PackageLocalData{
    static PackageLocalData _instance;
    public static PackageLocalData Instance{
        get{
            if (_instance == null)
                _instance = new PackageLocalData();
            return _instance;
        }
    }
    //存
    public List<PackageLocalItem> items;
    public void SavaPackage(){
        string inventoryJson = JsonUtility.ToJson(this);
        PlayerPrefs.SetString("PackageLocalData", inventoryJson);
        PlayerPrefs.Save();
    }
    //取
    public List<PackageLocalItem> LoadPackage(){
        if (items != null)
            return items;
        if (PlayerPrefs.HasKey("PackageLocalData")){
            string inventoryJson = PlayerPrefs.GetString("PackageLocalData");
            PackageLocalData packageLocalData = JsonUtility.FromJson<PackageLocalData>(inventoryJson);
            items = packageLocalData.items;
            return items;
        }
        else{
            items = new List<PackageLocalItem>();
            return items;
        }
    }
    //添加抽卡阶段
    public void SavePackage(){
        string inventoryJson = JsonUtility.ToJson(this);
        PlayerPrefs.SetString("PackageLocalData", inventoryJson);
        PlayerPrefs.Save();
    }
}
[System.Serializable]
public class PackageLocalItem{
    public string uid;
    public int id;
    public int num;
    public int level;
    public bool isNew;
    public override string ToString(){
        return string.Format($"[id] {id} [num] {num}");
    }
}

using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;
using static UIManager;
public class MainGame : MonoBehaviour{
    public static Player player;
    void Awake(){
        player = GameObject.Find("Player").GetComponent<Player>();
        //背包系统
        _instance = this;
        DontDestroyOnLoad(gameObject);
    }
    //背包系统
    static MainGame _instance;
    PackageTable packageTable;
    public static MainGame Instance{
        get{
            return _instance;
        }
    }
    void Start(){
        //UIManager.Instance.OpenPanel(UIConst.PackagePanel);
    }
    //对静态数据加载
    public PackageTable GetPackageTable(){
        if (packageTable == null)
            packageTable = Resources.Load<PackageTable>("TableData/PackageTable");
        return packageTable;
    }

    //对动态数据加载 
    public List<PackageLocalItem> GetPackageLocalData(){
        return PackageLocalData.Instance.LoadPackage();
    }
    //根据ID去表格中拿到指定的数据
    public PackageTableItem GetPackageItemById(int id){
        List<PackageTableItem> packageDataList = GetPackageTable().dataList;
        foreach (PackageTableItem item in packageDataList){
            if (item.id == id)
                return item;
        }
        return null;
    }
    //根据uid去本地数据中拿到动态数据
    public PackageLocalItem GetPackageLocalItemByUId(string uid){
        List<PackageLocalItem> packageDataList = GetPackageLocalData();
        foreach (PackageLocalItem item in packageDataList){
            if (item.uid == uid)
                return item;
        }
        return null;
    }
    public List<PackageLocalItem> GetSortPackageLocalData(){
        List<PackageLocalItem> localItems = PackageLocalData.Instance.LoadPackage();
        localItems.Sort(new PackageItemComparer());//添加
        return localItems;
    }
    public class PackageItemComparer : IComparer<PackageLocalItem>{
        public int Compare(PackageLocalItem a, PackageLocalItem b){
            PackageTableItem x = MainGame.Instance.GetPackageItemById(a.id);
            PackageTableItem y = MainGame.Instance.GetPackageItemById(b.id);
            //首先按star从大到小排序
            int starComparison = y.star.CompareTo(x.star);
            //如果star相同,则按id从大到小排序
            if (starComparison == 0){
                int idComparison = y.id.CompareTo(x.id);
                if (idComparison == 0)
                    return b.level.CompareTo(a.level);
                return idComparison;
            }
            return starComparison;
        }
    }

    //添加抽卡阶段字段
    public class GameConst {
        //武器类型
        public const int PackageTypeWeapon = 1;
        //食物类型
        public const int PackageTypeFood = 2;   
    }
    //添加抽卡阶段
    //根据类型获取配置的表格数据
    public List<PackageTableItem> GetPackageTableByType(int type){
        List<PackageTableItem> packageItems = new List<PackageTableItem>();
        foreach (PackageTableItem packageItem in GetPackageTable().dataList){
            if (packageItem.type == type)
                packageItems.Add(packageItem);
        }
        return packageItems;
    }
    //添加抽卡阶段具体逻辑 随机抽卡,获得一件武器
    public PackageLocalItem GetLotteryRandom1(){
        List<PackageTableItem> packageItems = GetPackageTableByType(GameConst.PackageTypeWeapon);
        int index = Random.Range(0, packageItems.Count);
        PackageTableItem packageItem = packageItems[index];
        PackageLocalItem packageLocalItem = new(){
            uid = System.Guid.NewGuid().ToString(),
            id = packageItem.id,
            num = 1,
            level = 1,
            isNew = CheckWeaponIsNew(packageItem.id),
        };
        PackageLocalData.Instance.items.Add(packageLocalItem);
        PackageLocalData.Instance.SavePackage();
        return packageLocalItem;    
    }
    public bool CheckWeaponIsNew(int id) {
        foreach (PackageLocalItem packageLocalItem in GetPackageLocalData()) {
            if (packageLocalItem.id == id)
                return false;
        }
        return true;
    }
    //随机抽卡 十连抽
    public List<PackageLocalItem> GetLotteryRandom10(bool sort = false) {
        //随机抽卡
        List<PackageLocalItem> packageLocalItems = new();
        for (int i = 0; i < 10; i++) {
            PackageLocalItem packageLocalItem = GetLotteryRandom1();
            packageLocalItems.Add(packageLocalItem);
        }
        //武器排序
        if (sort)
            packageLocalItems.Sort(new PackageItemComparer());
        return packageLocalItems;    
    }
}
下一步写整个抽卡界面的代码逻辑:

首先添加一个脚本LotteryPanel.cs

然后绑定脚本,

双击LotteryPanel.cs脚本修改代码:

using UnityEngine;
using UnityEngine.UI;
public class LotteryPanel : BasePanel{
    Transform UIClose;
    Transform UICenter;
    Transform UILottery10;
    Transform UILottery1;
    GameObject LotteryCellPrefab;
    protected override void Awake(){
        base.Awake();
        InitUI();
        InitPrefab();
    }
    void InitUI() {
        UIClose = transform.Find("TopRight/Close");
        UICenter = transform.Find("Center");
        UILottery10 = transform.Find("Bottom/Lottery10");
        UILottery1 = transform.Find("Bottom/Lottery1");
        UILottery10.GetComponent<Button>().onClick.AddListener(OnLottert10Btn);
        UILottery1.GetComponent<Button>().onClick.AddListener(OnLottert1Btn);

        UIClose.GetComponent<Button>().onClick.AddListener (OnClose);
    }
    void OnClose(){
        print(">>>>>>>> OnClose");
    }
    void OnLottert1Btn(){
        print(">>>>>>>> OnLottert1Btn");
    }
    void OnLottert10Btn(){
        print(">>>>>>>> OnLottert10Btn");
    }
    void InitPrefab() {
        LotteryCellPrefab = Resources.Load("Prefab/Panel/Lottery/LotteryItem") as GameObject;
    }
}
修改UIManager.cs脚本:

using System.Collections.Generic;
using UnityEngine;
public class UIManager{
    static UIManager _instance;
    Transform _uiRoot;
    //路径配置字典
    Dictionary<string, string> pathDict;
    //预制体缓存字典
    Dictionary<string, GameObject> prefabDict;
    //已打开界面的缓存字典
    public Dictionary<string, BasePanel> panelDict;
    public static UIManager Instance{
        get{
            if (_instance == null)
                _instance = new UIManager();
            return _instance;
        }
    }
    public Transform UIRoot{
        get{
            if (_uiRoot == null){
                if (GameObject.Find("Canvas"))
                    _uiRoot = GameObject.Find("Canvas").transform;
                else
                    _uiRoot = new GameObject("Canvas").transform;
            };
            return _uiRoot;
        }
    }
    UIManager(){
        InitDicts();
    }
    void InitDicts(){
        prefabDict = new Dictionary<string, GameObject>();
        panelDict = new Dictionary<string, BasePanel>();
        pathDict = new Dictionary<string, string>(){
            { UIConst.PackagePanel,"Package/PackagePanel"},//**
            //添加抽卡路径
            { UIConst.LotteryPanel,"Lottery/LotteryPanel"},
        };
    }
    public BasePanel GetPanel(string name){
        BasePanel panel = null;
        //检查是否已打开
        if (panelDict.TryGetValue(name, out panel))
            return panel;
        return null;
    }
    public BasePanel OpenPanel(string name){
        BasePanel panel = null;
        //检查是否已打开
        if (panelDict.TryGetValue(name, out panel)){
            Debug.Log($"界面已打开 {name}");
            return null;
        }
        //检查路径是否配置
        string path = "";
        if (!pathDict.TryGetValue(name, out path)){
            Debug.Log($"界面名称错误 或未配置路径 {name}");
            return null;
        }
        //使用缓存的预制体
        GameObject panelPrefab = null;
        if (!prefabDict.TryGetValue(name, out panelPrefab)){
            string realPath = "Prefabs/Panel/" + path;
            panelPrefab = Resources.Load<GameObject>(realPath) as GameObject;
            prefabDict.Add(name, panelPrefab);
        }
        //打开界面
        GameObject panelObject = GameObject.Instantiate(panelPrefab, UIRoot, false);
        panel = panelObject.GetComponent<BasePanel>();
        panelDict.Add(name, panel);
        panel.OpenPanel(name);
        return panel;
    }
    //关闭界面
    public bool ClosePanel(string name){
        BasePanel panel = null;
        if (!panelDict.TryGetValue(name, out panel)){
            Debug.LogError($"界面未打开 {name}");
            return false;
        }
        panel.ClosePanel();
        return true;
    }
    public class UIConst{
        //配置常量
        public const string PackagePanel = "PackagePanel";//**
        //添加抽卡阶段
        public const string LotteryPanel = "LotteryPanel";
    }
}
配置完成之后就可以在MainGame.cs脚本中打开这个界面,

运行游戏点击十连抽和单抽就会做出响应,

为了将背包与抽卡界面关联起来,先写主页面脚本,

创建新脚本MainPanel.cs脚本,

绑定脚本,

双击MainPanel.cs修改代码:

using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
public class MainPanel : BasePanel{
    Transform UILottery;
    Transform UIPackage;
    Transform UIQuitBtn;
    protected override void Awake(){
        base.Awake();
        InitUI();
    }
    void InitUI(){
        UILottery = transform.Find("Top/LotteryBtn");
        UIPackage = transform.Find("Top/PackageBtn");
        UIQuitBtn = transform.Find("BottomLeft/QuitBtn");
        UILottery.GetComponent<Button>().onClick.AddListener(OnBtnLottery);
        UIPackage.GetComponent<Button>().onClick.AddListener(OnBtnPackage);
        UIQuitBtn.GetComponent<Button>().onClick.AddListener(OnQuitGame);
    }
    void OnQuitGame(){
        print(">>>>>  OnQuitGame");
        EditorApplication.isPlaying = false;
        Application.Quit();
    }
    void OnBtnPackage(){
        print(">>>>>  OnBtnPackage");
        UIManager.Instance.OpenPanel(UIManager.UIConst.PackagePanel);
        ClosePanel();
    }
    void OnBtnLottery(){
        print(">>>>>  OnBtnLottery");
        UIManager.Instance.OpenPanel(UIManager.UIConst.LotteryPanel);
        ClosePanel();
    }
}
接着修改UIManager.cs脚本:

using System.Collections.Generic;
using UnityEngine;
public class UIManager{
    static UIManager _instance;
    Transform _uiRoot;
    //路径配置字典
    Dictionary<string, string> pathDict;
    //预制体缓存字典
    Dictionary<string, GameObject> prefabDict;
    //已打开界面的缓存字典
    public Dictionary<string, BasePanel> panelDict;
    public static UIManager Instance{
        get{
            if (_instance == null)
                _instance = new UIManager();
            return _instance;
        }
    }
    public Transform UIRoot{
        get{
            if (_uiRoot == null){
                if (GameObject.Find("Canvas"))
                    _uiRoot = GameObject.Find("Canvas").transform;
                else
                    _uiRoot = new GameObject("Canvas").transform;
            };
            return _uiRoot;
        }
    }
    UIManager(){
        InitDicts();
    }
    void InitDicts(){
        prefabDict = new Dictionary<string, GameObject>();
        panelDict = new Dictionary<string, BasePanel>();
        pathDict = new Dictionary<string, string>(){
            { UIConst.PackagePanel,"Package/PackagePanel"},//**
            //添加抽卡路径
            { UIConst.LotteryPanel,"Lottery/LotteryPanel"},
            //添加主页面转换路径
            { UIConst.MainPanel,"MainPanel"},
        };
    }
    public BasePanel GetPanel(string name){
        BasePanel panel = null;
        //检查是否已打开
        if (panelDict.TryGetValue(name, out panel))
            return panel;
        return null;
    }
    public BasePanel OpenPanel(string name){
        BasePanel panel = null;
        //检查是否已打开
        if (panelDict.TryGetValue(name, out panel)){
            Debug.Log($"界面已打开 {name}");
            return null;
        }
        //检查路径是否配置
        string path = "";
        if (!pathDict.TryGetValue(name, out path)){
            Debug.Log($"界面名称错误 或未配置路径 {name}");
            return null;
        }
        //使用缓存的预制体
        GameObject panelPrefab = null;
        if (!prefabDict.TryGetValue(name, out panelPrefab)){
            string realPath = "Prefabs/Panel/" + path;
            panelPrefab = Resources.Load<GameObject>(realPath) as GameObject;
            prefabDict.Add(name, panelPrefab);
        }
        //打开界面
        GameObject panelObject = GameObject.Instantiate(panelPrefab, UIRoot, false);
        panel = panelObject.GetComponent<BasePanel>();
        panelDict.Add(name, panel);
        panel.OpenPanel(name);
        return panel;
    }
    //关闭界面
    public bool ClosePanel(string name){
        BasePanel panel = null;
        if (!panelDict.TryGetValue(name, out panel)){
            Debug.LogError($"界面未打开 {name}");
            return false;
        }
        panel.ClosePanel();
        return true;
    }
    public class UIConst{
        //配置常量
        public const string PackagePanel = "PackagePanel";//**
        //添加抽卡阶段
        public const string LotteryPanel = "LotteryPanel";
        //添加抽卡的主界面阶段
        public const string MainPanel = "MainPanel";
    }
}
最后修改MainGame.cs脚本:

再修改LotteryPanel.cs脚本:

再修改PackagePanel.cs脚本:

调整资源包位置,

运行游戏即可在背包中进行切换了,

接下来继续修改LotteryPanel.cs脚本:

先不写十连抽函数更重要的是去写更新单抽的逻辑脚本:

首先创建一个脚本LotteryCell.cs脚本,

绑定脚本,

双击LotteryCell.cs修改脚本:

using UnityEngine;
using UnityEngine.UI;
public class LotteryCell : MonoBehaviour{
    Transform UIImage;
    Transform UIStars;
    Transform UINew;
    PackageLocalItem packageLocalItem;
    PackageTableItem packageTableItem;
    LotteryPanel uiParent;
    void Awake(){
        InitUI();    
    }
    void InitUI(){
        UIImage = transform.Find("Center/Image");
        UIStars = transform.Find("Bottom/Stars");
        UINew = transform.Find("Top/New");
        UINew.gameObject.SetActive(false);
    }
    public void Refresh(PackageLocalItem packageLocalItem, LotteryPanel uiParent) {
        //数据初始化
        this.packageLocalItem = packageLocalItem;
        this.packageTableItem = MainGame.Instance.GetPackageItemById(this.packageLocalItem.id);
        this.uiParent = uiParent;

        //刷新UI信息
        RefreshImage();
    }
    void RefreshImage() {
        Texture2D t = (Texture2D)Resources.Load(this.packageTableItem.imagePath);
        Sprite temp = Sprite.Create(t, new Rect(0, 0, t.width, t.height), new Vector2(0, 0));
        UIImage.GetComponent<Image>().sprite = temp;    
    }
    public void RefreshStars() {
        for (int i = 0; i < UIStars.childCount; i++) {
            Transform star = UIStars.GetChild(i);
            if (this.packageTableItem.star > i)
                star.gameObject.SetActive(true);
            else
                star.gameObject.SetActive(false);
        }
    }
}
为了方便拓展的一个排序模式,修改PackagePanel.cs脚本

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum PackageMode{
    normal,
    delete,
    sort,
}
public class PackagePanel : BasePanel{
    Transform UIMenu;
    Transform UIMenuWeapon;
    Transform UIMenuFood;
    Transform UITabName;
    Transform UICloseBtn;
    Transform UICenter;
    Transform UIScrollView;
    Transform UIDetailPanel;
    Transform UILeftBtn;
    Transform UIRightBtn;
    Transform UIDeletePanel;
    Transform UIDeleteBackBtn;
    Transform UIDeleteInfoText;
    Transform UIDeleteConfirmBtn;
    Transform UIBottomMenus;
    Transform UIDeleteBtn;
    Transform UIDetailBtn;
    //添加
    public GameObject PackageUIItemPrefab;
    //添加一列用来容纳所有被选中的物品uid
    public List<string> deleteChooseUid;
    //添加删除属性
    public PackageMode curMode = PackageMode.normal;
    public void AddChooseDeleteUid(string uid) {
        this.deleteChooseUid ??= new List<string>();
        if(!this.deleteChooseUid.Contains(uid))
            this.deleteChooseUid.Add(uid);
        else
            this.deleteChooseUid.Remove(uid);
        RefreshDeletePanel();
    }
    //添加删除选中项
    void RefreshDeletePanel(){
        RectTransform scrollContent = UIScrollView.GetComponent<ScrollRect>().content;
        foreach(Transform cell in scrollContent){
            PackageCell packageCell = cell.GetComponent<PackageCell>();
            //todo:物品刷新选中状态
            //packageCell.RefreshDeleteState();
        }
    }
    //添加 表示当前选中的物品时哪一个uid
    string _chooseUid;
    public string ChooseUid {
        get { return _chooseUid; }
        set {
            _chooseUid = value;
            RefreshDetail();
        }
    }
    void RefreshDetail() {
        //找到uid对应的动态数据
        PackageLocalItem localItem = MainGame.Instance.GetPackageLocalItemByUId(ChooseUid);
        //刷新详情界面
        UIDetailPanel.GetComponent<PackageDetail>().Refresh(localItem, this);
    }
    override protected void Awake(){
        base.Awake();
        InitUI();
    }
    //添加1
    void Start(){
        RefreshUI();
    }
    //添加1
    void RefreshUI(){
        RefreshScroll();
    }
    //添加1
    void RefreshScroll(){
        //清理滚动容器中原本的物品
        RectTransform scrollContent = UIScrollView.GetComponent<ScrollRect>().content;
        for (int i = 0; i < scrollContent.childCount; i++)
            Destroy(scrollContent.GetChild(i).gameObject);
        //获取本地数据的方法拿到自己身上背包数据 并且根据背包数据初始化滚动容器
        foreach (PackageLocalItem localData in MainGame.Instance.GetSortPackageLocalData()){
            Transform PackageUIItem = Instantiate(PackageUIItemPrefab.transform, scrollContent) as Transform;

            PackageCell packageCell = PackageUIItem.GetComponent<PackageCell>();
            //添加2
            packageCell.Refresh(localData, this);
        }
    }
    void InitUI(){
        InitUIName();
        InitClick();
    }
    void InitUIName(){
        UIMenu = transform.Find("TopCenter/Menu");
        UIMenuWeapon = transform.Find("TopCenter/Menus/Weapon");
        UIMenuFood = transform.Find("TopCenter/Menus/Food");
        UITabName = transform.Find("LeftTop/TabName");
        UICloseBtn = transform.Find("RightTop/Close");
        UICenter = transform.Find("Center");
        UIScrollView = transform.Find("Center/Scroll View");
        UIDetailPanel = transform.Find("Center/DetailPanel");
        UILeftBtn = transform.Find("Left/Button");
        UIRightBtn = transform.Find("Right/Button");

        UIDeletePanel = transform.Find("Bottom/DeletePanel");
        UIDeleteBackBtn = transform.Find("Bottom/DeletePanel/Back");
        UIDeleteInfoText = transform.Find("Bottom/DeletePanel/InfoText");
        UIDeleteConfirmBtn = transform.Find("Bottom/DeletePanel/ConfirmBtn");
        UIBottomMenus = transform.Find("Bottom/BottomMenus");
        UIDeleteBtn = transform.Find("Bottom/BottomMenus/DeleteBtn");
        UIDetailBtn = transform.Find("Bottom/BottomMenus/DetailBtn");

        UIDeletePanel.gameObject.SetActive(false);
        UIBottomMenus.gameObject.SetActive(true);
    }
    void InitClick(){
        UIMenuWeapon.GetComponent<Button>().onClick.AddListener(OnClickWeapon);
        UIMenuFood.GetComponent<Button>().onClick.AddListener(OnClickFood);
        UICloseBtn.GetComponent<Button>().onClick.AddListener(OnClickClose);
        UILeftBtn.GetComponent<Button>().onClick.AddListener(OnClickLeft);
        UIRightBtn.GetComponent<Button>().onClick.AddListener(OnClickRight);

        UIDeleteBackBtn.GetComponent<Button>().onClick.AddListener(OnDeleteBack);
        UIDeleteConfirmBtn.GetComponent<Button>().onClick.AddListener(OnDeleteConfirm);
        UIDeleteBtn.GetComponent<Button>().onClick.AddListener(OnDelete);
        UIDetailBtn.GetComponent<Button>().onClick.AddListener(OnDetail);
    }

    void OnDetail(){
        print(">>>>>>> OnDetail()");
    }
    //进入删除模式 ; 左下角删除按钮
    void OnDelete(){
        print(">>>>>>> OnDelete()");
        curMode = PackageMode.delete;
        UIDeletePanel.gameObject.SetActive(true);
    }
    //确认删除
    void OnDeleteConfirm(){
        print(">>>>>>> OnDeleteConfirm()");
        if (this.deleteChooseUid == null)
            return;
        if (this.deleteChooseUid.Count == 0)
            return;
        MainGame.Instance.DeletePackageItems(this.deleteChooseUid);
        //删除完成后刷新整个背包页面
        RefreshUI();
    }
    //退出删除模式
    void OnDeleteBack(){
        print(">>>>>>> OnDeleteBack()");
        curMode = PackageMode.normal;
        UIDeletePanel.gameObject.SetActive(false);
        //重置选中的删除列表
        deleteChooseUid = new List<string>();
        //刷新选中状态
        RefreshDeletePanel();
    }
    void OnClickRight(){
        print(">>>>>>> OnClickRight()");
    }
    void OnClickLeft(){
        print(">>>>>>> OnClickLeft()");
    }
    void OnClickWeapon(){
        print(">>>>>>> OnClickWeapon()");
    }
    void OnClickFood(){
        print(">>>>>>> OnClickFood()");
    }
    void OnClickClose(){
        ClosePanel();
        UIManager.Instance.OpenPanel(UIManager.UIConst.MainPanel);
    }
}
这里会出现报红,修改MainGame.cs脚本添加删除方法即可:

using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;
using static UIManager;
public class MainGame : MonoBehaviour{
    public static Player player;
    void Awake(){
        player = GameObject.Find("Player").GetComponent<Player>();
        //背包系统
        _instance = this;
        DontDestroyOnLoad(gameObject);
    }
    //背包系统
    static MainGame _instance;
    PackageTable packageTable;
    public static MainGame Instance{
        get{
            return _instance;
        }
    }
    void Start(){
        UIManager.Instance.OpenPanel(UIConst.MainPanel);
    }
    //对静态数据加载
    public PackageTable GetPackageTable(){
        if (packageTable == null)
            packageTable = Resources.Load<PackageTable>("TableData/PackageTable");
        return packageTable;
    }

    //对动态数据加载 
    public List<PackageLocalItem> GetPackageLocalData(){
        return PackageLocalData.Instance.LoadPackage();
    }
    //根据ID去表格中拿到指定的数据
    public PackageTableItem GetPackageItemById(int id){
        List<PackageTableItem> packageDataList = GetPackageTable().dataList;
        foreach (PackageTableItem item in packageDataList){
            if (item.id == id)
                return item;
        }
        return null;
    }
    //根据uid去本地数据中拿到动态数据
    public PackageLocalItem GetPackageLocalItemByUId(string uid){
        List<PackageLocalItem> packageDataList = GetPackageLocalData();
        foreach (PackageLocalItem item in packageDataList){
            if (item.uid == uid)
                return item;
        }
        return null;
    }
    public List<PackageLocalItem> GetSortPackageLocalData(){
        List<PackageLocalItem> localItems = PackageLocalData.Instance.LoadPackage();
        localItems.Sort(new PackageItemComparer());//添加
        return localItems;
    }
    public class PackageItemComparer : IComparer<PackageLocalItem>{
        public int Compare(PackageLocalItem a, PackageLocalItem b){
            PackageTableItem x = MainGame.Instance.GetPackageItemById(a.id);
            PackageTableItem y = MainGame.Instance.GetPackageItemById(b.id);
            //首先按star从大到小排序
            int starComparison = y.star.CompareTo(x.star);
            //如果star相同,则按id从大到小排序
            if (starComparison == 0){
                int idComparison = y.id.CompareTo(x.id);
                if (idComparison == 0)
                    return b.level.CompareTo(a.level);
                return idComparison;
            }
            return starComparison;
        }
    }

    //添加抽卡阶段字段
    public class GameConst {
        //武器类型
        public const int PackageTypeWeapon = 1;
        //食物类型
        public const int PackageTypeFood = 2;   
    }
    //添加抽卡阶段
    //根据类型获取配置的表格数据
    public List<PackageTableItem> GetPackageTableByType(int type){
        List<PackageTableItem> packageItems = new List<PackageTableItem>();
        foreach (PackageTableItem packageItem in GetPackageTable().dataList){
            if (packageItem.type == type)
                packageItems.Add(packageItem);
        }
        return packageItems;
    }
    //添加抽卡阶段具体逻辑 随机抽卡,获得一件武器
    public PackageLocalItem GetLotteryRandom1(){
        List<PackageTableItem> packageItems = GetPackageTableByType(GameConst.PackageTypeWeapon);
        int index = Random.Range(0, packageItems.Count);
        PackageTableItem packageItem = packageItems[index];
        PackageLocalItem packageLocalItem = new(){
            uid = System.Guid.NewGuid().ToString(),
            id = packageItem.id,
            num = 1,
            level = 1,
            isNew = CheckWeaponIsNew(packageItem.id),
        };
        PackageLocalData.Instance.items.Add(packageLocalItem);
        PackageLocalData.Instance.SavePackage();
        return packageLocalItem;    
    }
    public bool CheckWeaponIsNew(int id) {
        foreach (PackageLocalItem packageLocalItem in GetPackageLocalData()) {
            if (packageLocalItem.id == id)
                return false;
        }
        return true;
    }
    //随机抽卡 十连抽
    public List<PackageLocalItem> GetLotteryRandom10(bool sort = false) {
        //随机抽卡
        List<PackageLocalItem> packageLocalItems = new();
        for (int i = 0; i < 10; i++) {
            PackageLocalItem packageLocalItem = GetLotteryRandom1();
            packageLocalItems.Add(packageLocalItem);
        }
        //武器排序
        if (sort)
            packageLocalItems.Sort(new PackageItemComparer());
        return packageLocalItems;    
    }
    //添加删除背包道具方法
    public void DeletePackageItems(List<string> uids) {
        foreach(string uid in uids)
            DeletePackageItem(uid,false);
        PackageLocalData.Instance.SavePackage();
    }
    public void DeletePackageItem(string uid, bool needSave = true) {
        PackageLocalItem packageLocalItem = GetPackageLocalItemByUId(uid);
        if (packageLocalItem == null)
            return;
        PackageLocalData.Instance.items.Remove(packageLocalItem);
        if (needSave)
            PackageLocalData.Instance.SavePackage();
    }
}
修改PackageCell.cs脚本:

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class PackageCell : MonoBehaviour,IPointerClickHandler,IPointerEnterHandler,IPointerExitHandler{
    Transform UIIcon;
    Transform UIHead;
    Transform UINew;
    Transform UISelect;
    Transform UILevel;
    Transform UIStars;
    Transform UIDeleteSelect;

    //添加
    Transform UISelectAni;
    Transform UIMouseOverAni;

    //动态数据
    PackageLocalItem packageLocalData;
    //静态数据
    PackageTableItem packageTableItem;
    //父物体也就是PackagePanel本身
    PackagePanel uiParent;

    void Awake(){
        InitUIName();
    }
    void InitUIName(){
        UIIcon = transform.Find("Top/Icon");
        UIHead = transform.Find("Top/Head");
        UINew = transform.Find("Top/New");
        UILevel = transform.Find("Bottom/LevelText");
        UIStars = transform.Find("Bottom/Stars");
        UISelect = transform.Find("Select");
        UIDeleteSelect = transform.Find("DeleteSelect");
        //添加
        UIMouseOverAni = transform.Find("MouseOverAni");
        UISelectAni = transform.Find("SelectAni");

        UIDeleteSelect.gameObject.SetActive(false);
        //添加
        UIMouseOverAni.gameObject.SetActive(false);
        UISelectAni.gameObject.SetActive(false);
    }
    //刷新
    public void Refresh(PackageLocalItem packageLocalData, PackagePanel uiParent){
        //数据初始化
        this.packageLocalData = packageLocalData;
        this.packageTableItem = MainGame.Instance.GetPackageItemById(packageLocalData.id);
        this.uiParent = uiParent;
        //等级信息
        UILevel.GetComponent<Text>().text = "Lv." + this.packageLocalData.level.ToString();
        //是否是新获得?
        UINew.gameObject.SetActive(this.packageLocalData.isNew);
        Debug.Log("ImagePath: " + this.packageTableItem.imagePath);
        //物品的图片
        Texture2D t = (Texture2D)Resources.Load(this.packageTableItem.imagePath);
        if (t != null){
            Sprite temp = Sprite.Create(t, new Rect(0, 0, t.width, t.height), new Vector2(0, 0));
            // 继续处理 Sprite 对象
            UIIcon.GetComponent<Image>().sprite = temp;
        }
        else{
            // 处理纹理加载失败的情况
            Debug.LogError("Failed to load texture.");
        }
        //刷新星级
        RefreshStars();
    }
    //刷新星级
    public void RefreshStars(){
        for (int i = 0; i < UIStars.childCount; i++){
            Transform star = UIStars.GetChild(i);
            if (this.packageTableItem.star > i)
                star.gameObject.SetActive(true);
            else
                star.gameObject.SetActive(false);
        }
    }

    public void OnPointerClick(PointerEventData eventData){
        //if (this.uiParent.ChooseUid == this.packageLocalData.uid)
        //    return;
        //根据点击设置最新的uid 进而刷新详情界面
        //this.uiParent.ChooseUid = this.packageLocalData.uid;
        //UISelectAni.gameObject.SetActive(true);
        //UISelectAni.GetComponent<Animator>().SetTrigger("In");
        //添加删除方法:
        if(this.uiParent.curMode == PackageMode.delete)
            this.uiParent.AddChooseDeleteUid(this.packageLocalData.uid);
        if (this.uiParent.ChooseUid == this.packageLocalData.uid)
            return;
        //根据点击设置最新的uid -> 进而刷新详情界面
        this.uiParent.ChooseUid = this.packageLocalData.uid;
        UISelectAni.gameObject.SetActive(true);
        UISelectAni.GetComponent<Animator>().SetTrigger("In");
    }

    public void OnPointerEnter(PointerEventData eventData){
        UIMouseOverAni.gameObject.SetActive(true);
        UIMouseOverAni.GetComponent<Animator>().SetTrigger("In");
    }

    public void OnPointerExit(PointerEventData eventData){
        Debug.Log($"OnPointerExit {eventData.ToString()}");
    }
    //添加删除方法
    public void RefershDeleteState() {
        if (this.uiParent.deleteChooseUid.Contains(this.packageLocalData.uid))
            this.UIDeleteSelect.gameObject.SetActive(true);
        else
            this.UIDeleteSelect.gameObject.SetActive(false);
    }
}
最后修改PackagePanel.cs脚本:

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum PackageMode{
    normal,
    delete,
    sort,
}
public class PackagePanel : BasePanel{
    Transform UIMenu;
    Transform UIMenuWeapon;
    Transform UIMenuFood;
    Transform UITabName;
    Transform UICloseBtn;
    Transform UICenter;
    Transform UIScrollView;
    Transform UIDetailPanel;
    Transform UILeftBtn;
    Transform UIRightBtn;
    Transform UIDeletePanel;
    Transform UIDeleteBackBtn;
    Transform UIDeleteInfoText;
    Transform UIDeleteConfirmBtn;
    Transform UIBottomMenus;
    Transform UIDeleteBtn;
    Transform UIDetailBtn;
    //添加
    public GameObject PackageUIItemPrefab;
    //添加一列用来容纳所有被选中的物品uid
    public List<string> deleteChooseUid;
    //添加删除属性
    public PackageMode curMode = PackageMode.normal;
    public void AddChooseDeleteUid(string uid) {
        this.deleteChooseUid ??= new List<string>();
        if(!this.deleteChooseUid.Contains(uid))
            this.deleteChooseUid.Add(uid);
        else
            this.deleteChooseUid.Remove(uid);
        RefreshDeletePanel();
    }
    //添加删除选中项
    void RefreshDeletePanel(){
        RectTransform scrollContent = UIScrollView.GetComponent<ScrollRect>().content;
        foreach(Transform cell in scrollContent){
            PackageCell packageCell = cell.GetComponent<PackageCell>();
            //todo: 物品刷新选中状态
            packageCell.RefershDeleteState();
        }
    }
    //添加 表示当前选中的物品时哪一个uid
    string _chooseUid;
    public string ChooseUid {
        get { return _chooseUid; }
        set {
            _chooseUid = value;
            RefreshDetail();
        }
    }
    void RefreshDetail() {
        //找到uid对应的动态数据
        PackageLocalItem localItem = MainGame.Instance.GetPackageLocalItemByUId(ChooseUid);
        //刷新详情界面
        UIDetailPanel.GetComponent<PackageDetail>().Refresh(localItem, this);
    }
    override protected void Awake(){
        base.Awake();
        InitUI();
    }
    //添加1
    void Start(){
        RefreshUI();
    }
    //添加1
    void RefreshUI(){
        RefreshScroll();
    }
    //添加1
    void RefreshScroll(){
        //清理滚动容器中原本的物品
        RectTransform scrollContent = UIScrollView.GetComponent<ScrollRect>().content;
        for (int i = 0; i < scrollContent.childCount; i++)
            Destroy(scrollContent.GetChild(i).gameObject);
        //获取本地数据的方法拿到自己身上背包数据 并且根据背包数据初始化滚动容器
        foreach (PackageLocalItem localData in MainGame.Instance.GetSortPackageLocalData()){
            Transform PackageUIItem = Instantiate(PackageUIItemPrefab.transform, scrollContent) as Transform;

            PackageCell packageCell = PackageUIItem.GetComponent<PackageCell>();
            //添加2
            packageCell.Refresh(localData, this);
        }
    }
    void InitUI(){
        InitUIName();
        InitClick();
    }
    void InitUIName(){
        UIMenu = transform.Find("TopCenter/Menu");
        UIMenuWeapon = transform.Find("TopCenter/Menus/Weapon");
        UIMenuFood = transform.Find("TopCenter/Menus/Food");
        UITabName = transform.Find("LeftTop/TabName");
        UICloseBtn = transform.Find("RightTop/Close");
        UICenter = transform.Find("Center");
        UIScrollView = transform.Find("Center/Scroll View");
        UIDetailPanel = transform.Find("Center/DetailPanel");
        UILeftBtn = transform.Find("Left/Button");
        UIRightBtn = transform.Find("Right/Button");

        UIDeletePanel = transform.Find("Bottom/DeletePanel");
        UIDeleteBackBtn = transform.Find("Bottom/DeletePanel/Back");
        UIDeleteInfoText = transform.Find("Bottom/DeletePanel/InfoText");
        UIDeleteConfirmBtn = transform.Find("Bottom/DeletePanel/ConfirmBtn");
        UIBottomMenus = transform.Find("Bottom/BottomMenus");
        UIDeleteBtn = transform.Find("Bottom/BottomMenus/DeleteBtn");
        UIDetailBtn = transform.Find("Bottom/BottomMenus/DetailBtn");

        UIDeletePanel.gameObject.SetActive(false);
        UIBottomMenus.gameObject.SetActive(true);
    }
    void InitClick(){
        UIMenuWeapon.GetComponent<Button>().onClick.AddListener(OnClickWeapon);
        UIMenuFood.GetComponent<Button>().onClick.AddListener(OnClickFood);
        UICloseBtn.GetComponent<Button>().onClick.AddListener(OnClickClose);
        UILeftBtn.GetComponent<Button>().onClick.AddListener(OnClickLeft);
        UIRightBtn.GetComponent<Button>().onClick.AddListener(OnClickRight);

        UIDeleteBackBtn.GetComponent<Button>().onClick.AddListener(OnDeleteBack);
        UIDeleteConfirmBtn.GetComponent<Button>().onClick.AddListener(OnDeleteConfirm);
        UIDeleteBtn.GetComponent<Button>().onClick.AddListener(OnDelete);
        UIDetailBtn.GetComponent<Button>().onClick.AddListener(OnDetail);
    }

    void OnDetail(){
        print(">>>>>>> OnDetail()");
    }
    //进入删除模式 ; 左下角删除按钮
    void OnDelete(){
        print(">>>>>>> OnDelete()");
        curMode = PackageMode.delete;
        UIDeletePanel.gameObject.SetActive(true);
    }
    //确认删除
    void OnDeleteConfirm(){
        print(">>>>>>> OnDeleteConfirm()");
        if (this.deleteChooseUid == null)
            return;
        if (this.deleteChooseUid.Count == 0)
            return;
        MainGame.Instance.DeletePackageItems(this.deleteChooseUid);
        //删除完成后刷新整个背包页面
        RefreshUI();
    }
    //退出删除模式
    void OnDeleteBack(){
        print(">>>>>>> OnDeleteBack()");
        curMode = PackageMode.normal;
        UIDeletePanel.gameObject.SetActive(false);
        //重置选中的删除列表
        deleteChooseUid = new List<string>();
        //刷新选中状态
        RefreshDeletePanel();
    }
    void OnClickRight(){
        print(">>>>>>> OnClickRight()");
    }
    void OnClickLeft(){
        print(">>>>>>> OnClickLeft()");
    }
    void OnClickWeapon(){
        print(">>>>>>> OnClickWeapon()");
    }
    void OnClickFood(){
        print(">>>>>>> OnClickFood()");
    }
    void OnClickClose(){
        ClosePanel();
        UIManager.Instance.OpenPanel(UIManager.UIConst.MainPanel);
    }
}

 修改LotteryPanel.cs脚本:

using System.Collections.Generic;
using UnityEditor.Build.Content;
using UnityEngine;
using UnityEngine.UI;
public class LotteryPanel : BasePanel{
    Transform UIClose;
    Transform UICenter;
    Transform UILottery10;
    Transform UILottery1;
    GameObject LotteryCellPrefab;
    protected override void Awake(){
        base.Awake();
        InitUI();
        InitPrefab();
    }
    void InitUI() {
        UIClose = transform.Find("TopRight/Close");
        UICenter = transform.Find("Center");
        UILottery10 = transform.Find("Bottom/Lottery10");
        UILottery1 = transform.Find("Bottom/Lottery1");
        UILottery10.GetComponent<Button>().onClick.AddListener(OnLottert10Btn);
        UILottery1.GetComponent<Button>().onClick.AddListener(OnLottert1Btn);

        UIClose.GetComponent<Button>().onClick.AddListener (OnClose);
    }
    void OnClose(){
        print(">>>>>>>> OnClose");
        ClosePanel();
        UIManager.Instance.OpenPanel(UIManager.UIConst.MainPanel);
    }
    void OnLottert1Btn(){
        print(">>>>>>>> OnLottert1Btn");
        //销毁原本的卡片
        for (int i = 0; i < UICenter.childCount; i++)
            Destroy(UICenter.GetChild(i).gameObject);
        //抽卡获得一张新的物品
        PackageLocalItem item = MainGame.Instance.GetLotteryRandom1();
        Transform LotteryCellTran = Instantiate(LotteryCellPrefab.transform, UICenter) as Transform;
        // 对卡片做信息展示刷新
        LotteryCell lotteryCell = LotteryCellTran.GetComponent<LotteryCell>();
        lotteryCell.Refresh(item, this);
    }
    void OnLottert10Btn(){
        print(">>>>>>>> OnLottert10Btn");
        List<PackageLocalItem> packageLocalItems = MainGame.Instance.GetLotteryRandom10(sort: true);
        for (int i = 0; i < UICenter.childCount; i++)
            Destroy(UICenter.GetChild(i).gameObject);
        foreach (PackageLocalItem item in packageLocalItems){
            Transform LotteryCellTran = Instantiate(LotteryCellPrefab.transform, UICenter) as Transform;
            // 对卡片做信息展示刷新
            LotteryCell lotteryCell = LotteryCellTran.GetComponent<LotteryCell>();
            lotteryCell.Refresh(item, this);
        }
    }
    void InitPrefab() {
        LotteryCellPrefab = Resources.Load("Prefabs/Panel/Lottery/LotteryItem") as GameObject;
    }
}

End.

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

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

相关文章

软件价值10-数字时钟

这是一个数字时钟程序&#xff1a; # importing whole module from tkinter import * from tkinter.ttk import *# importing strftime function to # retrieve systems time from time import strftime# creating tkinter window root Tk() root.title(Clock)# This functio…

多路服务器技术如何处理大量并发请求?

在当今的互联网时代&#xff0c;随着用户数量的爆炸性增长和业务规模的扩大&#xff0c;多路服务器技术已成为处理大量并发请求的关键手段。多路服务器技术是一种并行处理技术&#xff0c;它可以通过多个服务器同时处理来自不同用户的请求&#xff0c;从而显著提高系统的整体性…

three.js 箭头ArrowHelper的实践应用

效果&#xff1a; 代码&#xff1a; <template><div><el-container><el-main><div class"box-card-left"><div id"threejs" style"border: 1px solid red"></div></div></el-main></…

复制和粘贴文本时剥离格式的5种方法(MacWindows)

您可能每天复制和粘贴多次。虽然它是一个非常方便的功能&#xff0c;但最大的烦恼之一就是带来了特殊的格式。从网络上获取一些文本&#xff0c;您经常会发现粘贴到文档中时&#xff0c;它保持原始样式。 我们将展示如何使用一些简单的技巧在不格式化的情况下复制和粘贴。 1.…

Zabbix 配置实时开通的LDAP认证-基于AD

介绍 本教程适用于6.4-7.0版本的Zabbix&#xff0c;域控&#xff08;AD&#xff09;使用Windows Server 2022搭建&#xff0c;域控等级为 2016。 域控域名为 songxwn.com 最终实现AD用户统一认证&#xff0c;统一改密&#xff0c;Zabbix用户自动添加。&#xff08;6.4之前不…

【远程通信系统】服务端初始化

服务器架构&#xff1a;libevent 线程池 数据库&#xff1a;MySQL 有两张表&#xff1a;chat_user和chat_group&#xff0c;分别保存用户信息和群信息 在线用户和群的保存&#xff1a; struct User {std::string name;//账号&#xff08;用户名struct bufferevent* bev;//客…

WordPress如何实现随机显示一句话经典语录?怎么添加到评论框中?

我们在一些WordPress网站的顶部或侧边栏或评论框中&#xff0c;经常看到会随机显示一句经典语录&#xff0c;他们是怎么实现的呢&#xff1f; 其实&#xff0c;boke112百科前面跟大家分享的『WordPress集成一言&#xff08;Hitokoto&#xff09;API经典语句功能』一文中就提供…

94.网游逆向分析与插件开发-游戏窗口化助手-地图数据获取的逆向分析与C++代码还原

内容参考于&#xff1a;易道云信息技术研究院VIP课 上一个内容&#xff1a;升级经验数据获取的逆向分析 码云地址&#xff08;游戏窗口化助手 分支&#xff09;&#xff1a;https://gitee.com/dye_your_fingers/sro_-ex.git 码云版本号&#xff1a;c4351a5b346d8953a1a8e3ec…

Android:国际化弹出框

3.13 风格与主题、国际化 1、应用国际化 应用国际化&#xff0c;通过修改系统语言&#xff0c;应用显示语言跟着改变。 选择Locale,点击>>符号。 创建多个国家&#xff0c;地区strings.xml文件&#xff0c;有一个默认strings.xml文件&#xff0c;各个stirngs.xml中<…

以“防方视角”观社工钓鱼攻击

为方便您的阅读&#xff0c;可点击下方蓝色字体&#xff0c;进行跳转↓↓↓ 01 案例概述02 攻击路径03 防方思路 01 案例概述 这篇文章来自奇安信攻防社区“小艾”&#xff0c;记录的某师傅通过社工钓鱼诱导企业员工点击含有木马的文件&#xff0c;侵入系统取得了终端控制权。接…

中科大计网学习记录笔记(四):Internet 和 ISP | 分组延时、丢失和吞吐量

前言&#xff1a; 学习视频&#xff1a;中科大郑烇、杨坚全套《计算机网络&#xff08;自顶向下方法 第7版&#xff0c;James F.Kurose&#xff0c;Keith W.Ross&#xff09;》课程 该视频是B站非常著名的计网学习视频&#xff0c;但相信很多朋友和我一样在听完前面的部分发现信…

27. 云原生流量治理之kubesphere灰度发布

云原生专栏大纲 文章目录 灰度发布介绍灰度发布策略KubeSphere中恢复发布策略蓝绿部署金丝雀发布流量镜像 灰度发布实战部署自制应用金丝雀发布创建金丝雀发布任务测试金丝雀发布情况 蓝绿部署创建蓝绿部署测试蓝绿部署情况 流量镜像创建流量进行任务测试流量镜像情况 灰度发布…

Vue CLI学习笔记

在看任何开源库的源码之前&#xff0c;必须先了解它有哪些功能&#xff0c;这样才能针对性地分模块阅读源码。 Vue CLI 简介 Vue CLI是Vue.js的官方命令行工具&#xff0c;它是一个基于Vue.js进行快速开发的完整系统。 通过Vue CLI&#xff0c;开发者可以快速搭建和开发Vue.js项…

机器学习--K-近邻算法常见的几种距离算法详解

文章目录 距离度量1 欧式距离(Euclidean Distance)2 曼哈顿距离(Manhattan Distance)3 切比雪夫距离 (Chebyshev Distance)4 闵可夫斯基距离(Minkowski Distance)5 标准化欧氏距离 (Standardized EuclideanDistance)6 余弦距离(Cosine Distance)7 汉明距离(Hamming Distance)【…

使用 WPF + Chrome 内核实现高稳定性的在线客服系统复合应用程序

对于在线客服与营销系统&#xff0c;客服端指的是后台提供服务的客服或营销人员&#xff0c;他们使用客服程序在后台观察网站的被访情况&#xff0c;开展营销活动或提供客户服务。在本篇文章中&#xff0c;我将详细介绍如何通过 WPF Chrome 内核的方式实现复合客服端应用程序。…

前端-Vue項目初始化

大家好我是苏麟 , 今天聊聊前端依赖 Ant Design Vue 快速初始化项目 . Ant Design Vue官网 : 快速上手 - Ant Design Vue (antdv.com) 初始化项目 找到文档->快速上手 脚手架命令 : npm install -g vue/cli 找到一个文件夹(不要在中文路径) 下打开cmd窗口输入脚手架命令 成…

PyTorch 2.2大更新!集成FlashAttention-2,性能提升2倍

【新智元导读】新的一年&#xff0c;PyTorch也迎来了重大更新&#xff0c;PyTorch 2.2集成了FlashAttention-2和AOTInductor等新特性&#xff0c;计算性能翻倍。 新的一年&#xff0c;PyTorch也迎来了重大更新&#xff01; 继去年十月份的PyTorch大会发布了2.1版本之后&#…

查看NodeJs版本和查看NPM版本

Windows10 Dos命令下 查看NodeJs版本和查看NPM版本 NodeJs的命令是&#xff1a;node -v Npm的命令是&#xff1a;npm -v 下图&#xff1a; 记录下&#xff01;~

Docker Compose 构建 LNMP 环境:一站式 PHP 网站部署指南

Docker Compose 构建 LNMP 环境&#xff1a;一站式 PHP 网站部署指南 简介环境准备和安装安装 Docker安装 Docker Compose准备项目目录结构 编写 Docker Compose 文件基础结构配置 Nginx 服务配置 PHP 服务配置 MySQL 服务完整的 docker-compose.yml 示例 Nginx 容器配置创建 N…

Text2SQL研究-Chat2DB体验与剖析

文章目录 概要业务数据库配置Chat2DB安装设置原理剖析 小结 概要 近期笔者在做Text2SQL的研究&#xff0c;于是调研了下Chat2DB&#xff0c;基于车辆订单业务做了一些SQL生成验证&#xff0c;有了一点心得&#xff0c;和大家分享一下.&#xff1a; 业务数据库设置 基于车辆订…