Esempio n. 1
0
        /// <summary>
        /// Save Data
        /// </summary>
        public void SaveGameFile(int groupID, string saveName, int indexID)
        {
            GameSaveData gameSave = GameSaveData.CreateSave(groupID, indexID);

            GameSaveDataItem saveItem = Create_gameSaveData_GroupNav(groupID, saveName);

            string SaveFilePath = Application.persistentDataPath + "/SaveData";

            if (!Directory.Exists(SaveFilePath))
            {
                Directory.CreateDirectory(SaveFilePath);
            }

            ///Crete Save Group
            DirectoryInfo info = new DirectoryInfo(SaveFilePath);
            string        saveGroupFilePath = SaveFilePath + "/Sav_" + saveName;

            if (!Directory.Exists(saveGroupFilePath))
            {
                Directory.CreateDirectory(saveGroupFilePath);
            }

            string savePath    = saveGroupFilePath + "/" + saveName + "_" + indexID + ".sav";
            string savePathNav = saveGroupFilePath + "/" + saveName + "_" + indexID + ".nav";

            SaveData(savePath, gameSave);
            SaveData(savePathNav, saveItem);

            if (File.Exists(savePath) && File.Exists(savePathNav))
            {
                Debug.Log("Save Success");
            }
        }
Esempio n. 2
0
        private GameSaveDataItem Create_gameSaveData_GroupNav(int groupID, string saveName)
        {
            GameSaveDataItem groupData = new GameSaveDataItem(
                groupID,
                saveName,
                GetGameDataIndex(saveName) + 1,
                GetCurrentTime(),
                1000);

            return(groupData);
        }
Esempio n. 3
0
        public GameSaveData GetSaveData(int groupID, int saveIndex)
        {
            GameSaveDataItem item = GetSaveNavigatorData(groupID, saveIndex);

            if (item != null)
            {
                var savedata = GetSaveDataBySaveID(item.saveName, groupID, saveIndex);
                if (savedata != null)
                {
                    return(savedata);
                }
            }
            DebugPlus.LogError("GetSave Data null! ,groupID= " + groupID + "  saveIndex=" + saveIndex);
            return(null);
        }
Esempio n. 4
0
        private GameSaveDataItem LoadSaveNavigator(string savePath)
        {
            GameSaveDataItem result = null;

            if (File.Exists(savePath))
            {
                try
                {
                    result = (GameSaveDataItem)GetData(savePath, typeof(GameSaveDataItem));
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取存档
        /// </summary>
        /// <param name="saveID"></param>
        /// <returns></returns>
        private GameSaveData GetSaveDataBySaveID(string groupName, int groupID, int saveIndex)
        {
            GameSaveDataItem data = GetSaveNavigatorData(groupID, saveIndex);

            if (data == null)
            {
                DebugPlus.LogError("Save Not Exists! SaveID=  " + data.saveName + "_" + data.Index);
                return(null);
            }
            else
            {
                string SaveFilePath = Application.persistentDataPath + "/SaveData/Sav_" + groupName;
                if (Directory.Exists(SaveFilePath))
                {
                    DirectoryInfo dirs  = new DirectoryInfo(SaveFilePath);
                    var           files = dirs.GetFiles();
                    DebugPlus.Log("Save num=" + files.Length / 2);

                    for (int i = 0; i < files.Length; i++)
                    {
                        if (files[i].Name == groupName + "_" + saveIndex + ".sav")
                        {
                            try
                            {
                                var savePath = files[i].FullName;
                                var saveData = LoadSave(savePath);
                                if (saveData != null)
                                {
                                    return(saveData);
                                }
                            }
                            catch (Exception e)
                            {
                                Debug.LogError(e);
                                return(null);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 6
0
        /// <summary>
        /// 获取同组最新存档
        /// </summary>
        /// <param name="groupID"></param>
        /// <returns></returns>
        public GameSaveDataItem GetLatestSaveData(int groupID)
        {
            var saveList = GetSaveNavigatorDataList(groupID);

            if (saveList.Count == 0)
            {
                return(null);
            }

            for (int i = 0; i < saveList.Count - 1; i++)
            {
                for (int j = 0; j < saveList.Count - 1 - i; j++)
                {
                    if (Utility.CompareDate(saveList[j].SaveDate, saveList[j + 1].SaveDate) > 0)
                    {
                        // t1>t2
                        GameSaveDataItem temp = saveList[j];
                        saveList[j]     = saveList[j + 1];
                        saveList[j + 1] = temp;
                    }
                }
            }
            return(saveList[0]);
        }