private void CreateStandAloneNode(NodeType nodeType)
        {
            switch (nodeType)
            {
            case NodeType.Leaf:
            case NodeType.Sequence:
            case NodeType.Selector:
            case NodeType.Inverter:
                NodeEditorObject newNode
                    = new NodeEditorObject(nodeType, ++lastNodeIndex)
                    {
                    description = nodeType + " type node. Add description of desired behaviour",
                    displayName = nodeType.ToString(),
                    windowRect  = new Rect(
                        savedMousePos + EditorWindow.GetWindow <OhBehaveEditorWindow>().zoomer.GetContentOffset(),
                        OhBehaveEditorWindow.SequenceNodeStyle.size)
                    };

                AddNewNode(newNode, lastNodeIndex);

                break;

            default:
                Debug.LogWarning("TODO: CreateChildNode of type " + nodeType);
                break;
            }
        }
        private void CreateParentNode(NodeEditorObject childNode, NodeType nodeType, bool createAtMousePosition)
        {
            Rect childWindowRect = childNode.GetWindow().GetRectNoOffset();

            NodeEditorObject.DisconnectNodes(childNode.Parent, childNode);
            save = true;
            switch (nodeType)
            {
            case NodeType.Sequence:
            case NodeType.Selector:
            case NodeType.Inverter:
                NodeEditorObject newNode
                    = new NodeEditorObject(nodeType, ++lastNodeIndex)
                    {
                    description = nodeType + " type node. Add description of desired behaviour",
                    displayName = nodeType.ToString(),
                    windowRect  = new Rect(createAtMousePosition ?
                                           savedMousePos + EditorWindow.GetWindow <OhBehaveEditorWindow>().zoomer.GetContentOffset() :
                                           new Vector2(childWindowRect.x,
                                                       childWindowRect.y - childWindowRect.height - DefaultTreeRowHeight),
                                           OhBehaveEditorWindow.SequenceNodeStyle.size)
                    };
                AddNewNode(newNode, lastNodeIndex);

                NodeEditorObject.ConnectNodes(newNode, childNode);
                break;

            case NodeType.Leaf:
                throw new Exception("A leaf may not be a parent");

            default:
                Debug.LogWarning("TODO: CreateParentNode of type " + nodeType);
                break;
            }
        }
        private JsonNodeData AddNodeToTreeWithChildren(
            NodeEditorObject node, int parentIndex, ref List <JsonNodeData> tree)
        {
            JsonNodeData nodeData = new JsonNodeData
            {
                index          = node.index,
                nodeType       = node.nodeType,
                isRandom       = node.isRandom,
                methodInfoName = node.actionName,
            };

            nodeData.parentIndex = parentIndex;

            tree.Add(nodeData);

            if (!node.HasChildren())
            {
                return(nodeData);
            }

            List <JsonNodeData> childrenData = new List <JsonNodeData>();

            foreach (var nodeIndex in node.GetChildren())
            {
                NodeEditorObject childNode = GetNodeObjectByIndex(nodeIndex);
                childrenData.Add(AddNodeToTreeWithChildren(childNode, nodeData.index, ref tree));
            }

            nodeData.childrenIndices = node.GetChildren().ToArray();
            return(nodeData);
        }
Esempio n. 4
0
        public NodeWindow(NodeEditorObject nodeObj)
        {
            var ohBehave = EditorWindow.GetWindow <OhBehaveEditorWindow>();

            treeBlueprint = ohBehave.treeBlueprint;
            nodeObject    = nodeObj;
            nodeName      = nodeObj.displayName;

            switch (nodeObj.nodeType)
            {
            case NodeType.Leaf:
                nodeStyle  = OhBehaveEditorWindow.LeafNodeStyle;
                bgColor    = NodeStyle.LeafColor;
                labelStyle = NodeStyle.LeafLabelStyle;
                break;

            case NodeType.Selector:
                nodeStyle  = OhBehaveEditorWindow.SelectorNodeStyle;
                bgColor    = NodeStyle.SelectorColor;
                labelStyle = NodeStyle.SelectorLabelStyle;
                outPoint   = new ConnectionPoint(this, ConnectionPointType.Out, ConnectionControls.OnClickOutPoint);
                break;

            case NodeType.Sequence:
                nodeStyle  = OhBehaveEditorWindow.SequenceNodeStyle;
                bgColor    = NodeStyle.SequenceColor;
                labelStyle = NodeStyle.SequencerLabelStyle;
                outPoint   = new ConnectionPoint(this, ConnectionPointType.Out, ConnectionControls.OnClickOutPoint);
                break;

            case NodeType.Inverter:
                nodeStyle  = OhBehaveEditorWindow.InverterNodeStyle;
                bgColor    = NodeStyle.InverterColor;
                labelStyle = NodeStyle.InverterLabelStyle;
                outPoint   = new ConnectionPoint(this, ConnectionPointType.Out, ConnectionControls.OnClickOutPoint);
                break;
            }

            currentStyle = nodeStyle.defaultStyle;

            if (nodeObject.index != OhBehaveTreeBlueprint.ROOT_INDEX)
            {
                inPoint = new ConnectionPoint(this, ConnectionPointType.In, ConnectionControls.OnClickInPoint);
            }

            NodeEditorObject prntObj = nodeObject.Parent;

            if (prntObj != null)
            {
                parent = (IParentNodeWindow)prntObj.GetWindow();
                if (parent == null)
                {
                    refreshConnection = true;
                }
            }
            else
            {
                bgColor = NodeStyle.RootColor;
            }
        }
 public static void DisconnectNodes(NodeEditorObject parent, NodeEditorObject child)
 {
     child.RemoveParent();
     if (parent != null)
     {
         parent.RemoveChild(child.index);
     }
 }
        public void SelectNode(NodeEditorObject nodeObject)
        {
            if (IsNodeSelected() && selectedNode != nodeObject)
            {
                selectedNode.GetWindow().Deselect();
            }

            selectedNode = nodeObject;
        }
 public void DeselectNode()
 {
     if (!IsNodeSelected())
     {
         return;
     }
     selectedNode.GetWindow().Deselect();
     selectedNode = null;
 }
 private void RemoveParent()
 {
     if (parent != null)
     {
         //parent.RemoveChild(index);
         window.ParentRemoved();
         parent      = null;
         parentIndex = OhBehaveTreeBlueprint.NO_PARENT_INDEX;
     }
 }
        private void CompleteConnection()
        {
            NodeEditorObject nodeParent, nodeChild;

            if (startConnection.type == ConnectionPointType.Out)
            {
                nodeParent = startConnection.nodeWindow.nodeObject;
                nodeChild  = endConnection.nodeWindow.nodeObject;
            }
            else
            {
                nodeParent = endConnection.nodeWindow.nodeObject;
                nodeChild  = startConnection.nodeWindow.nodeObject;
            }

            // check for loop
            NodeEditorObject check = nodeParent;

            while (check != null && check.index != ROOT_INDEX)
            {
                check = check.Parent;
                if (check == nodeChild)
                {
                    Debug.LogWarning("No loop for you!");
                    startConnection.isCreatingNewConnection = false;
                    endConnection   = null;
                    startConnection = null;
                    return;
                }
            }

            if (nodeParent.nodeType == NodeType.Inverter && nodeParent.HasChildren())
            {
                // orphan the olde child
                var oldChild = GetNodeObjectByIndex(nodeParent.GetChildren()[0]);
                NodeEditorObject.DisconnectNodes(nodeParent, oldChild);
            }

            var oldParent = GetNodeObjectByIndex(nodeChild.parentIndex);

            if (oldParent != null)
            {
                // remove from old parent
                NodeEditorObject.DisconnectNodes(oldParent, nodeChild);
            }

            // ok, let's do this
            NodeEditorObject.ConnectNodes(nodeParent, nodeChild);

            startConnection.isCreatingNewConnection = false;
            endConnection   = null;
            startConnection = null;
            save            = true;
        }
        public void CreateParentContextMenu(NodeEditorObject childNode, bool createAtMousePosition = false)
        {
            var genericMenu = new GenericMenu();

            genericMenu.AddItem(new GUIContent("Add Inverter"), false,
                                () => CreateParentNode(childNode, NodeType.Inverter, createAtMousePosition));
            genericMenu.AddItem(new GUIContent("Add Sequence"), false,
                                () => CreateParentNode(childNode, NodeType.Sequence, createAtMousePosition));
            genericMenu.AddItem(new GUIContent("Add Selector"), false,
                                () => CreateParentNode(childNode, NodeType.Selector, createAtMousePosition));
            genericMenu.ShowAsContext();
        }
Esempio n. 11
0
        protected void RefreshConnection()
        {
            NodeEditorObject prntObj = nodeObject.Parent;

            if (prntObj != null)
            {
                parent = (IParentNodeWindow)prntObj.GetWindow();
                if (parent != null)
                {
                    refreshConnection = false;
                }
            }
        }
Esempio n. 12
0
        public NodeEditorObject(NodeType type, int nodeIndex)
        {
            nodeType = type;
            index    = nodeIndex;
            if (nodeIndex == OhBehaveTreeBlueprint.ROOT_INDEX)
            {
                isConnectedToRoot = true;
                parentIndex       = OhBehaveTreeBlueprint.ROOT_NODE_PARENT_INDEX;
            }

            parent = Parent;
            CreateWindow();
        }
Esempio n. 13
0
        private void AddChild(NodeEditorObject newChildNode)
        {
            if (children == null)
            {
                children = new List <int>();
            }
            else if (children.Contains(newChildNode.index))
            {
                Debug.LogError("Duplicate node index " + newChildNode.index + " found in " + displayName);
                return;
            }

            children.Add(newChildNode.index);
            window.UpdateChildrenList();
        }
Esempio n. 14
0
		public static void Init(NodeEditorObject node)
		{
			if (instance == null)
			{
				instance = ScriptableObject.CreateInstance<NodeEditPopup>();
				instance.position = new Rect(
					GUIUtility.GUIToScreenPoint(Event.current.mousePosition),
					new Vector2(250, 150));
				instance.ShowPopup();
			}
			else
			{
				instance.Repaint();
			}

			editing = node;
			newname = editing.displayName;
			newdesc = editing.description;
		}
Esempio n. 15
0
        /// <summary>
        /// Called when a node gets deleted to keep now orphaned nodes and parent node in sink.
        /// </summary>
        public void NotifyFamilyOfDelete()
        {
            if (parentIndex != OhBehaveTreeBlueprint.NO_PARENT_INDEX)
            {
                Parent.RemoveChild(index);
            }

            if (HasChildren())
            {
                // this node has children. Warn before deleting?
                var ohBehave      = EditorWindow.GetWindow <OhBehaveEditorWindow>();
                var treeBlueprint = ohBehave.treeBlueprint;

                for (int i = children.Count - 1; i >= 0; --i)
                {
                    NodeEditorObject child = treeBlueprint.GetNodeObjectByIndex(children[i]);
                    child.RemoveParent();
                }
            }
        }
        public void ConstructNodes()
        {
            if (nodeObjects == null)
            {
                InitializeNodeDictionary();
            }

            serializedObject = new SerializedObject(this);

            if (nodeObjects.Count == 0)
            {
                if (OhBehaveEditorWindow.SequenceNodeStyle == null)
                {
                    return;
                }

                var winData = new Rect(
                    -OhBehaveEditorWindow.SequenceNodeStyle.size.x / 2,
                    -OhBehaveEditorWindow.SequenceNodeStyle.size.y,
                    OhBehaveEditorWindow.SequenceNodeStyle.size.x,
                    OhBehaveEditorWindow.SequenceNodeStyle.size.y);

                NodeEditorObject newNode = new NodeEditorObject(NodeType.Sequence, ROOT_INDEX)
                {
                    description = "The Root Node - where it all begins",
                    displayName = "Root",
                    windowRect  = winData,
                };

                AddNewNode(newNode, 0);
                jsonTreeData.rootNode = new JsonNodeData {
                    nodeType = NodeType.Sequence
                };

                zoomerSettings = new ZoomerSettings();
                AssetDatabase.Refresh();
                EditorUtility.SetDirty(this);
                save = true;
            }
        }
        private void CreateChildNode(NodeEditorObject parentNode, NodeType nodeType, bool createAtMousePosition)
        {
            Rect parentWindowRect = parentNode.GetWindow().GetRectNoOffset();

            if (parentNode.nodeType == NodeType.Inverter)
            {
                if (parentNode.HasChildren())
                {
                    DisconnectNodes(parentNode, GetNodeObjectByIndex(parentNode.GetChildren()[0]));
                }
            }

            switch (nodeType)
            {
            case NodeType.Leaf:
            case NodeType.Sequence:
            case NodeType.Selector:
            case NodeType.Inverter:
                NodeEditorObject newNode
                    = new NodeEditorObject(nodeType, ++lastNodeIndex)
                    {
                    description = nodeType + " type node. Add description of desired behaviour",
                    displayName = nodeType.ToString(),
                    windowRect  = new Rect(createAtMousePosition ?
                                           savedMousePos + EditorWindow.GetWindow <OhBehaveEditorWindow>().zoomer.GetContentOffset() :
                                           new Vector2(parentWindowRect.x,
                                                       parentWindowRect.y + parentWindowRect.height + DefaultTreeRowHeight),
                                           OhBehaveEditorWindow.SequenceNodeStyle.size)
                    };

                AddNewNode(newNode, lastNodeIndex);
                NodeEditorObject.ConnectNodes(parentNode, newNode);
                break;

            default:
                Debug.LogWarning("TODO: CreateChildNode of type " + nodeType);
                break;
            }
        }
 public void DeleteNode(NodeEditorObject node)
 {
     deleteTasks.Add(node);
 }
 private void AddNewNode(NodeEditorObject newNode, int nodeIndex)
 {
     nodeObjects.Add(nodeIndex, newNode);
     savedNodes.Add(newNode);
     save = true;
 }
Esempio n. 20
0
 public static void ConnectNodes(NodeEditorObject parent, NodeEditorObject child)
 {
     parent.AddChild(child);
     child.AddParent(parent.index);
 }
Esempio n. 21
0
 public LeafNodeWindow(NodeEditorObject node) : base(node)
 {
 }
Esempio n. 22
0
 /// <summary>
 /// Called when Remove Connection selected from context menu.
 /// </summary>
 private void DisconnectParent(IParentNodeWindow parent)
 {
     NodeEditorObject.DisconnectNodes(((NodeWindow)parent).nodeObject, nodeWindow.nodeObject);
 }
Esempio n. 23
0
 private void DisconnectChild(NodeEditorObject childNode)
 {
     NodeEditorObject.DisconnectNodes(nodeWindow.nodeObject, childNode);
 }
 public InverterNodeWindow(NodeEditorObject nodeObj) : base(nodeObj)
 {
 }
 public CompositeNodeWindow(NodeEditorObject node) : base(node)
 {
 }