public static void DeleteNode(Node node, BehaviorTree bt) { if (node.parentNode != null) { node.parentNode.childNodes = ArrayUtility.Remove <Node>(node.parentNode.childNodes, node); } foreach (Node child in node.childNodes) { child.parentNode = null; } if (node.decorators.Length > 0) { foreach (Decorator decorator in node.decorators) { BehaviorTreeEditorUtility.DeleteDecorator(decorator); } } if (node is Composite && (node as Composite).services.Length > 0) { foreach (Service service in (node as Composite).services) { BehaviorTreeEditorUtility.DeleteService(service); } } bt.nodes = ArrayUtility.Remove <Node>(bt.nodes, node); BehaviorTreeEditorUtility.DestroyImmediate(node); }
private void DecoratorContextMenu() { if (_currentEvent.type != EventType.MouseDown || _currentEvent.button != 1 || _currentEvent.clickCount != 1) { return; } Decorator decorator = MouseOverDecorator(); if (decorator == null) { return; } int currentIndex = 0; for (int i = 0; i < decorator.parent.decorators.Length; i++) { if (decorator.parent.decorators[i] == decorator) { break; } currentIndex++; } GenericMenu menu = new GenericMenu(); if (currentIndex > 0) { menu.AddItem(new GUIContent("Move Up"), false, delegate() { decorator.parent.decorators = ArrayUtility.MoveItem <Decorator>(decorator.parent.decorators, currentIndex, currentIndex - 1); }); } else { menu.AddDisabledItem(new GUIContent("Move Up")); } if (currentIndex < decorator.parent.decorators.Length - 1) { menu.AddItem(new GUIContent("Move Down"), false, delegate() { decorator.parent.decorators = ArrayUtility.MoveItem <Decorator>(decorator.parent.decorators, currentIndex, currentIndex + 1); }); } else { menu.AddDisabledItem(new GUIContent("Move Down")); } menu.AddItem(new GUIContent("Delete Decorator"), false, delegate() { if (_decoratorSelection.Contains(decorator)) { _decoratorSelection.Clear(); } BehaviorTreeEditorUtility.DeleteDecorator(decorator); UpdateUnitySelection(); EditorUtility.SetDirty(BehaviorTreeEditor.active); }); menu.ShowAsContext(); Event.current.Use(); }