private void SelectBehaviorBrain() { GUIContent content = new GUIContent(BehaviorTreesEditor.active != null ? BehaviorTreesEditor.active.name : "[None Selected]"); float width = EditorStyles.toolbarDropDown.CalcSize(content).x; width = Mathf.Clamp(width, 100f, width); if (GUILayout.Button(content, EditorStyles.toolbarDropDown, GUILayout.Width(width))) { GenericMenu menu = new GenericMenu(); if (BehaviorTreesEditor.active != null) { SelectBehaviorBrainMenu(BehaviorTreesEditor.active, ref menu); } menu.AddItem(new GUIContent("[Create New]"), false, delegate() { BehaviorTrees bt = AssetCreator.CreateAsset <BehaviorTrees>(true); if (bt != null) { bt.Name = bt.name; Root root = BehaviorTreesEditorUtility.AddNode <Root>(BehaviorTreesEditor.center, bt); bt.rootNode = root; root.Name = "Root"; AssetCreator.SaveAIAsset(); BehaviorTreesEditor.SelectBehaviorTrees(bt); } }); menu.ShowAsContext(); } }
public static void CreateBehaviorTrees() { // This code is borrowed from ICode(https://www.assetstore.unity3d.com/en/#!/content/13761) BehaviorTrees bt = AssetCreator.CreateAsset <BehaviorTrees>(false); if (bt != null) { bt.Name = bt.name; Root root = BehaviorTreesEditorUtility.AddNode <Root>(BehaviorTreesEditor.center, bt); bt.rootNode = root; root.Name = "Root"; //AssetCreator.SaveAIAsset(); SaveAIAsset(); } }
protected override void CanvasContextMenu() { if (_currentEvent.type != EventType.MouseDown || _currentEvent.button != 1 || _currentEvent.clickCount != 1 || BehaviorTreesEditor.active == null) { return; } GenericMenu canvasMenu = new GenericMenu(); // Composite canvasMenu.AddItem(new GUIContent("Create Composite/Selector"), false, delegate() { BehaviorTreesEditorUtility.AddNode <Selector>(_mousePosition, BehaviorTreesEditor.active); }); canvasMenu.AddItem(new GUIContent("Create Composite/Sequence"), false, delegate() { BehaviorTreesEditorUtility.AddNode <Sequence>(_mousePosition, BehaviorTreesEditor.active); }); // Task canvasMenu.AddItem(new GUIContent("Create Task/Wait"), false, delegate() { BehaviorTreesEditorUtility.AddNode <Wait>(_mousePosition, BehaviorTreesEditor.active); }); canvasMenu.AddSeparator("Create Task/"); canvasMenu.AddItem(new GUIContent("Create Task/Task"), false, delegate() { BehaviorTreesEditorUtility.AddNode <Task>(_mousePosition, BehaviorTreesEditor.active); }); canvasMenu.AddSeparator("Empty/"); canvasMenu.AddItem(new GUIContent("Empty/Task"), false, delegate() { BehaviorTreesEditorUtility.EmptyNode(_mousePosition, BehaviorTreesEditor.active); }); canvasMenu.AddSeparator("Save/"); canvasMenu.AddItem(new GUIContent("Save/Save"), false, delegate() { AssetCreator.SaveAIAsset(); }); canvasMenu.AddSeparator("Refresh/"); canvasMenu.AddItem(new GUIContent("Refresh/Refresh"), false, delegate() { AssetCreator.Refresh(); }); canvasMenu.ShowAsContext(); }
public static T AddNode <T>(Vector2 position, BehaviorTrees bt) { if (bt == null) { Debug.LogWarning("Can't add a node to the behavior trees, because the behavior trees are null."); return(default(T)); } Node node = ScriptableObject.CreateInstance(typeof(T)) as Node; node.hideFlags = HideFlags.HideInHierarchy; node.Name = BehaviorTreesEditorUtility.GenerateName <T>(); node.comment = node.Name; node.bt = bt; bt.nodes = ArrayUtility.Add <Node>(bt.nodes, node); node.position = new Rect(position.x, position.y, BehaviorTreesEditorStyles.NodeNormalWidth, BehaviorTreesEditorStyles.NodeNormalHeight); if (EditorUtility.IsPersistent(bt)) { AssetDatabase.AddObjectToAsset(node, bt); } if (node is BehaviorTrees) { node.position.width = 150f; node.position.height = 45f; Root root = BehaviorTreesEditorUtility.AddNode <Root>(BehaviorTreesEditor.center, node as BehaviorTrees); root.Name = "Root"; } else if (node is Wait) { Wait wait = node as Wait; wait.tick = 0.1f; wait.comment = "Wait: 0.1s"; } AssetCreator.SaveAIAsset(); return((T)(object)node); }