public void SaveAsset()
        {
            if (tmpAsset == null)
            {
                return;
            }
            List <BTNode> children = new List <BTNode>();
            var           path     = tree == null ? null : AssetDatabase.GetAssetPath(tree);

            tmpAsset.EditorResort();
            if (string.IsNullOrEmpty(path))
            {
                path = EditorUtility.SaveFilePanelInProject("Save Behaviour Tree", AssetName, "asset", "Save behaviour asset.");
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }
                if (File.Exists(path))
                {
                    AssetDatabase.DeleteAsset(path);
                }
                tree = tmpAsset.Clone();
                var name = Path.GetFileName(path);
                if (name.EndsWith(".asset"))
                {
                    name = name.Substring(0, name.Length - 6);
                }
                tree.name = name;
                AssetDatabase.CreateAsset(tree, path);
                tree.GetAllNodes(children);
                foreach (var t in children)
                {
                    AssetDatabase.AddObjectToAsset(t.Asset, path);
                }
                AssetDatabase.ImportAsset(path);
            }
            else
            {
                tmpAsset.EditorMergeTo(path, tree);
                tree.GetAllNodes(children);
                foreach (var t in children)
                {
                    AssetDatabase.AddObjectToAsset(t.Asset, path);
                }
                AssetDatabase.ImportAsset(path);
            }
            //AssetDatabase.SaveAssets();
        }
예제 #2
0
 void GetServices()
 {
     mAsset = editor.TargetTree;
     mServiceNodes.Clear();
     mServiceNames.Clear();
     mServiceModules.Clear();
     if (mAsset != null)
     {
         mAsset.GetAllNodes(mServiceNodes, (x) => x.isService);
     }
     for (int i = 0; i < mServiceNodes.Count; i++)
     {
         var mod = AIModules.Get(mServiceNodes[i]);
         mServiceModules.Add(mod);
         mServiceNames.Add(GetServiceName(mServiceNodes[i], mod));
     }
 }