public static void DeleteNode(Node node, BehaviorTrees bt)
        {
            if (node.parentNode != null)
            {
                node.parentNode.childNodes = ArrayUtility.Remove <Node>(node.parentNode.childNodes, node);
            }

            foreach (Node child in node.childNodes)
            {
                if (child != null)
                {
                    child.parentNode = null;
                }
            }

            if (node.decorators.Length > 0)
            {
                foreach (Decorator decorator in node.decorators)
                {
                    BehaviorTreesEditorUtility.DeleteDecorator(decorator);
                }
            }
            if (node is Composite && (node as Composite).services.Length > 0)
            {
                foreach (Service service in (node as Composite).services)
                {
                    BehaviorTreesEditorUtility.DeleteService(service);
                }
            }
            bt.nodes = ArrayUtility.Remove <Node>(bt.nodes, node);
            BehaviorTreesEditorUtility.DestroyImmediate(node);
        }
示例#2
0
        private void ServiceContextMenu()
        {
            if (_currentEvent.type != EventType.MouseDown || _currentEvent.button != 1 || _currentEvent.clickCount != 1)
            {
                return;
            }

            Service service = MouseOverService();

            if (service == null)
            {
                return;
            }

            int currentIndex = 0;

            for (int i = 0; i < service.parent.services.Length; i++)
            {
                if (service.parent.services[i] == service)
                {
                    break;
                }
                currentIndex++;
            }
            GenericMenu menu = new GenericMenu();

            if (currentIndex > 0)
            {
                menu.AddItem(new GUIContent("Move Up"), false, delegate()
                {
                    service.parent.services = ArrayUtility.MoveItem <Service>(service.parent.services, currentIndex, currentIndex - 1);
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Move Up"));
            }

            if (currentIndex < service.parent.services.Length - 1)
            {
                menu.AddItem(new GUIContent("Move Down"), false, delegate()
                {
                    service.parent.services = ArrayUtility.MoveItem <Service>(service.parent.services, currentIndex, currentIndex + 1);
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Move Down"));
            }

            menu.AddItem(new GUIContent("Delete Service"), false, delegate()
            {
                if (_serviceSelection.Contains(service))
                {
                    _serviceSelection.Clear();
                }
                BehaviorTreesEditorUtility.DeleteService(service);
                UpdateUnitySelection();
                EditorUtility.SetDirty(BehaviorTreesEditor.active);
            });
            menu.ShowAsContext();
            UnityEngine.Event.current.Use();
        }