Example #1
0
        public void Load(JSON js, string filePath)
        {
            ClearAll();

            SetFilePath(filePath);
            _name = js.ToString("name");

            JSON[] nodeListJS = js.ToArray <JSON>("bTree");
            for (int i = 0; i < nodeListJS.Length; ++i)
            {
                float           posX     = nodeListJS[i].ToFloat("posX");
                float           posY     = nodeListJS[i].ToFloat("posY");
                ZNode.BASE_TYPE baseType = ZEditorUtils.ParseEnum <ZNode.BASE_TYPE>(nodeListJS[i].ToString("baseType"));
                ZNode           newNode  = null;
                if (baseType == ZNode.BASE_TYPE.ROOT)
                {
                    newNode = CreateRoot(posX, posY);
                }
                else if (baseType == ZNode.BASE_TYPE.SUBTREE)
                {
                    newNode = CreateBaseNode(baseType, posX, posY, nodeListJS[i]);
                }
                else if (baseType == ZNode.BASE_TYPE.COMPOSITE)
                {
                    ZNodeComposite.NODE_TYPE nodeType = ZEditorUtils.ParseEnum <ZNodeComposite.NODE_TYPE>(nodeListJS[i].ToString("nodeType"));
                    newNode = CreateCompositeNode(nodeType, posX, posY, nodeListJS[i]);
                }
                else if (baseType == ZNode.BASE_TYPE.DECORATOR)
                {
                    ZNodeDecorator.NODE_TYPE nodeType = ZEditorUtils.ParseEnum <ZNodeDecorator.NODE_TYPE>(nodeListJS[i].ToString("nodeType"));
                    newNode = CreateDecoratorNode(nodeType, posX, posY, nodeListJS[i]);
                }
                else if (baseType == ZNode.BASE_TYPE.ACTION)
                {
                    ZBTActionManager.NODE_TYPE nodeType = ZEditorUtils.ParseEnum <ZBTActionManager.NODE_TYPE>(nodeListJS[i].ToString("nodeType"));
                    newNode = CreateActionNode(nodeType, posX, posY, nodeListJS[i]);
                }
                newNode.Name = nodeListJS[i].ToString("id");
            }

            JSON[] connectionListJS = js.ToArray <JSON>("connections");
            for (int i = 0; i < connectionListJS.Length; ++i)
            {
                int            inId         = connectionListJS[i].ToInt("inNodeId");
                int            outId        = connectionListJS[i].ToInt("outNodeId");
                ZNodeConnector inConnector  = GetNode(inId).OutConnector;
                ZNodeConnector outConnector = GetNode(outId).InConnector;
                if (inConnector != null && outConnector != null)
                {
                    CreateConnection(inConnector, outConnector);
                }
                else
                {
                    Debug.Log("Unable to find in or out connector for node: " + inId.ToString() + " " + outId.ToString());
                }
            }
        }
Example #2
0
        public void RemoveNode(ZNode node)
        {
            _currentNodeTree.RemoveNode(node);

            if (_selectedNode == node)
            {
                DeselectNode(_selectedNode);
            }
        }
Example #3
0
 public void DeselectNode(ZNode node)
 {
     _selectedNode = null;
     if (OnNodeSelected != null)
     {
         OnNodeSelected(null);
     }
     GUI.changed = true;
 }
Example #4
0
        public ZNodeConnector(ZNode node, TYPE type)
        {
            _type       = type;
            _parentNode = node;

            SetupSkinParams();

            _connections = new List <ZNodeConnection>();
        }
Example #5
0
 public void DeselectOtherNodes(ZNode node)
 {
     for (int i = 0; i < _nodes.Count; ++i)
     {
         if (_nodes[i] != node)
         {
             _nodes[i].Reset();
         }
     }
 }
Example #6
0
        public static ZNode CreateNode(NODE_TYPE nodeType, ZNodeTree nodeTree, Rect nodeRect, JSON js)
        {
            ZNode node = null;

            if (nodeType == NODE_TYPE.REPEATER)
            {
                node = new ZBTRepeater(nodeTree, nodeRect);
            }

            return(node);
        }
Example #7
0
        public ZNode CreateActionNode(ZBTActionManager.NODE_TYPE actionType, float posX, float posY, JSON js)
        {
            Rect  nodeRect = new Rect(posX, posY, _nodeEditor.SkinItem.nodeWidth, _nodeEditor.SkinItem.nodeHeight);
            ZNode node     = ZBTActionManager.CreateNode(actionType, this, nodeRect, js);

            if (node != null)
            {
                _nodes.Add(node);
            }
            return(node);
        }
Example #8
0
        public ZNode CreateCompositeNode(ZNodeComposite.NODE_TYPE nodeType, float posX, float posY, JSON js)
        {
            Rect  nodeRect = new Rect(posX, posY, _nodeEditor.SkinItem.nodeWidth, _nodeEditor.SkinItem.nodeHeight);
            ZNode node     = ZNodeComposite.CreateNode(nodeType, this, nodeRect, js);

            if (node != null)
            {
                _nodes.Add(node);
            }
            return(node);
        }
Example #9
0
        public static ZNode CreateNode(NODE_TYPE nodeType, ZNodeTree nodeTree, Rect nodeRect, JSON js)
        {
            ZNode node = null;

            if (nodeType == NODE_TYPE.SEQUENCER)
            {
                node = new ZBTSequencer(nodeTree, nodeRect);
            }

            return(node);
        }
Example #10
0
 public void RemoveNode(ZNode node)
 {
     _nodes.Remove(node);
     for (int i = 0; i < _connections.Count; ++i)
     {
         if (_connections[i].ContainsNode(node))
         {
             RemoveConnection(_connections[i]);
             i--;
         }
     }
 }
Example #11
0
        public int GetNodeId(ZNode node)
        {
            for (int i = 0; i < _nodes.Count; ++i)
            {
                if (_nodes[i] == node)
                {
                    return(i);
                }
            }

            return(-1);
        }
Example #12
0
        public ZNode CreateBaseNode(ZNode.BASE_TYPE type, float posX, float posY, JSON js)
        {
            Rect  nodeRect = new Rect(posX, posY, _nodeEditor.SkinItem.nodeWidth, _nodeEditor.SkinItem.nodeHeight);
            ZNode node     = null;

            if (type == ZNode.BASE_TYPE.SUBTREE)
            {
                node = new ZNodeSubTree(this, nodeRect, js);
            }
            _nodes.Add(node);
            return(node);
        }
Example #13
0
        void UpdateRightOffsetCount(ZNode rightChildNode, ref float rightIndex)
        {
            List <ZNode> children   = rightChildNode.GetChildren();
            int          childCount = children.Count;

            if (childCount > 0)
            {
                if (childCount > 1)
                {
                    rightIndex += (childCount / 2) * _nodeEditor.SkinItem.autoLayoutWidth;
                }

                UpdateLeftOffsetCount(children[children.Count - 1], ref rightIndex);
                UpdateRightOffsetCount(children[children.Count - 1], ref rightIndex);
            }
        }
Example #14
0
        List <ZNode> GetChildren(ZNode parentNode)
        {
            List <ZNode> children = new List <ZNode>();

            for (int i = 0; i < _connections.Count; ++i)
            {
                if (_connections[i].HasParentNode(parentNode))
                {
                    children.Add(_connections[i].GetChildNode());
                }
            }
            if (_nodeEditor.SkinItem.isVerticalLayout)
            {
                children.Sort(SortByX);
            }
            else
            {
                children.Sort(SortByY);
            }

            return(children);
        }
Example #15
0
 int SortByX(ZNode n1, ZNode n2)
 {
     return(n1.GetOriginalRect().x.CompareTo(n2.GetOriginalRect().x));
 }
Example #16
0
 public bool HasParentNode(ZNode node)
 {
     return(_inConnector.Node == node);
 }
Example #17
0
        void DoAutoArrangeHorizontal(ZNode parentNode)
        {
            float        parentX    = parentNode.GetOriginalRect().x;
            float        parentY    = parentNode.GetOriginalRect().y;
            List <ZNode> children   = parentNode.GetChildren();
            int          childCount = children.Count;

            // Case 1: no children
            if (childCount == 0)
            {
                return;
            }
            // Case 2: one child
            if (childCount <= 1)
            {
                children[0].SetPosition(parentX + _nodeEditor.SkinItem.autoLayoutHeight, parentY);
                DoAutoArrangeHorizontal(children[0]);
                return;
            }

            // Case 3: multiple children
            bool isEvenTree = (childCount % 2 == 0);
            int  mid        = childCount / 2;

            if (!isEvenTree)
            {
                // middle child of this tree stays under parent position
                children[mid].SetPosition(parentX + _nodeEditor.SkinItem.autoLayoutHeight, parentY);
                DoAutoArrangeHorizontal(children[mid]);
            }

            // process left children
            int i = mid - 1;

            while (i >= 0)
            {
                float startY = parentY;
                if (i < mid - 1)
                {
                    startY = children[i + 1].GetOriginalRect().y;
                }

                float y = startY - _nodeEditor.SkinItem.autoLayoutWidth;
                // Check my rightmost child
                float rightIndex = 0;
                UpdateRightOffsetCount(children[i], ref rightIndex);
                y -= rightIndex;

                if ((isEvenTree && i < mid - 1) || (!isEvenTree))
                {
                    // Check my right neighbors left most child
                    ZNode rightNbr          = children[i + 1];
                    float rightNbrLeftIndex = 0;
                    UpdateLeftOffsetCount(rightNbr, ref rightNbrLeftIndex);
                    y -= rightNbrLeftIndex;
                }

                children[i].SetPosition(parentX + _nodeEditor.SkinItem.autoLayoutHeight, y);
                DoAutoArrangeHorizontal(children[i]);

                i--;
            }

            // process right children
            i = isEvenTree?mid:mid + 1;
            while (i < children.Count)
            {
                float startY = parentY;
                if ((isEvenTree && i > mid) || (!isEvenTree && i > mid + 1))
                {
                    startY = children[i - 1].GetOriginalRect().y;
                }

                float y = startY + _nodeEditor.SkinItem.autoLayoutWidth;

                // Shift to the right based on left most child (recursive check)
                float leftIndex = 0;
                UpdateLeftOffsetCount(children[i], ref leftIndex);
                y += leftIndex;

                if ((isEvenTree && i > mid) || (!isEvenTree))
                {
                    // Check left neighbor's rightmost child for another right shift for spacing
                    ZNode leftNbr          = children[i - 1];
                    float leftNbrLeftIndex = 0;
                    UpdateRightOffsetCount(leftNbr, ref leftNbrLeftIndex);
                    y += leftNbrLeftIndex;
                }

                children[i].SetPosition(parentX + _nodeEditor.SkinItem.autoLayoutHeight, y);
                DoAutoArrangeHorizontal(children[i]);

                i++;
            }
        }
Example #18
0
 public bool IsNodeInSelectedGroup(ZNode node)
 {
     return(_selectedNodes.Contains(node));
 }
Example #19
0
 public bool ContainsNode(ZNode node)
 {
     return((_inConnector.Node == node) || (_outConnector.Node == node));
 }
Example #20
0
 int SortByY(ZNode n1, ZNode n2)
 {
     return(n1.GetOriginalRect().y.CompareTo(n2.GetOriginalRect().y));
 }
Example #21
0
 void OnNodeSelected(ZNode node)
 {
     _selectedNode = node;
     GUI.changed   = true;
 }
Example #22
0
 ZNode CreateRoot(float posX, float posY)
 {
     _rootNode = new ZNodeRoot(this, new Rect(posX, posY, _nodeEditor.SkinItem.nodeWidth, _nodeEditor.SkinItem.nodeHeight));
     _nodes.Add(_rootNode);
     return(_rootNode);
 }