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

news/2024/7/6 17:54:22/文章来源:https://blog.csdn.net/weixin_69360830/article/details/136058637

基于      项目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.luyixian.cn/news_show_955618.aspx

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

相关文章

升级Oracle 单实例数据库19.3到19.22

需求 我的Oracle Database Vagrant Box初始版本为19.3&#xff0c;需要升级到最新的RU&#xff0c;当前为19.22。 以下操作时间为为2024年2月5日。 补丁下载 补丁下载文档参见MOS文档&#xff1a;Primary Note for Database Proactive Patch Program (Doc ID 888.1)。 补丁…

深兰科技陈海波出席CTDC2024第五届首席技术官领袖峰会:“民主化AI”的到来势如破竹

1月26日&#xff0c;CTDC 2024 第五届首席技术官领袖峰会暨出海创新峰会在上海举行。深兰科技创始人、董事长陈海波受邀出席了本届会议&#xff0c;并作为首个演讲嘉宾做了题为“前AGI时代的生产力革命范式”的行业分享。 作为国内顶级前瞻性技术峰会&#xff0c;CTDC首席技术官…

陪护系统|陪护小程序提升长者护理服务质量的关键

在如今逐渐老龄化的社会中&#xff0c;老年人对更好的护理服务需求不断增加。科技的进步使得陪护小程序系统源码成为提供优质服务的重要途径之一。本文将从运营角度探讨如何优化陪护小程序系统源码&#xff0c;提升长者护理服务的质量。 首先&#xff0c;我们需要对软件的设计和…

论文阅读-面向公平性的分布式系统负载均衡机制

摘要 当一组自利的用户在分布式系统中共享多个资源时&#xff0c;我们面临资源分配问题&#xff0c;即所谓的负载均衡问题。特别地&#xff0c;负载均衡被定义为将负载分配到分布式系统的服务器上&#xff0c;以便最小化作业响应时间并提高服务器的利用率。在本文中&#xff0…

MySQL篇----第十一篇

系列文章目录 文章目录 系列文章目录前言一、BLOB 和 TEXT 有什么区别?二、MySQL_fetch_array 和 MySQL_fetch_object 的区别是什么?三、MyISAM 表格将在哪里存储,并且还提供其存储格式?四、MySQL 如何优化 DISTINCT?五、如何显示前 50 行?前言 前些天发现了一个巨牛的人…

springboot集成easypoi导出多sheet页

pom文件 <dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-base</artifactId><version>4.1.0</version> </dependency> 导出模板&#xff1a; 后端代码示例&#xff1a; /*** 导出加油卡进便利店大额审批列…

Java+SpringBoot:构建稳定高效的计算机基础教学平台

✍✍计算机编程指导师 ⭐⭐个人介绍&#xff1a;自己非常喜欢研究技术问题&#xff01;专业做Java、Python、微信小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。 ⛽⛽实战项目&#xff1a;有源码或者技术上的问题欢迎在评论区一起讨论交流&#xff01; ⚡⚡ Java实战 |…

<网络安全>《15 移动安全管理系统》

1 概念 移动安全管理系统&#xff0c;MSM&#xff0c;Mobile security management,提供大而全的功能解决方案&#xff0c;覆盖了企业移动信息化中所涉及到安全沙箱、数据落地保护、威胁防护、设备管理、应用管理、文档管理、身份认证等各个维度。移动安全管理系统将设备管理和…

Python学习路线 - Python高阶技巧 - 拓展

Python学习路线 - Python高阶技巧 - 拓展 闭包闭包注意事项 装饰器装饰器的一般写法(闭包写法)装饰器的语法糖写法 设计模式单例模式工厂模式 多线程进程、线程并行执行多线程编程threading模块 网络编程Socket客户端和服务端Socket服务端编程实现服务端并结合客户端进行测试 S…

计算机毕业设计 | SpringBoot大型旅游网站 旅行后台管理系统(附源码)

1&#xff0c; 概述 1.1 项目背景 随着互联网技术的快速发展和普及&#xff0c;旅游行业逐渐转向线上&#xff0c;越来越多的游客选择在线预订旅游产品。传统的线下旅行社模式已不能满足市场需求&#xff0c;因此&#xff0c;开发一个高效、便捷的旅游网站成为行业的迫切需求…

论文阅读-Transformer-based language models for software vulnerability detection

「分享了一批文献给你&#xff0c;请您通过浏览器打开 https://www.ivysci.com/web/share/biblios/D2xqz52xQJ4RKceFXAFaDU/ 您还可以一键导入到 ivySCI 文献管理软件阅读&#xff0c;并在论文中引用 」 本文主旨&#xff1a;本文提出了一个系统的框架来利用基于Transformer的语…

VSTO打包Word插件WPS也支持

启动AdvancedInstallerPortable.exe打包软件 选择“加载项” 选择“office加载项”之后点“创建项目” 四、输入自已的插件名和公司名 任选一种包类型 五、选择包的保存位置 勾选“vsto office加载项” 六、选择要打包的项目debug文件夹 选择相应版本 配置相应环境 选择语言 添…

uniapp设置不显示顶部返回按钮

一、pages文件中&#xff0c;在相应的页面中设置 "titleNView": {"autoBackButton": false} 二、对应的页面文件设置隐藏元素 document.querySelector(.uni-page-head-hd).style.display none

Linux内核与驱动面试经典“小”问题集锦(4)

接前一篇文章&#xff1a;Linux内核与驱动面试经典“小”问题集锦&#xff08;3&#xff09; 问题5 问&#xff1a;Linux内核中内存分配都有哪些方式&#xff1f;它们之间的使用场景都是什么&#xff1f; 备注&#xff1a;这个问题是笔者近期参加蔚来面试时遇到的一个问题。这…

redis大数据统计之hyperloglog,GEO,Bitmap

目录 一、亿级系统常见的四中统计 1、聚合统计 2、排序统计 3、二值统计 4、基数统计 二、hyperloglog 去重的方式有哪些&#xff1f; hyperloglog实战演示 1、技术选型 2、代码演示 三、GEO GEO实战演示 四、Bitmap 一、亿级系统常见的四中统计 1、聚合统计 聚…

MacOS - 时间如何显示读秒?

mac 上的时间比较精确&#xff0c;所以打算把秒也显示出来&#xff0c;网上搜的大部分都是通过设置来设置的&#xff0c;但是一般会找不到设置&#xff0c;反正我就这里推荐使用命令来设置 在设置中进行设置 Tips&#xff1a;如果没有在设置中找到对应设置可以用以下方案 设置时…

7.0 Zookeeper 客户端基础命令使用

zookeeper 命令用于在 zookeeper 服务上执行操作。 首先执行命令&#xff0c;打开新的 session 会话&#xff0c;进入终端。 $ sh zkCli.sh 下面开始讲解基本常用命令使用&#xff0c;其中 acl 权限内容在后面章节详细阐述。 ls 命令 ls 命令用于查看某个路径下目录列表。…

【RK3288 Android6 T8, 突然无声音问题排查】

文章目录 【RK3288 Android6 T8&#xff0c; 突然无声音问题排查】问题描述问题调查patch 【RK3288 Android6 T8&#xff0c; 突然无声音问题排查】 问题描述 页面上方突然出现音量进度条&#xff0c;小铃铛图标显示静音状态&#xff0c;不再播报语音 手动去安卓设置内查看&a…

【人工智能】神奇的Embedding:文本变向量,大语言模型智慧密码解析(10)

什么是嵌入&#xff1f; OpenAI 的文本嵌入衡量文本字符串的相关性。嵌入通常用于&#xff1a; Search 搜索&#xff08;结果按与查询字符串的相关性排序&#xff09;Clustering 聚类&#xff08;文本字符串按相似性分组&#xff09;Recommendations 推荐&#xff08;推荐具有…

Android.mk 语法详解

一.Android.mk简介 Android.mk 是Android 提供的一种makefile 文件,注意用来编译生成&#xff08;exe&#xff0c;so&#xff0c;a&#xff0c;jar&#xff0c;apk&#xff09;等文件。 二.Android.mk编写 分析一个最简单的Android.mk LOCAL_PATH : $(call my-dir) //定义了…