private void LoadNPCs()
        {
            if (mAllNpcs.Count > 0)
            {
                return;
            }

            string npcDataDirectory = CommonData.npcsDataFilePath;

            DirectoryInfo npcDirectoryInfo = new DirectoryInfo(npcDataDirectory);

            FileInfo[] npcFiles = npcDirectoryInfo.GetFiles();

            for (int i = 0; i < npcFiles.Length; i++)
            {
                FileInfo npcData = npcFiles [i];
                if (npcData.Extension != ".json")
                {
                    continue;
                }
                NPC npc = null;
                if (npcData.Name.Contains("Normal"))
                {
                    npc = DataHandler.LoadDataToSingleModelWithPath <NPC> (npcData.FullName);
                }
                else if (npcData.Name.Contains("Trader"))
                {
                    npc = DataHandler.LoadDataToSingleModelWithPath <Trader> (npcData.FullName);
                }
                mAllNpcs.Add(npc);
            }
        }
        /// <summary>
        /// 玩家角色数据重置回初始状态
        /// </summary>
        public void ResetPlayerDataToOriginal()
        {
            string sourcePlayerDataPath = CommonData.oriPlayerDataFilePath;

            string targetPlayerDataPath = CommonData.playerDataFilePath;

            // 使用原始角色数据作为重置数据源
            PlayerData resetPd = DataHandler.LoadDataToSingleModelWithPath <PlayerData> (sourcePlayerDataPath);


            // 学习数据更新进新数据中
            resetPd.totalLearnedWordCount = LearningInfo.Instance.learnedWordCount;
            resetPd.totalUngraspWordCount = LearningInfo.Instance.ungraspedWordCount;

            resetPd.simpleWordContinuousRightRecord    = Player.mainPlayer.simpleWordContinuousRightRecord;
            resetPd.maxSimpleWordContinuousRightRecord = Player.mainPlayer.maxSimpleWordContinuousRightRecord;
            resetPd.titleQualificationsOfSimple        = Player.mainPlayer.titleQualificationsOfSimple;

            resetPd.mediumWordContinuousRightRecord    = Player.mainPlayer.mediumWordContinuousRightRecord;
            resetPd.maxMediumWordContinuousRightRecord = Player.mainPlayer.maxMediumWordContinuousRightRecord;
            resetPd.titleQualificationsOfMedium        = Player.mainPlayer.titleQualificationsOfMedium;

            resetPd.masterWordContinuousRightRecord    = Player.mainPlayer.masterWordContinuousRightRecord;
            resetPd.maxMasterWordContinuousRightRecord = Player.mainPlayer.maxMasterWordContinuousRightRecord;
            resetPd.titleQualificationsOfMaster        = Player.mainPlayer.titleQualificationsOfMaster;

            // 一些不随重置改变的属性
            resetPd.isNewPlayer          = Player.mainPlayer.isNewPlayer;
            resetPd.needChooseDifficulty = Player.mainPlayer.needChooseDifficulty;
            resetPd.mapIndexRecord.Clear();

            // 重置本次探索的探索数据
            resetPd.learnedWordsCountInCurrentExplore = 0;
            resetPd.correctWordsCountInCurrentExplore = 0;
            resetPd.totaldefeatMonsterCount           = 0;

            resetPd.currentExploreStartDateString = DateTime.Now.ToShortDateString();
            resetPd.spellRecord.Clear();

            if (ExploreManager.Instance != null)
            {
                ExploreManager.Instance.battlePlayerCtr.fadeStepsLeft = 0;
            }

            // 重新初始化人物
            Player.mainPlayer.SetUpPlayerWithPlayerData(resetPd);
            // 地图随机
            Player.mainPlayer.InitializeMapIndex();
            // 重置聊天记录
            ResetChatRecords();
            // 重置地图事件记录
            ResetMapEventsRecord();
            // 重置小地图记录
            ResetMiniMapEventsRecord();
            // 重置本关地图事件记录
            ResetCurrentMapEventRecord();
            // 保存玩家角色数据
            SaveCompletePlayerData();
        }
        /// <summary>
        /// 更新人物技能点并保存
        /// </summary>
        public void AddOneSkillPointToPlayerDataFile()
        {
            PlayerData playerData = DataHandler.LoadDataToSingleModelWithPath <PlayerData>(CommonData.playerDataFilePath);

            playerData.skillNumLeft++;

            DataHandler.SaveInstanceDataToFile <PlayerData>(playerData, CommonData.playerDataFilePath, true);
        }
        /// <summary>
        /// 更新人物金钱并保存
        /// </summary>
        public void UpdateBuyGoldToPlayerDataFile()
        {
            PlayerData playerData = DataHandler.LoadDataToSingleModelWithPath <PlayerData>(CommonData.playerDataFilePath);

            playerData.totalGold = Player.mainPlayer.totalGold;

            DataHandler.SaveInstanceDataToFile <PlayerData>(playerData, CommonData.playerDataFilePath, true);
        }
Example #5
0
        /// <summary>
        /// 加载指定id的npc数据
        /// </summary>
        /// <returns>The npc.</returns>
        /// <param name="npcId">Npc identifier.</param>
        public HLHNPC LoadNpc(int npcId)
        {
            string npcDataPath = string.Format("{0}/NPC_{1}.json", CommonData.npcsDataDirPath, npcId);

            HLHNPC npc = DataHandler.LoadDataToSingleModelWithPath <HLHNPC> (npcDataPath);

            return(npc);
        }
Example #6
0
        public HLHMapData LoadMapDataOfLevel(int level)
        {
            string mapDataFilePath = string.Format("{0}/MapData/Level_{1}.json", CommonData.persistDataPath, level);

            HLHMapData mapData = DataHandler.LoadDataToSingleModelWithPath <HLHMapData>(mapDataFilePath);

            return(mapData);
        }
Example #7
0
        public static MapData GetMapDataOfLevel(int level)
        {
            string mapDataFilePath = string.Format("{0}/MapData/Level_{1}.json", CommonData.persistDataPath, level);

//			string mapDataFilePath = string.Format ("{0}/Level_{1}.json", CommonData.persistDataPath, level);

//			Debug.Log (mapDataFilePath);

            return(DataHandler.LoadDataToSingleModelWithPath <MapData> (mapDataFilePath));
        }
Example #8
0
        private void SaveGoodsInfoOfTrader()
        {
            string traderDataPath = Path.Combine(CommonData.originDataPath, "NPCs/Trader_TraderMan.json");

            Trader trader = DataHandler.LoadDataToSingleModelWithPath <Trader> (traderDataPath);

            trader.goodsGroupList = allGoodsGroup;

            DataHandler.SaveInstanceDataToFile <Trader> (trader, traderDataPath);
        }
Example #9
0
        private void LoadGameSettings()
        {
            if (mGameSettings != null)
            {
                return;
            }

            mGameSettings = DataHandler.LoadDataToSingleModelWithPath <GameSettings>(CommonData.gameSettingsDataFilePath);

            if (mGameSettings == null)
            {
                mGameSettings = new GameSettings();
            }
        }
        /// <summary>
        /// 从本地加载玩家游戏数据
        /// </summary>
        public PlayerData LoadPlayerData()
        {
            string playerDataPath = Path.Combine(CommonData.persistDataPath, "PlayerData.json");

            if (!File.Exists(playerDataPath))
            {
                playerDataPath = Path.Combine(CommonData.persistDataPath, "OriginalPlayerData.json");
            }

            if (!File.Exists(playerDataPath))
            {
                string error = "未找到玩家信息数据";
                Debug.LogError(error);
                return(null);
            }

            return(DataHandler.LoadDataToSingleModelWithPath <PlayerData> (playerDataPath));
        }
        /// <summary>
        /// 从本地加载玩家游戏数据
        /// </summary>
        public PlayerData LoadPlayerData()
        {
            string playerDataPath = CommonData.playerDataFilePath;

            if (!File.Exists(playerDataPath))
            {
                playerDataPath = CommonData.oriPlayerDataFilePath;
            }

            if (!File.Exists(playerDataPath))
            {
                string error = "未找到玩家信息数据";
                Debug.LogError(error);
                return(null);
            }

            PlayerData pd = DataHandler.LoadDataToSingleModelWithPath <PlayerData> (playerDataPath);

            return(pd);
        }
Example #12
0
        /// <summary>
        /// 没有旧版本时的安装逻辑
        /// </summary>
        private void OnNewInstall()
        {
            GameSettings gameSettings = GameManager.Instance.gameDataCenter.gameSettings;

            string dateString = DateTime.Now.ToShortDateString();

            gameSettings.installDateString = dateString;

            GameManager.Instance.persistDataManager.SaveGameSettings();

            Player.mainPlayer.currentExploreStartDateString = dateString;

            PlayerData playerData = DataHandler.LoadDataToSingleModelWithPath <PlayerData>(CommonData.playerDataFilePath);

            playerData.currentExploreStartDateString = dateString;

            ApplicationInfo.Instance.currentVersion = GameManager.Instance.currentVersion;

            DataHandler.SaveInstanceDataToFile <ApplicationInfo>(ApplicationInfo.Instance, CommonData.applicationInfoFilePath);

            DataHandler.SaveInstanceDataToFile <PlayerData>(playerData, CommonData.playerDataFilePath, true);
        }
Example #13
0
        public void OnGUI()
        {
            Rect windowRect = npcEditor.position;

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, new GUILayoutOption[] {
                GUILayout.Height(windowRect.height),
                GUILayout.Width(windowRect.width)
            });

            EditorGUILayout.LabelField("please input information of npc");

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("npc数据源", labelLayouts);

            rect        = EditorGUILayout.GetControlRect(GUILayout.Width(300));
            npcDataPath = EditorGUI.TextField(rect, npcDataPath);
            //如果鼠标正在拖拽中或拖拽结束时,并且鼠标所在位置在文本输入框内
            if ((UnityEngine.Event.current.type == UnityEngine.EventType.DragUpdated ||
                 UnityEngine.Event.current.type == UnityEngine.EventType.DragExited) &&
                rect.Contains(UnityEngine.Event.current.mousePosition))
            {
                //改变鼠标的外表
                DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
                {
                    npcDataPath = DragAndDrop.paths [0];
                }
            }


            EditorGUILayout.EndHorizontal();

            bool loadNpcData = GUILayout.Button("加载npc数据", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(150)
            });

            if (loadNpcData)
            {
                dialogGroups.Clear();
                chatDialogGroups.Clear();
                taskDialogGroups.Clear();

                dialogGroupFoldoutList.Clear();
                dialogFoldoutList.Clear();
                rewardTypeCountList.Clear();
                taskFoldoutList.Clear();

                string npcDataFileName = Path.GetFileName(npcDataPath);

                npcDataPath = string.Format("{0}/NPCs/{1}", CommonData.originDataPath, npcDataFileName);

                string npcTypeStr = npcDataFileName.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries)[0];


                npc = DataHandler.LoadDataToSingleModelWithPath <MyNpc> (npcDataPath);



                switch (npcTypeStr)
                {
                case "Normal":
                    npcType = NPCType.Normal;
                    break;

                case "Trader":
                    npcType          = NPCType.Trader;
                    goodsIdsInString = TransferGoodsIdsToString(npc);
                    break;
                }

                Debug.Log(npcDataPath);

                for (int i = 0; i < npc.chatDialogGroups.Count; i++)
                {
                    dialogGroups.Add(npc.chatDialogGroups [i]);
                    chatDialogGroups.Add(npc.chatDialogGroups [i]);

                    bool foldout = false;
                    dialogGroupFoldoutList.Add(foldout);

                    List <bool> foldoutList = new List <bool> ();
                    dialogFoldoutList.Add(foldoutList);

                    List <int> rewardTypeCounts = new List <int> ();
                    rewardTypeCountList.Add(rewardTypeCounts);

                    for (int j = 0; j < npc.chatDialogGroups [i].dialogs.Count; j++)
                    {
                        Dialog d             = npc.chatDialogGroups [i].dialogs [j];
                        bool   dialogFoldout = false;
                        foldoutList.Add(dialogFoldout);

                        rewardTypeCounts.Add(d.rewardIds.Length);
                    }
                }

                for (int i = 0; i < npc.tasks.Count; i++)
                {
                    dialogGroups.Add(npc.tasks [i].taskDialogGroup);
                    bool foldout = false;
                    taskFoldoutList.Add(foldout);
                    dialogGroupFoldoutList.Add(dialogGroupFoldout);
                    List <bool> foldoutList = new List <bool> ();
                    dialogFoldoutList.Add(foldoutList);
                    List <int> rewardTypeCounts = new List <int> ();
                    rewardTypeCountList.Add(rewardTypeCounts);

                    for (int j = 0; j < npc.tasks [i].taskDialogGroup.dialogs.Count; j++)
                    {
                        Dialog d             = npc.tasks [i].taskDialogGroup.dialogs [j];
                        bool   dialogFoldout = false;
                        foldoutList.Add(dialogFoldout);

                        rewardTypeCounts.Add(d.rewardIds.Length);
                    }
                }

                for (int i = 0; i < npc.attachedFunctions.Length; i++)
                {
                    if (npc.attachedFunctions [i] == NPCAttachedFunctionType.SkillPromotion)
                    {
                        skillPromotionFunction = true;
                    }
                    if (npc.attachedFunctions [i] == NPCAttachedFunctionType.PropertyPromotion)
                    {
                        propertyPromotionFunction = true;
                    }
                    if (npc.attachedFunctions [i] == NPCAttachedFunctionType.Task)
                    {
                        taskFunction = true;
                    }
                    if (npc.attachedFunctions [i] == NPCAttachedFunctionType.CharactersTrade)
                    {
                        characterTradeFunction = true;
                    }
                }
            }

            CreateNPCBaseInformationGUI();



            EditorGUILayout.BeginHorizontal();
            bool createNewDialogGroup = GUILayout.Button("新建对话组", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(200)
            });

            bool removeLastDialogGroup = GUILayout.Button("删除尾部对话组", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(200)
            });

            EditorGUILayout.EndHorizontal();

            if (createNewDialogGroup)
            {
                DialogGroup chatDialogGroup = new DialogGroup();
                dialogGroups.Add(chatDialogGroup);
                bool foldout = true;
                dialogGroupFoldoutList.Add(foldout);
                List <bool> foldoutList = new List <bool> ();
                dialogFoldoutList.Add(foldoutList);
                List <int> rewardTypeCounts = new List <int> ();
                rewardTypeCountList.Add(rewardTypeCounts);
                ReCalculateDialogGroups();
            }

            if (removeLastDialogGroup && chatDialogGroups.Count > 0)
            {
                DialogGroup dg = chatDialogGroups [chatDialogGroups.Count - 1];

                int index = dialogGroups.FindIndex(delegate(DialogGroup obj) {
                    return(obj == dg);
                });
                dialogGroupFoldoutList.RemoveAt(index);
                dialogFoldoutList.RemoveAt(index);
                rewardTypeCountList.RemoveAt(index);

                chatDialogGroups.Remove(dg);
                dialogGroups.Remove(dg);

                ReCalculateDialogGroups();
            }



            for (int i = 0; i < chatDialogGroups.Count; i++)
            {
                DialogGroup dg = chatDialogGroups [i];

                int index = dialogGroups.FindIndex(delegate(DialogGroup obj) {
                    return(obj == dg);
                });

                List <bool> currentDialogFoldoutList = dialogFoldoutList [index];

                List <int> currentDialogRewardTypeCountList = rewardTypeCountList [index];

                dialogGroupFoldoutList [index] = EditorGUILayout.Foldout(dialogGroupFoldoutList [index], "对话组编辑区");

                if (dialogGroupFoldoutList [index])
                {
                    CreateDialogGroupGUI(dg, currentDialogFoldoutList, currentDialogRewardTypeCountList);
                }
            }


            EditorGUILayout.BeginHorizontal();
            bool createNewTask = GUILayout.Button("新建任务", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(200)
            });

            bool removeLastTask = GUILayout.Button("删除尾部任务", new GUILayoutOption[] {
                GUILayout.Height(20),
                GUILayout.Width(200)
            });

            EditorGUILayout.EndHorizontal();


            if (createNewTask)
            {
                Task task = new Task();
                npc.tasks.Add(task);
                DialogGroup taskDialogGroup = new DialogGroup();
                dialogGroups.Add(taskDialogGroup);
                task.taskDialogGroup = taskDialogGroup;
                bool foldout = true;
                taskFoldoutList.Add(foldout);
                dialogGroupFoldoutList.Add(dialogGroupFoldout);
                List <bool> foldoutList = new List <bool> ();
                dialogFoldoutList.Add(foldoutList);
                List <int> rewardIdsCount = new List <int> ();
                rewardTypeCountList.Add(rewardIdsCount);
                ReCalculateDialogGroups();
            }

            if (removeLastTask && npc.tasks.Count > 0)
            {
                Task task = npc.tasks [npc.tasks.Count - 1];

                npc.tasks.RemoveAt(npc.tasks.Count - 1);

                taskFoldoutList.RemoveAt(taskFoldoutList.Count - 1);



                int index = dialogGroups.FindIndex(delegate(DialogGroup obj) {
                    return(obj == task.taskDialogGroup);
                });

                dialogGroupFoldoutList.RemoveAt(index);
                dialogFoldoutList.RemoveAt(index);
                rewardTypeCountList.RemoveAt(index);

                taskDialogGroups.Remove(task.taskDialogGroup);
                dialogGroups.Remove(task.taskDialogGroup);

                ReCalculateDialogGroups();
            }

            for (int i = 0; i < npc.tasks.Count; i++)
            {
                Task task = npc.tasks [i];
                taskFoldoutList [i] = EditorGUILayout.Foldout(taskFoldoutList [i], "任务编辑区");
                if (taskFoldoutList [i])
                {
                    CreateTaskGUI(task);
                }
            }

//			EditorGUILayout.Separator ();
//			EditorGUILayout.LabelField ("************************结束*************************", new GUILayoutOption[] {
//				GUILayout.Height (20),
//				GUILayout.Width (600)
//			});
            bool saveNpcData = GUILayout.Button("保存NPC数据", new GUILayoutOption[] {
                GUILayout.Width(500),
                GUILayout.Height(20)
            });

            if (saveNpcData)
            {
                SaveNpcData();
            }



            EditorGUILayout.EndScrollView();
        }
        public static void SetUpMapData()
        {
            string originalMapDataDirectory = "/Users/houlianghong/Desktop/MyGameData/Map/MapDatas";

            DirectoryInfo directory = new DirectoryInfo(originalMapDataDirectory);

            FileInfo[] originalMapDatasFiles = directory.GetFiles();

//			string floorTilesInfoPath = "/Users/houlianghong/Desktop/MyGameData/Map/FloorTilesInfo.json";

//			FloorTilesInfo[] floorTilesInfoArray = DataHandler.LoadDataToModelsWithPath<FloorTilesInfo> (floorTilesInfoPath);

//			FloorTilesInfo tilesInfo = null;

            Layer attachedInfoLayer = null;
            Layer attachedItemLayer = null;

            for (int i = 0; i < originalMapDatasFiles.Length; i++)
            {
                FileInfo fi = originalMapDatasFiles [i];

                if (fi.Extension != ".json")
                {
                    continue;
                }

                OriginalMapData oriMapData = DataHandler.LoadDataToSingleModelWithPath <OriginalMapData> (fi.FullName);

                for (int j = 0; j < oriMapData.tilesets.Length; j++)
                {
                    OriginalTileSet ts = oriMapData.tilesets [j];

                    if (ts.source.Contains("Floor"))
                    {
                        oriMapData.floorTileFirstGid = ts.firstgid;
                    }
                    else if (ts.source.Contains("AttachedInfo"))
                    {
                        oriMapData.attachedInfoFirstGid = ts.firstgid;
                    }
                    else if (ts.source.Contains("AttachedItem"))
                    {
                        oriMapData.attachedItemFirstGid = ts.firstgid;
                    }
                    else
                    {
                        Debug.LogError(string.Format("未查询到地图/附加信息的原始贴图数据"));
                    }
                }


                Layer[] newLayers           = new Layer[oriMapData.layers.Length];
                string  backgroundImageName = null;
                string  floorImageName      = null;


                for (int j = 0; j < oriMapData.layers.Length; j++)
                {
                    OriginalLayer layer = oriMapData.layers [j];

                    int firstGid = 0;

                    int row = 0;
                    int col = 0;

                    List <Tile> tileDatas = new List <Tile> ();

                    switch (layer.name)
                    {
                    case "FloorLayer":
                        firstGid       = oriMapData.floorTileFirstGid;
                        floorImageName = layer.properties.floorImageName;

                        for (int k = 0; k < layer.data.Length; k++)
                        {
                            row = oriMapData.height - k / oriMapData.width - 1;
                            col = k % oriMapData.width;
                            int tileIndex = layer.data [k] - firstGid;
                            if (tileIndex >= 0)
                            {
//								bool walkable = tileInfo.walkableInfoArray [tileIndex] == 1;
                                bool walkable = true;
                                Tile tile     = new Tile(new Vector2(col, row), tileIndex, walkable);
                                tileDatas.Add(tile);
                                Debug.LogFormat("mapName:{0},layerName:{1},index:{2},tileInfo:{3}", fi.Name, "floor", k, tile);
                            }
                        }
                        newLayers[j] = new Layer(layer.name, tileDatas);
                        break;

                    case "AttachedInfoLayer":
                        firstGid            = oriMapData.attachedInfoFirstGid;
                        backgroundImageName = layer.properties.backgroundImageName;

                        for (int k = 0; k < layer.data.Length; k++)
                        {
                            row = oriMapData.height - k / oriMapData.width - 1;
                            col = k % oriMapData.width;
                            int tileIndex = layer.data [k] - firstGid;
                            if (tileIndex >= 0)
                            {
                                Tile tile = new Tile(new Vector2(col, row), tileIndex, false);
                                tileDatas.Add(tile);
//								Debug.LogFormat ("mapName:{0},layerName:{1},index:{2},tileInfo:{3}",fi.Name,"attachedInfo",k,tile);
                            }
                        }
                        attachedInfoLayer = new Layer(layer.name, tileDatas);
                        newLayers [j]     = attachedInfoLayer;
                        break;

                    case "AttachedItemLayer":
                        firstGid = oriMapData.attachedItemFirstGid;

                        for (int k = 0; k < layer.data.Length; k++)
                        {
                            row = oriMapData.height - k / oriMapData.width - 1;
                            col = k % oriMapData.width;
                            int tileIndex = layer.data [k] - firstGid;
                            if (tileIndex >= 0)
                            {
                                Tile tile = new Tile(new Vector2(col, row), tileIndex, false);
                                tileDatas.Add(tile);
                                Debug.LogFormat("mapName:{0},layerName:{1},index:{2},tileInfo:{3}", fi.Name, "attachedItem", k, tile);
                            }
                        }
                        attachedItemLayer = new Layer(layer.name, tileDatas);
                        newLayers [j]     = attachedItemLayer;
                        break;

                    default:
                        Debug.LogError(string.Format("地图{0}层名称设置错误或缺失", fi.Name));
                        break;
                    }
                }

                for (int k = 0; k < attachedInfoLayer.tileDatas.Count; k++)
                {
                    Tile attachedInfoTile = attachedInfoLayer.tileDatas [k];

                    if ((AttachedInfoType)(attachedInfoTile.tileIndex) == AttachedInfoType.Buck ||
                        (AttachedInfoType)(attachedInfoTile.tileIndex) == AttachedInfoType.Pot ||
                        (AttachedInfoType)(attachedInfoTile.tileIndex) == AttachedInfoType.TreasureBox)
                    {
                        bool attachedInfoDataExist = false;

                        for (int m = 0; m < attachedItemLayer.tileDatas.Count; m++)
                        {
                            if (attachedItemLayer.tileDatas [m].position == attachedInfoTile.position)
                            {
                                attachedInfoDataExist = true;
                                break;
                            }
                        }

                        if (!attachedInfoDataExist)
                        {
                            Tile tile = new Tile(attachedInfoTile.position, (int)AttachedItemType.Random, true);

                            attachedItemLayer.tileDatas.Add(tile);
//							Debug.LogError (string.Format ("地图{0}上箱子内部没有对应物品---pos:[{1},{2}]",fi.Name, attachedInfoTile.position.x, attachedInfoTile.position.y));
                        }
                    }
                }


                MapData newMapData = new MapData(oriMapData.height, oriMapData.width, oriMapData.tilewidth, oriMapData.tileheight, floorImageName, backgroundImageName, newLayers);

                string newMapDataDirectory = "/Users/houlianghong/Desktop/Unityfolder/TestOnSkills/Assets/StreamingAssets/Data/MapData";

                SaveNewMapData(newMapData, newMapDataDirectory, fi.Name);
            }
        }
Example #15
0
        /// <summary>
        /// 持久化数据
        /// </summary>
        public void PersistData()
        {
            DirectoryInfo persistDi = new DirectoryInfo(CommonData.persistDataPath);

            IEnumerator initDataCoroutine = null;

            CheckDataModel checkData = new CheckDataModel();

            MySQLiteHelper sql = MySQLiteHelper.Instance;

            // 检查数据的完整性
            bool dataComplete = CheckDataComplete();

            // 如果原始玩家数据存在的话
            if (File.Exists(CommonData.playerDataFilePath))
            {
                // 记录原始玩家数据
                checkData.playerData = DataHandler.LoadDataToSingleModelWithPath <PlayerData>(CommonData.playerDataFilePath);
                checkData.playerData.needChooseDifficulty = false;

                if (ApplicationInfo.Instance != null)
                {
                    checkData.versionUpdate = ApplicationInfo.Instance.currentVersion + 0.001f < GameManager.Instance.currentVersion;
                }
                else
                {
                    checkData.versionUpdate = true;
                }
            }

            if (checkData.versionUpdate)
            {
                if (File.Exists(CommonData.dataBaseFilePath))
                {
                    sql.GetConnectionWith(CommonData.dataBaseName);

                    sql.BeginTransaction();

                    checkData.learnedWordsInSimple = GetWordRecordsInDataBase(sql, 0);
                    checkData.learnedWordsInMedium = GetWordRecordsInDataBase(sql, 1);
                    checkData.learnedWordsInMaster = GetWordRecordsInDataBase(sql, 2);

                    sql.EndTransaction();
                    sql.CloseConnection(CommonData.dataBaseName);
                }

                checkData.playerData.isNewPlayer = true;

                if (File.Exists(CommonData.buyRecordFilePath))
                {
                    checkData.buyRecord = BuyRecord.Instance;
                }

                if (File.Exists(CommonData.chatRecordsFilePath))
                {
                    checkData.chatRecords = GameManager.Instance.gameDataCenter.chatRecords;
                }

                if (File.Exists(CommonData.mapEventsRecordFilePath))
                {
                    checkData.mapEventsRecords = GameManager.Instance.gameDataCenter.mapEventsRecords;
                }

                if (File.Exists(CommonData.gameSettingsDataFilePath))
                {
                    checkData.gameSettings = GameManager.Instance.gameDataCenter.gameSettings;
                }

                if (File.Exists(CommonData.miniMapRecordFilePath))
                {
                    checkData.miniMapRecord = GameManager.Instance.gameDataCenter.currentMapMiniMapRecord;
                }
                if (File.Exists(CommonData.currentMapEventsRecordFilePath))
                {
                    checkData.currentMapEventsRecord = GameManager.Instance.gameDataCenter.currentMapEventsRecord;
                }
                if (File.Exists(CommonData.playRecordsFilePath))
                {
                    checkData.playRecords = GameManager.Instance.gameDataCenter.allPlayRecords;
                }
            }



#if UNITY_IOS
            if (!persistDi.Exists || checkData.versionUpdate || !dataComplete)
            {
                bool dataValidate = CheckDataValidate();

                if (!dataValidate)
                {
                    return;
                }

                GameManager.Instance.persistDataManager.BackUpDataWhenUpdataVersion(checkData);

                DataHandler.CopyDirectory(CommonData.originDataPath, CommonData.persistDataPath, true);

                if (!persistDi.Exists)
                {
                    OnNewInstall();
                }

                else if (checkData.versionUpdate || !dataComplete)
                {
                    GameManager.Instance.persistDataManager.versionUpdateWhenLoad = checkData.versionUpdate;

                    OnVersionUpdate(checkData, sql);
                }

                initDataCoroutine = InitData();

                StartCoroutine(initDataCoroutine);

                return;
            }
            else if (alwaysPersistData)
            {
                bool dataValidate = CheckDataValidate();

                if (!dataValidate)
                {
                    return;
                }

                GameManager.Instance.persistDataManager.BackUpDataWhenUpdataVersion(checkData);

                DataHandler.CopyDirectory(CommonData.originDataPath, CommonData.persistDataPath, true);

                if (!persistDi.Exists)
                {
                    OnNewInstall();
                }

                else if (checkData.versionUpdate || !dataComplete)
                {
                    GameManager.Instance.persistDataManager.versionUpdateWhenLoad = checkData.versionUpdate;

                    OnVersionUpdate(checkData, sql);
                }
            }

            initDataCoroutine = InitData();

            StartCoroutine(initDataCoroutine);
#elif UNITY_ANDROID
            if (!persistDi.Exists || checkData.versionUpdate || !dataComplete)
            {
                bool dataValidate = CheckDataValidate();

                if (!dataValidate)
                {
                    return;
                }

                GameManager.Instance.persistDataManager.BackUpDataWhenUpdataVersion(checkData);

                IEnumerator copyDataCoroutine = CopyDataForPersist(delegate {
                    if (!persistDi.Exists)
                    {
                        OnNewInstall();
                    }
                    else if (checkData.versionUpdate || !dataComplete)
                    {
                        GameManager.Instance.persistDataManager.versionUpdateWhenLoad = checkData.versionUpdate;
                        OnVersionUpdate(checkData, sql);
                    }
                });
                StartCoroutine(copyDataCoroutine);
                return;
            }
            else if (alwaysPersistData)
            {
                bool dataValidate = CheckDataValidate();

                if (!dataValidate)
                {
                    return;
                }

                if (DataHandler.DirectoryExist(CommonData.persistDataPath + "/Data"))
                {
                    DataHandler.DeleteDirectory(CommonData.persistDataPath + "/Data");
                }

                GameManager.Instance.persistDataManager.BackUpDataWhenUpdataVersion(checkData);

                IEnumerator copyDataCoroutine = CopyDataForPersist(delegate {
                    if (!persistDi.Exists)
                    {
                        OnNewInstall();
                    }
                    else if (checkData.versionUpdate || !dataComplete)
                    {
                        GameManager.Instance.persistDataManager.versionUpdateWhenLoad = checkData.versionUpdate;
                        OnVersionUpdate(checkData, sql);
                    }
                });
                StartCoroutine(copyDataCoroutine);
            }
            else
            {
                initDataCoroutine = InitData();

                StartCoroutine(initDataCoroutine);
            }
#endif
        }
        public GameSettings LoadGameSettings()
        {
            string settingsPath = string.Format("{0}/{1}", CommonData.persistDataPath, "GameSettings.json");

            return(DataHandler.LoadDataToSingleModelWithPath <GameSettings> (settingsPath));
        }