Exemple #1
0
    public static void Save(SAVE_DATA_TYPE type)
    {
        SaveAble kSaveAble = null;

        if (m_DicSaveDatas != null && m_DicSaveDatas.TryGetValue(type, out kSaveAble))
        {
            kSaveAble.Save();
        }
    }
Exemple #2
0
    public static void LoadAll(System.Action <bool> onFinish = null)
    {
#if UNITY_EDITOR
        _UKey = "ABC";
#else
        _UKey = SystemInfo.deviceUniqueIdentifier;
#endif

        int index  = 0;
        int iCount = Enum.GetValues(typeof(SAVE_DATA_TYPE)).Length;

        m_DicTypeSaveDatas = new Dictionary <Type, SaveAble>();
        m_DicSaveDatas     = new Dictionary <SAVE_DATA_TYPE, SaveAble>();

        foreach (SAVE_DATA_TYPE item in Enum.GetValues(typeof(SAVE_DATA_TYPE)))
        {
            try
            {
                Type kTargetType = Type.GetType(item.ToString());
                if (kTargetType != null)
                {
                    SaveAble saveData = SaveAble.Load(kTargetType);
                    if (saveData == null)
                    {
                        saveData = CreateInstance <SaveAble>(kTargetType);
                    }
                    m_DicSaveDatas.Add(item, saveData);
                    m_DicTypeSaveDatas.Add(kTargetType, saveData);
                    saveData.OnLoadFinish();
                }
                else
                {
                    Debug.LogError("cannot find save data class for enum: " + item.ToString());
                }
                index++;
                //m_dProgress = index * 1f / iCount;
            }
            catch
            {
                Debug.LogError("Error loading data : " + item.ToString());
            }
        }

        if (null != onFinish)
        {
            onFinish(true);
        }
    }
Exemple #3
0
    public static T getSaveAbleData <T>() where T : SaveAble
    {
        SaveAble kRet = null;

        if (m_DicTypeSaveDatas != null && m_DicTypeSaveDatas.TryGetValue(typeof(T), out kRet))
        {
            return(kRet as T);
        }
        return(null);

        /*Type kType = typeof(T);
         * string kTypeName = kType.FullName;
         * SAVE_DATA_TYPE kEnumType = (SAVE_DATA_TYPE)Enum.Parse(typeof(SAVE_DATA_TYPE), kTypeName);
         * T kRet = null;
         * if (m_DicSaveDatas != null && m_DicSaveDatas.TryGetValue (kEnumType, out kRet))
         * {
         *      return kRet;
         * }
         * return null;*/
    }
Exemple #4
0
    //读档时调用的函数//
    public static SaveAble Load(System.Type type)
    {
        string gameDataFile = Utils.GetDataPath() + "/" + type.Name + ".xml";

        if (xs.hasFile(gameDataFile))
        {
            try
            {
                string dataString = xs.LoadXML(gameDataFile);

                object   gameDataFromXML = xs.DeserializeObject(dataString, type);
                SaveAble sa = (SaveAble)gameDataFromXML;
                if (null != sa && sa.key == GDM.UKey)
                {
                    //是合法存档//
                    SaveAble t = (SaveAble)sa;
                    Debug.Log("读档成功......");
                    return(t);
                }
                else
                {
                    //是非法拷贝存档//
                    string fileKey = "";
                    if (null != sa)
                    {
                        fileKey = sa.key;
                    }
                    Debug.Log("不是本设备的存档!存档清除:key=" + GDM.UKey + "; FileKey=" + fileKey + "; File:" + type.Name);
                    //留空:游戏启动后数据清零,存档后作弊档被自动覆盖//
                }
            } catch (System.Exception e)
            {
                Debug.Log("存档Load出错!存档清除:key=" + GDM.UKey + "; File:" + type.Name);
                Debug.Log("e.Message: " + e.Message);
            }
        }

        return(null);
    }