static void CreateNewBehaviorTree(MenuCommand menuCommand) { string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (path == "") { path = "Assets"; } else if (Path.GetExtension(path) != "") { path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); } string fullPath = AssetDatabase.GenerateUniqueAssetPath(path + "/New Behavior Tree.asset"); BehaviorTree bt = ScriptableObject.CreateInstance <BehaviorTree>(); Root root = ScriptableObject.CreateInstance <Root>(); root.editorPosition = new Vector2(0, 0); bt.SetRoot(root); BTAsset btAsset = ScriptableObject.CreateInstance <BTAsset>(); btAsset.Serialize(bt); AssetDatabase.CreateAsset(btAsset, fullPath); AssetDatabase.Refresh(); EditorUtility.FocusProjectWindow(); Selection.activeObject = btAsset; }
static void CreateNewBehaviorTree(MenuCommand menuCommand) { // string path = AssetDatabase.GetAssetPath(Selection.activeObject); // if (path == "") // path = "Assets"; // else if (Path.GetExtension(path) != "") // path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); string basePath = PStr.b().a("Assets/").a(CLPathCfg.self.basePath).a("/xRes/carbonEvent/").e(); string fullPath = EditorUtility.SaveFilePanel("Save Carbon Event", basePath, "New Behavior Tree", "asset"); if (string.IsNullOrEmpty(fullPath)) { return; } // fullPath = AssetDatabase.GenerateUniqueAssetPath (fullPath); fullPath = fullPath.Substring(fullPath.IndexOf("/Assets/") + 1); BehaviorTree bt = ScriptableObject.CreateInstance <BehaviorTree> (); Root root = ScriptableObject.CreateInstance <Root> (); root.editorPosition = new Vector2(0, 0); bt.SetRoot(root); BTAsset btAsset = ScriptableObject.CreateInstance <BTAsset> (); btAsset.Serialize(bt); AssetDatabase.CreateAsset(btAsset, fullPath); AssetDatabase.Refresh(); EditorUtility.FocusProjectWindow(); Selection.activeObject = btAsset; }
public void Dirty() { if (editorWindow != null) { editorWindow.Repaint(); } btAsset.Serialize(behaviorTree); EditorUtility.SetDirty(btAsset); }