Example #1
0
        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, "保存成功");
            }
        }
Example #2
0
        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);
            }
        }