关闭

《组合变身小宠物游戏》ConfigManager(修改更新中)【初学者】

111人阅读 评论(0) 收藏 举报
分类:
using UnityEngine;
using Mono.Xml;
using System.Security;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Reflection;
using ZPStudio;

public class ConfigManager : MonoBehaviour
{

    private static ConfigManager mInstance = null;
 
    public Dictionary<int, PetXmlData> petXmlDataDict = new Dictionary<int, PetXmlData>();
    public List<int> petIdList = new List<int>();

    public Dictionary<int, PetCombineXmlData> PetCombineXmlDataDict = new Dictionary<int, PetCombineXmlData>();
    public static ConfigManager Instance
    {
        get
        {
            return mInstance;
        }
    }
    //*************
    public int GetpetXmlDictCount()//获取长度
    {
        return petXmlDataDict.Count;
    }

    public PetXmlData GetPetXMLInfo(int DictOrder)
    {
        return petXmlDataDict[DictOrder];
    }

    public PetXmlData GetPetData(int id)//根据id获得宠物数据信息
    {
        PetXmlData tmp = null;
        petXmlDataDict.TryGetValue(id, out tmp);
        return tmp;
    }
    //*******
    public int GetPetCombineDicCount()
    {
        return PetCombineXmlDataDict.Count;
    }

    public PetCombineXmlData GetPetCombineDicData(int id1, int id2)//根据id1和id2确定某条数据(之后获取它的combineId)
    {
        
        for (int i = 0; i < PetCombineXmlDataDict.Count; i++)
        {
            PetCombineXmlData tmp = null;
            PetCombineXmlDataDict.TryGetValue(i, out tmp);
            if (tmp != null &&tmp.id1 == id1 && tmp.id2 == id2)
                return tmp;
        }
        return null;
    }

    //*************
    public bool IsLoaded
    {
        get;
        private set;
    }

    void Awake()
    {
        if (Instance != null)
        {
            Destroy(gameObject);
        }
        else
        {
            DontDestroyOnLoad(gameObject);
            mInstance = this;
            mInstance.InitGlobal();
            mInstance.StartCoroutine(InitConfig());
        }
    }


    void InitGlobal()
    {
        DataRecord.Load();

    }

    IEnumerator InitConfig()
    {
        IsLoaded = false;

        petXmlDataDict.Clear();
        PetCombineXmlDataDict.Clear();
        yield return StartCoroutine(ReadXmlData<int, PetXmlData>("Pet", "id", petXmlDataDict));
        yield return StartCoroutine(ReadXmlData<int, PetCombineXmlData>("PetCombine", "id", PetCombineXmlDataDict));
        IsLoaded = true;
        //UIManager.instance.ShowPanel(UIPanelNames.PetIllustrationsPanel);
    }

    public IEnumerator ReadXmlData<TKEY, TRECORD>(string filename, string keyName, Dictionary<TKEY, TRECORD> dictRecord) where TRECORD : new()
    {
        string path = Application.streamingAssetsPath + "/" + filename + ".xml";
        WWW www = null;
        if (Application.platform == RuntimePlatform.Android)
        {
            www = new WWW(path);
        }
        else
        {
            www = new WWW("file://" + path);
        }
        yield return www;

        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.Log(string.Format("Error Message : {0}", www.error));
            yield break;
        }

        XmlReader.ReadXmlData<TKEY, TRECORD>(www.text, keyName, dictRecord);
    }

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:8319次
    • 积分:415
    • 等级:
    • 排名:千里之外
    • 原创:34篇
    • 转载:1篇
    • 译文:0篇
    • 评论:7条
    心灵鸡汤
    我想,你总觉得自己活得不快乐的原因,大体应该是:既无法忍受目前的状态,又没有能力改变眼前这一切;你虽然可以像只猪一样懒,缺无法像只猪一样懒得心安理得。
    交流学习
    QQ1987885497
    文章分类