public static bool CreateNewTree(string exName, out string path) { path = EditorUtility.SaveFilePanel("创建行为树", EditorTreeConfigHelper.Instance.Config.ServersPath, "名字", exName); if (string.IsNullOrEmpty(path)) { return(false); } string name = BehaviourTreeJsonHelper.GetNameFromPath(path); NodeProto proto = new NodeProto() { Desc = name, Id = 10001 }; if (exName == "txt") { proto.Name = "ServerTreeNodeTest"; using (StreamWriter wr = new StreamWriter(path)) { wr.Write(MongoHelper.ToJson(proto)); } } else { proto.Name = typeof(SpellHitRoot).Name; GameObject goes = CreatePrefabWithNodeProto(proto); PrefabUtility.CreatePrefab(path, goes); UnityEngine.Object.DestroyImmediate(goes); } return(true); }
private void Save() { foreach (var pair in _datas) { string path = _paramsPath[pair.Value]; bool isClient = !path.Contains(".txt"); RunTimeNodeData data = pair.Value; GameObject go; GameObject repGo = null; bool saveType = data.Save(out go); if (!saveType) { continue; } GameObject src = new GameObject(pair.Value.Root.NodeDesc); if (isClient) { repGo = AssetDatabase.LoadAssetAtPath <GameObject>(path); src = PrefabUtility.ConnectGameObjectToPrefab(src, repGo); UnityEngine.Object.DestroyImmediate(src.transform.GetChild(0).gameObject, true); } go.transform.SetParent(src.transform); var tree = src.GetComponent <BehaviorTreeConfig>() ?? src.AddComponent <BehaviorTreeConfig>(); tree.RootNodeConfig = go.GetComponent <BehaviorNodeConfig>(); if (path.Contains(".txt")) { BehaviourTreeJsonHelper.WriteToJson(tree, path); } else { //src = PrefabUtility.ConnectGameObjectToPrefab(src, repGo); PrefabUtility.ReplacePrefab(src, repGo, ReplacePrefabOptions.ConnectToPrefab); EditorUtility.SetDirty(repGo); //AssetDatabase.SaveAssets(); } UnityEngine.Object.DestroyImmediate(src); BehaviourTreeDebugPanel.Log(_curOpenningCtrl, "保存成功"); } }
private void SaveToJson() { foreach (var pair in _datas) { string path = _paramsPath[pair.Value]; RunTimeNodeData data = pair.Value; GameObject go; if (!data.Save(out go)) { continue; } GameObject src = new GameObject(pair.Value.Root.NodeDesc); go.transform.SetParent(src.transform); var tree = src.AddComponent <BehaviorTreeConfig>(); tree.RootNodeConfig = go.GetComponent <BehaviorNodeConfig>(); BehaviourTreeJsonHelper.WriteToJson(tree, path); UnityEngine.Object.DestroyImmediate(src); } }