private static void UpdateAllFile(string filePath) { //TableRead.Instance.Init(); //string csvPath = string.Format("{0}/StreamingAssets/CSVAssets/", Application.dataPath); // Extend.GameUtils.CombinePath(Application.dataPath, "StreamingAssets", "CSV"); //string.Format("{0}/StreamingAssets/CSV/", Application.dataPath); //TableRead.Instance.ReadCustomPath(csvPath); DirectoryInfo dInfo = new DirectoryInfo(filePath); FileInfo[] fileInfoArr = dInfo.GetFiles("*.bytes", SearchOption.TopDirectoryOnly); for (int i = 0; i < fileInfoArr.Length; ++i) { string fullName = fileInfoArr[i].FullName; BehaviorReadWrite readWrite = new BehaviorReadWrite(); BehaviorTreeData treeData = readWrite.ReadJson(fullName); if (null != BehaviorManager.behaviorStandardID) { treeData = BehaviorManager.behaviorStandardID(treeData); } CheckChildID(treeData, treeData.rootNodeId); treeData = UpdateData(treeData); string jsonFilePath = System.IO.Path.GetDirectoryName(filePath) + "/Json/" + System.IO.Path.GetFileName(fullName); bool value = readWrite.WriteJson(treeData, jsonFilePath); if (!value) { Debug.LogError("WriteError:" + jsonFilePath); } } }
public void LoadFile(string fileName) { if (string.IsNullOrEmpty(fileName)) { return; } BehaviorDataController.Instance.ConfigDataDic.Clear(); BehaviorReadWrite readWrite = new BehaviorReadWrite(); BehaviorTreeData behaviorTreeData = ReadFile(fileName, true); if (null == behaviorTreeData) { UnityEngine.Debug.LogError("file is null:" + fileName); return; } BehaviorDataController.Instance.PlayState = BehaviorPlayType.STOP; NodeNotify.SetPlayState((int)BehaviorPlayType.STOP); BehaviorDataController.Instance.SetBehaviorData(behaviorTreeData); BehaviorDataController.Instance.CurrentSelectId = -1; BehaviorDataController.Instance.CurrentOpenSubTree = -1; BehaviorRunTime.Instance.Reset(behaviorTreeData); }
public void Update(string filePath) { DirectoryInfo dInfo = new DirectoryInfo(filePath); FileInfo[] fileInfoArr = dInfo.GetFiles("*.bytes", SearchOption.TopDirectoryOnly); for (int i = 0; i < fileInfoArr.Length; ++i) { string fullName = fileInfoArr[i].FullName; BehaviorReadWrite readWrite = new BehaviorReadWrite(); BehaviorTreeData treeData = readWrite.ReadJson(fullName); treeData = DataNodeIdStandardTool.StandardID(treeData); CheckCircle(treeData, treeData.rootNodeId); treeData = UpdateData(treeData); string fileName = System.IO.Path.GetFileNameWithoutExtension(fullName); fileName = string.Format("{0}.bytes", fileName); string jsonFilePath = CommonUtils.FileUtils.CombinePath(filePath, "Json", fileName); bool value = readWrite.WriteJson(treeData, jsonFilePath); if (!value) { Debug.LogError("WriteError:" + jsonFilePath); } } }
public void SaveFile(string fileName, BehaviorTreeData data) { if (data == null) { UnityEngine.Debug.LogError("rootNode is null"); return; } if (string.IsNullOrEmpty(fileName)) { if (EditorUtility.DisplayDialog("警告", "文件名不能为空", "确定")) { return; } } if (fileName.Length > 30) { if (EditorUtility.DisplayDialog("警告", "文件名过长,不能大于20个字符", "确定")) { return; } } string path = BehaviorDataController.Instance.GetFilePath(fileName); if (File.Exists(path)) { if (!EditorUtility.DisplayDialog("已存在文件", "是否替换新文件", "替换", "取消")) { return; } } // 如果项目总不包含该路径,创建一个 string directory = Path.GetDirectoryName(path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } data.nodeDic.Clear(); data = DataNodeIdStandardTool.StandardID(data); data.fileName = fileName; BehaviorReadWrite readWrite = new BehaviorReadWrite(); readWrite.WriteJson(data, path); }
public BehaviorTreeData ReadFile(string fileName, bool warningWhenExist) { BehaviorTreeData behaviorTreeData = null; if (BehaviorDataController.Instance.ConfigDataDic.TryGetValue(fileName, out behaviorTreeData)) { return(behaviorTreeData); } Queue <string> queue = new Queue <string>(); queue.Enqueue(fileName); while (queue.Count > 0) { string name = queue.Dequeue(); string filePath = BehaviorDataController.Instance.GetFilePath(name); if (warningWhenExist && !File.Exists(filePath)) { string msg = string.Format("文件不存在:{0}", filePath); if (!EditorUtility.DisplayDialog("提示", msg, "yes")) { continue; } } BehaviorReadWrite readWrite = new BehaviorReadWrite(); behaviorTreeData = readWrite.ReadJson(filePath); BehaviorDataController.Instance.ConfigDataDic[name] = behaviorTreeData; foreach (var nodeValue in behaviorTreeData.nodeList) { if (nodeValue.NodeType == (int)NODE_TYPE.SUB_TREE && nodeValue.subTreeType == (int)SUB_TREE_TYPE.CONFIG && !BehaviorDataController.Instance.ConfigDataDic.TryGetValue(nodeValue.subTreeConfig, out behaviorTreeData)) { queue.Enqueue(nodeValue.subTreeConfig); } } } BehaviorDataController.Instance.ConfigDataDic.TryGetValue(fileName, out behaviorTreeData); return(behaviorTreeData); }
private static void UpdateAllFile(string filePath) { DirectoryInfo dInfo = new DirectoryInfo(filePath); FileInfo[] fileInfoArr = dInfo.GetFiles("*.bytes", SearchOption.TopDirectoryOnly); for (int i = 0; i < fileInfoArr.Length; ++i) { string fullName = fileInfoArr[i].FullName; BehaviorReadWrite readWrite = new BehaviorReadWrite(); BehaviorTreeData treeData = readWrite.ReadJson(fullName); treeData = UpdateData(treeData); string jsonFilePath = System.IO.Path.GetDirectoryName(filePath) + "/Json/" + System.IO.Path.GetFileName(fullName); bool value = readWrite.WriteJson(treeData, jsonFilePath); if (!value) { Debug.LogError("WriteError:" + jsonFilePath); } } }
private static void MergeFile(string filePath) { DirectoryInfo direcotryInfo = Directory.CreateDirectory(filePath); FileInfo[] fileInfoArr = direcotryInfo.GetFiles("*.bytes", SearchOption.TopDirectoryOnly); List <PBConfigWriteFile> fileList = new List <PBConfigWriteFile>(); for (int i = 0; i < fileInfoArr.Length; ++i) { string fullName = fileInfoArr[i].FullName; BehaviorReadWrite readWrite = new BehaviorReadWrite(); BehaviorTreeData behaviorTreeData = readWrite.ReadJson(fullName); behaviorTreeData = RemoveInvalidParameter(behaviorTreeData); string content = LitJson.JsonMapper.ToJson(behaviorTreeData); byte[] byteData = System.Text.Encoding.Default.GetBytes(content); string fileName = System.IO.Path.GetFileNameWithoutExtension(fullName); 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 = string.Format("{0}/StreamingAssets/Bina/BehaviorTreeConfig.bytes", Application.dataPath); if (System.IO.File.Exists(mergeFilePath)) { System.IO.File.Delete(mergeFilePath); AssetDatabase.Refresh(); } byte[] byteData = bbw.GetBytes(); FileReadWrite.Write(mergeFilePath, byteData); } AssetDatabase.Refresh(); }