コード例 #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());
                }
            }
        }
コード例 #2
0
 public void SetEndConnection(ZNodeConnector outConnector)
 {
     if (_selectedConnector != null && _selectedConnector != outConnector)
     {
         if (_selectedConnector.CanTakeConnection())
         {
             _currentNodeTree.CreateConnection(_selectedConnector, outConnector);
         }
     }
     _selectedConnector = null;
 }
コード例 #3
0
        public ZNodeConnection(ZNodeEditor editor, ZNodeConnector inConnector, ZNodeConnector outConnector, System.Action <ZNodeConnection> RemoveConnectionFunc)
        {
            _editor               = editor;
            _inConnector          = inConnector;
            _outConnector         = outConnector;
            _removeConnectionFunc = RemoveConnectionFunc;

            _style = new GUIStyle();
            _style.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left.png") as Texture2D;
            _style.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left on.png") as Texture2D;
            _style.border            = new RectOffset(4, 4, 12, 12);
        }
コード例 #4
0
 void ResetBeforeTabSwitch()
 {
     if (_selectedNode != null)
     {
         DeselectNode(_selectedNode);
     }
     if (_selectedConnector != null)
     {
         _selectedConnector = null;
     }
     if (_currentNodeTree != null)
     {
         _currentNodeTree.ResetNodes();
     }
 }
コード例 #5
0
        public void CreateConnection(ZNodeConnector inConnector, ZNodeConnector outConnector)
        {
            ZNodeConnection newConnection = new ZNodeConnection(_nodeEditor, inConnector, outConnector, RemoveConnection);

            _connections.Add(newConnection);

            // Can only have one outgoing connection for a root/single child connector
            if (inConnector.Node.BaseType == ZNode.BASE_TYPE.ROOT || inConnector.Node.BaseType == ZNode.BASE_TYPE.DECORATOR)
            {
                inConnector.CheckToRemoveExistingConnection();
            }
            inConnector.AddConnection(newConnection);

            // Can only have one incoming node for an out connector
            outConnector.CheckToRemoveExistingConnection();
            outConnector.AddConnection(newConnection);

            if (_nodeEditor.SkinItem.autoLayoutAsDefault)
            {
                AutoLayout();
            }
        }
コード例 #6
0
ファイル: ZNode.cs プロジェクト: ZenCoderGames/ZAI
 protected virtual void CreateOutConnector()
 {
     _outConnector = new ZNodeConnector(this, ZNodeConnector.TYPE.OUT);
     _connectorList.Add(_outConnector);
 }
コード例 #7
0
ファイル: ZNode.cs プロジェクト: ZenCoderGames/ZAI
 protected virtual void CreateInConnector()
 {
     _inConnector = new ZNodeConnector(this, ZNodeConnector.TYPE.IN);
     _connectorList.Add(_inConnector);
 }
コード例 #8
0
 public void SetStartConnection(ZNodeConnector inConnector)
 {
     _selectedConnector = inConnector;
 }