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(); }
public void Reset() { if (runner != null && tree == null) { tree = runner.SourceAsset; } if (tree != null) { runtimeBinder = runner == null ? null : runner.GetBinder(tree); if (tmpAsset == null) { tmpAsset = tree.Clone(); } else { tree.EditorMergeTo(null, tmpAsset); } if (updateTreeAsset != null) { updateTreeAsset(); } } }