//保存 public void Save() { if (WorkSpaceData == null) { ShowMessage("当前没有工作空间,请新建或者打开工作空间!"); return; } if (NodeClasses == null || TreeData == null) { return; } //节点类移除未定义的枚举字段 NodeClasses.RemoveUnDefineEnumField(); //移除未定义的节点 TreeData.RemoveUnDefineNode(); //修正数据,和模板的保持一致 TreeData.AjustData(); //检验枚举 VerifyInfo verifyEnum = NodeClasses.VerifyEnum(); if (verifyEnum.HasError) { ShowMessage(verifyEnum.Msg); ShowInfo(verifyEnum.Msg); return; } //检验节点类 VerifyInfo verifyNodeClass = NodeClasses.VerifyNodeClass(); if (verifyNodeClass.HasError) { ShowMessage(verifyNodeClass.Msg); ShowInfo(verifyNodeClass.Msg); return; } //校验行为树 VerifyInfo verifyBehaviorTree = TreeData.VerifyBehaviorTree(); if (verifyBehaviorTree.HasError) { ShowMessage(verifyBehaviorTree.Msg); ShowInfo(verifyBehaviorTree.Msg); return; } if (XmlUtility.Save(GetNodeClassPath(), NodeClasses)) { NodeClassesStringContent = XmlUtility.ObjectToString(NodeClasses); } if (XmlUtility.Save(GetBehaviorTreeDataPath(), TreeData)) { BehaviorTreeDataStringContent = XmlUtility.ObjectToString(TreeData); } //序列化成二进制 BehaviorTreeData.TreeData treeData = EditorUtility.CreateTreeData(TreeData); if (treeData != null) { string savePath = GetNodeDataSavePath(); if (File.Exists(savePath)) { File.Delete(savePath); } BehaviorTreeData.Serializer.SerializeToFile(treeData, savePath); } ShowInfo("保存成功 时间:" + DateTime.Now); }
private void enterBTN_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(workSpaceNameTB.Text.Trim())) { MainForm.Instance.ShowMessage("请输入工作区名字", "警告"); return; } if (string.IsNullOrEmpty(workSpaceDirectoryTB.Text.Trim())) { MainForm.Instance.ShowMessage("请选择工作区位置", "警告"); return; } if (!Directory.Exists(workSpaceDirectoryTB.Text.Trim())) { MainForm.Instance.ShowMessage("工作区目录不存在", "警告"); return; } //if (string.IsNullOrEmpty(dataSaveDirectoryTB.Text.Trim())) //{ // MainForm.Instance.ShowMessage("请选择数据保存位置", "警告"); // return; //} if (!string.IsNullOrEmpty(dataSaveDirectoryTB.Text.Trim()) && !Directory.Exists(dataSaveDirectoryTB.Text.Trim())) { MainForm.Instance.ShowMessage("数据保存目录不存在", "警告"); return; } if (MainForm.Instance.WorkSpaceData != null) { MainForm.Instance.WorkSpaceData.WorkSpaceName = workSpaceNameTB.Text.Trim(); MainForm.Instance.WorkSpaceData.Describe = describeTB.Text.Trim(); Settings.Default.WorkSpaceName = workSpaceNameTB.Text.Trim(); Settings.Default.WorkDirectory = workSpaceDirectoryTB.Text.Trim(); Settings.Default.NodeDataSavePath = dataSaveDirectoryTB.Text.Trim(); if (m_OldWorkSpaceDirectory != Settings.Default.WorkDirectory || m_OldWorkSpaceName != Settings.Default.WorkSpaceName) { //移动工作空间文件 string oldWorkSpaceFile = Path.Combine(m_OldWorkSpaceDirectory, m_OldWorkSpaceName + Settings.Default.WorkSpaceSetupSuffix); string newWorkSpaceFile = Path.Combine(Settings.Default.WorkDirectory, Settings.Default.WorkSpaceName + Settings.Default.WorkSpaceSetupSuffix); if (File.Exists(oldWorkSpaceFile)) { File.Move(oldWorkSpaceFile, newWorkSpaceFile); } //移动节点xml文件 string oldXmlDataFile = Path.Combine(m_OldWorkSpaceDirectory, m_OldWorkSpaceName + Settings.Default.BehaviorTreeDataFileSuffix); string newXmlDataFile = MainForm.Instance.GetBehaviorTreeDataPath(); if (File.Exists(oldXmlDataFile)) { File.Move(oldXmlDataFile, newXmlDataFile); } //移动NodeClass文件 string oldNodeClassXmlFile = Path.Combine(m_OldWorkSpaceDirectory, Settings.Default.NodeClassFile); string newNodeClassXmlFile = Path.Combine(Settings.Default.WorkDirectory, Settings.Default.NodeClassFile); if (File.Exists(oldNodeClassXmlFile)) { File.Move(oldNodeClassXmlFile, newNodeClassXmlFile); } } //移动旧二进制数据 if (Settings.Default.NodeDataSavePath != m_OldDataSaveDirectory) { string oldTreeDataFile = Path.Combine(m_OldDataSaveDirectory, m_OldWorkSpaceName + Settings.Default.NodeDataFileSuffix); string newFile = MainForm.Instance.GetNodeDataSavePath(); if (File.Exists(oldTreeDataFile)) { File.Move(oldTreeDataFile, newFile); } } Settings.Default.Save(); XmlUtility.Save <WorkSpaceData>(MainForm.Instance.GetWorkSpacePath(), MainForm.Instance.WorkSpaceData); MainForm.Instance.Exec(OperationType.Refresh); MainForm.Instance.ShowInfo("编辑工作区,时间:" + DateTime.Now); } this.Close(); }
private void enterBTN_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(workSpaceNameTB.Text.Trim())) { MainForm.Instance.ShowMessage("请输入工作区名字", "警告"); return; } if (string.IsNullOrEmpty(workSpaceDirectoryTB.Text.Trim())) { MainForm.Instance.ShowMessage("请选择工作区位置", "警告"); return; } if (!Directory.Exists(workSpaceDirectoryTB.Text.Trim())) { MainForm.Instance.ShowMessage("工作区目录不存在", "警告"); return; } //if (string.IsNullOrEmpty(dataSaveDirectoryTB.Text.Trim())) //{ // MainForm.Instance.ShowMessage("请选择数据保存位置", "警告"); // return; //} if (!string.IsNullOrEmpty(dataSaveDirectoryTB.Text.Trim()) && !Directory.Exists(dataSaveDirectoryTB.Text.Trim())) { MainForm.Instance.ShowMessage("数据保存目录不存在", "警告"); return; } string workSpaceDirector = workSpaceDirectoryTB.Text.Trim(); string[] files = Directory.GetFiles(workSpaceDirector, "*" + Settings.Default.WorkSpaceSetupSuffix); if (files.Length > 0) { string existWorkSpaceName = Path.GetFileName(files[0]); //去掉后缀 existWorkSpaceName = existWorkSpaceName.Replace(Settings.Default.WorkSpaceSetupSuffix, ""); MainForm.Instance.ShowMessage(string.Format("该位置已被{0}使用,请选择别的目录作为新的工作区位置", existWorkSpaceName), "警告"); return; } MainForm.Instance.WorkSpaceData = new WorkSpaceData(); MainForm.Instance.WorkSpaceData.WorkSpaceName = workSpaceNameTB.Text.Trim(); MainForm.Instance.WorkSpaceData.Describe = describeTB.Text.Trim(); Settings.Default.WorkSpaceName = workSpaceNameTB.Text.Trim(); Settings.Default.WorkDirectory = workSpaceDirectoryTB.Text.Trim(); Settings.Default.NodeDataSavePath = dataSaveDirectoryTB.Text.Trim(); Settings.Default.Save(); XmlUtility.Save <WorkSpaceData>(MainForm.Instance.GetWorkSpacePath(), MainForm.Instance.WorkSpaceData); MainForm.Instance.ShowInfo("新建工作区成功,时间:" + DateTime.Now); //初始化节点类信息 MainForm.Instance.NodeTemplate = new NodeTemplate(); MainForm.Instance.NodeTemplate.ResetNodes(); XmlUtility.Save(MainForm.Instance.GetNodeTemplatePath(), MainForm.Instance.NodeTemplate); MainForm.Instance.NodeTemplateStringContent = XmlUtility.ObjectToString(MainForm.Instance.NodeTemplate); //初始化行为树数据 MainForm.Instance.BehaviorTreeData = new TreeDatasDesigner(); XmlUtility.Save(MainForm.Instance.GetBehaviorTreeDataPath(), MainForm.Instance.BehaviorTreeData); MainForm.Instance.BehaviorTreeDataStringContent = XmlUtility.ObjectToString(MainForm.Instance.BehaviorTreeData); MainForm.Instance.CreateTreeViewManager(); MainForm.Instance.Exec(OperationType.Refresh); this.Close(); }
private void enterBTN_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(workSpaceNameTB.Text.Trim())) { MainForm.Instance.ShowMessage("请输入工作区名字", "警告"); return; } if (string.IsNullOrEmpty(workSpaceDirectoryTB.Text.Trim())) { MainForm.Instance.ShowMessage("请选择工作区位置", "警告"); return; } if (!Directory.Exists(workSpaceDirectoryTB.Text.Trim())) { MainForm.Instance.ShowMessage("工作区目录不存在", "警告"); return; } //if (string.IsNullOrEmpty(dataSaveDirectoryTB.Text.Trim())) //{ // MainForm.Instance.ShowMessage("请选择数据保存位置", "警告"); // return; //} if (!string.IsNullOrEmpty(dataSaveDirectoryTB.Text.Trim()) && !Directory.Exists(dataSaveDirectoryTB.Text.Trim())) { MainForm.Instance.ShowMessage("数据保存目录不存在", "警告"); return; } if (MainForm.Instance.WorkSpaceData != null) { MainForm.Instance.WorkSpaceData.WorkSpaceName = workSpaceNameTB.Text.Trim(); MainForm.Instance.WorkSpaceData.Describe = describeTB.Text.Trim(); Settings.Default.WorkSpaceName = workSpaceNameTB.Text.Trim(); Settings.Default.WorkDirectory = workSpaceDirectoryTB.Text.Trim(); Settings.Default.NodeDataSavePath = dataSaveDirectoryTB.Text.Trim(); if (m_OldWorkSpaceDirectory != Settings.Default.WorkDirectory || m_OldWorkSpaceName != Settings.Default.WorkSpaceName) { //移动工作空间文件 string oldWorkSpaceFile = Path.Combine(m_OldWorkSpaceDirectory, m_OldWorkSpaceName + Settings.Default.WorkSpaceSetupSuffix); string newWorkSpaceFile = Path.Combine(Settings.Default.WorkDirectory, Settings.Default.WorkSpaceName + Settings.Default.WorkSpaceSetupSuffix); if (File.Exists(oldWorkSpaceFile)) { if (File.Exists(newWorkSpaceFile)) { File.Delete(newWorkSpaceFile); } File.Move(oldWorkSpaceFile, newWorkSpaceFile); } //移动节点xml文件 string[] xmlFiles = Directory.GetFiles(m_OldWorkSpaceDirectory, $"*{Settings.Default.BehaviorTreeDataFileSuffix}"); for (int i = 0; i < xmlFiles.Length; i++) { string file = xmlFiles[i]; string fileName = Path.GetFileName(file); if (fileName.EndsWith(Settings.Default.BehaviorTreeSuffix, StringComparison.Ordinal) || fileName.EndsWith(Settings.Default.GroupSuffix, StringComparison.Ordinal)) { string oldXmlDataFile = file; string newXmlDataFile = Path.Combine(Settings.Default.WorkDirectory, fileName); if (File.Exists(newXmlDataFile)) { File.Delete(newXmlDataFile); } File.Move(oldXmlDataFile, newXmlDataFile); } } //移动NodeTemplate文件 string oldNodeTemplateXmlFile = Path.Combine(m_OldWorkSpaceDirectory, Settings.Default.NodeTemplateFile); string newNodeTemplateXmlFile = Path.Combine(Settings.Default.WorkDirectory, Settings.Default.NodeTemplateFile); if (File.Exists(oldNodeTemplateXmlFile)) { if (File.Exists(newNodeTemplateXmlFile)) { File.Delete(newNodeTemplateXmlFile); } File.Move(oldNodeTemplateXmlFile, newNodeTemplateXmlFile); } //移动全局变量文件 string oldGlobalVariableFile = Path.Combine(m_OldWorkSpaceDirectory, Settings.Default.GlobalVariableFile); string newGlobalVariableFile = Path.Combine(Settings.Default.WorkDirectory, Settings.Default.GlobalVariableFile); if (File.Exists(oldGlobalVariableFile)) { if (File.Exists(newGlobalVariableFile)) { File.Delete(newGlobalVariableFile); } File.Move(oldGlobalVariableFile, newGlobalVariableFile); } } //移动旧二进制数据 if (Settings.Default.NodeDataSavePath != m_OldDataSaveDirectory) { string oldTreeDataFile = Path.Combine(m_OldDataSaveDirectory, m_OldWorkSpaceName + Settings.Default.NodeDataFileSuffix); string newFile = MainForm.Instance.GetNodeDataSavePath(); if (File.Exists(oldTreeDataFile)) { if (File.Exists(newFile)) { File.Delete(newFile); } File.Move(oldTreeDataFile, newFile); } } Settings.Default.Save(); XmlUtility.Save <WorkSpaceData>(MainForm.Instance.GetWorkSpacePath(), MainForm.Instance.WorkSpaceData); MainForm.Instance.Exec(OperationType.Refresh); MainForm.Instance.ShowInfo("编辑工作区,时间:" + DateTime.Now); } this.Close(); }