• Unity3d


    现在开始处理游戏的背包系统。

    处理背包系统的第一步是读取物品信息,即将我们设计好的物品读取到内存中,实现调用。

    思路:①建立txt文本,设计物品信息;②建立ObjectsInfo类,在类中读取txt文本中的信息。

    脚本如下:

    ①建立txt文本

    序号      名称      icon名称    类型  hp mp price_sell.price_buy

    1001,生命药水,icon_01,Drug,100,0, 50,100

    1002,魔法药水,icon_02,Drug,0,100, 60,120

    ②建立ObjectsInfo类

    Class ObjectsInfo

    {

        public static ObjectsInfo _intance;

        public TextAsset objectText;

        public Dictionary <int,ObjectInfo> ObjectInfoDict = new Dictionary<int,ObjectInfo>();

        void Awake()

        {

        _intance = this;

        Readinfo();

        }  

        public ObjectInfo GetObjectInfoById(int id)

        {

            ObjectInfo = null;

            ObjectInfoDict.TryGetValue(id,out info);

            return info;

        }

        public void ReadInfo( )

        {

        string text = objectText.text;

        string[ ] strArray = text.Split(' ');

        foreach( string str in strArray )

        {

        ObjectInfo info = new ObjectInfo( );

        stringp[] strPro = str.Split(',');

        int id = int.Parse(strPro[0]);

        string name = strPro[1];

        string icon_name = strPro[2];

        string strType = strPro[3];

        info.id = id; info.name = name; info.icon_name = icon_name;

        ObjectType type = ObjectType.Drug;

        switch( strType)

            {

                case "Drug":

                type = Object.Drug;

                break;

                case "Equip":

                type = Object.Equip;

                break;

                case "Mat":

                type = Object.Mat;

                break;

            }

        info.type = type;

        if(type == Object.Drug)

        {

            int hp = strPro[4];

            in mp = strPro[5];

            int price_sell = strPro[6];

            int price_buy = strPro[7];

            info.hp = hp;info.mp =mp;info.price_sell = price_sell; info.price_buy = price_buy;

        }

        ObjectInfoDict.Add(id,info);

    }

    }

    public eunm ObjectType{Drug,Equip,Mat}

    public Class ObjectInfo

    {

    public int id,hp,mp,price_sell,price_buy;

    public string name,icon_name,type;

    }

    以上便实现了物品信息存储到内存空间,本日总结到此为止。

  • 相关阅读:
    POJ 2411 Mondriaan's Dream
    POJ 2505 A multiplication game
    HDOJ(HDU) 3949 XOR
    雅礼集训DAY 6 T1 xmasdag
    bzoj 2159: Crash 的文明世界
    如何查看Ubuntu版本
    Ubuntu如何安装谷歌Chrome浏览器
    使用nano编辑器进行查找和替换
    Ubuntu修改用户和root密码
    Anaconda/Conda创建环境时报错的解决方案
  • 原文地址:https://www.cnblogs.com/yanbenxin/p/5815493.html
Copyright © 2020-2023  润新知