Exemplo n.º 1
0
        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);
        }
Exemplo n.º 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();
                }
                BehaviorTreeEditorUtility.DeleteService(service);
                UpdateUnitySelection();
                EditorUtility.SetDirty(BehaviorTreeEditor.active);
            });
            menu.ShowAsContext();
            Event.current.Use();
        }