public static void UpdateAllFile(string filePath) { DirectoryInfo dInfo = new DirectoryInfo(filePath); FileInfo[] fileInfoArr = dInfo.GetFiles("*.txt", SearchOption.TopDirectoryOnly); for (int i = 0; i < fileInfoArr.Length; ++i) { string fullName = fileInfoArr[i].FullName; HSMReadWrite readWrite = new HSMReadWrite(); SkillHsmConfigHSMTreeData skillHsmData = readWrite.ReadJson(fullName); string fileName = System.IO.Path.GetFileNameWithoutExtension(fullName); skillHsmData.FileName = fileName; HSMManager.Instance.CheckData(skillHsmData); skillHsmData = UpdateData(skillHsmData); string jsonFilePath = Extend.GameUtils.CombinePath(filePath, "Json", System.IO.Path.GetFileName(fullName));// System.IO.Path.GetDirectoryName(filePath) + "/Json/" + System.IO.Path.GetFileName(fullName); jsonFilePath = System.IO.Path.ChangeExtension(jsonFilePath, "txt"); bool value = readWrite.WriteJson(skillHsmData, jsonFilePath); if (!value) { Debug.LogError("WriteError:" + jsonFilePath); } } }
private void SaveFile(string fileName) { if (_HSMTreeData == null) { Debug.LogError("rootNode is null"); return; } string path = GetFilePath(fileName); if (File.Exists(path)) { if (!EditorUtility.DisplayDialog("已存在文件", "是否替换新文件", "替换", "取消")) { return; } } // 如果项目总不包含该路径,创建一个 string directory = Path.GetDirectoryName(path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string name = System.IO.Path.GetFileNameWithoutExtension(path); CheckData(_HSMTreeData); HSMReadWrite readWrite = new HSMReadWrite(); _HSMTreeData.FileName = System.IO.Path.GetFileNameWithoutExtension(path); readWrite.WriteJson(_HSMTreeData, path); }
private void LoadFile(string fileName) { string path = GetFilePath(fileName); if (!File.Exists(path)) { if (!EditorUtility.DisplayDialog("提示", "文件不存在", "yes")) { } return; } _playState = HSMPlayType.STOP; NodeNotify.SetPlayState((int)_playState); HSMReadWrite readWrite = new HSMReadWrite(); SkillHsmConfigHSMTreeData HSMTreeData = readWrite.ReadJson(path); if (null == HSMTreeData) { Debug.LogError("file is null:" + fileName); return; } _fileName = fileName; _HSMTreeData = HSMTreeData; _currentOpenSubMachineId = -1; HSMRunTime.Instance.Reset(HSMTreeData); }
public SkillHsmConfigHSMTreeData GetSkillHsmData(string handleFile) { DirectoryInfo dInfo = new DirectoryInfo(FilePath); FileInfo[] fileInfoArr = dInfo.GetFiles("*.txt", SearchOption.TopDirectoryOnly); for (int i = 0; i < fileInfoArr.Length; ++i) { string fullName = fileInfoArr[i].FullName; HSMReadWrite readWrite = new HSMReadWrite(); SkillHsmConfigHSMTreeData skillHsmData = readWrite.ReadJson(fullName); if (Path.GetFileNameWithoutExtension(fullName).CompareTo(handleFile) == 0) { return(skillHsmData); } } return(null); }
public static void BeatchMergeAllFile() { string filePath = HSMManager.Instance.FilePath; DirectoryInfo dInfo = new DirectoryInfo(filePath); FileInfo[] fileInfoArr = dInfo.GetFiles("*.txt", SearchOption.TopDirectoryOnly); List <PBConfigWriteFile> fileList = new List <PBConfigWriteFile>(); for (int i = 0; i < fileInfoArr.Length; ++i) { string fullName = fileInfoArr[i].FullName; HSMReadWrite readWrite = new HSMReadWrite(); SkillHsmConfigHSMTreeData skillHsmData = readWrite.ReadJson(fullName); skillHsmData = FormatData(skillHsmData); HSMManager.Instance.CheckData(skillHsmData); string fileName = System.IO.Path.GetFileNameWithoutExtension(fullName); //skillHsmData.FileName = fileName; byte[] byteData = ProtoDataUtils.ObjectToBytes <SkillHsmConfigHSMTreeData>(skillHsmData); if (byteData.Length <= 0) { Debug.LogError("无效得配置文件"); return; } PBConfigWriteFile skillConfigWriteFile = new PBConfigWriteFile(); skillConfigWriteFile.filePath = filePath; skillConfigWriteFile.byteData = byteData; fileList.Add(skillConfigWriteFile); Debug.Log("end mergeFile:" + filePath); } ByteBufferWrite bbw = new ByteBufferWrite(); bbw.WriteInt32(fileList.Count); int start = 4 + fileList.Count * (4 + 4); for (int i = 0; i < fileList.Count; ++i) { PBConfigWriteFile skillConfigWriteFile = fileList[i]; bbw.WriteInt32(start); bbw.WriteInt32(skillConfigWriteFile.byteData.Length); start += skillConfigWriteFile.byteData.Length; } for (int i = 0; i < fileList.Count; ++i) { PBConfigWriteFile skillHsmWriteFile = fileList[i]; bbw.WriteBytes(skillHsmWriteFile.byteData, skillHsmWriteFile.byteData.Length); } { string mergeFilePath = Extend.GameUtils.CombinePath(Application.dataPath, "StreamingAssets", "Bina", "SkillHsmConfig.bytes"); //string.Format("{0}/StreamingAssets/Bina/SkillHsmConfig.bytes", Application.dataPath); // string.Format("{0}/MergeFile/SkillConfig.txt", path); if (System.IO.File.Exists(mergeFilePath)) { System.IO.File.Delete(mergeFilePath); AssetDatabase.Refresh(); } byte[] byteData = bbw.GetBytes(); FileReadWrite.Write(mergeFilePath, byteData); } }