コード例 #1
0
        public static BTreeNodeDesigner CreateBTreeNodeDesigner(BTreeEditorNodeConfig[] _configNodes, BTreeEditorNode[] _editorNodes, ref BTreeNodeDesigner[] _nodeDesigners, int _index)
        {
            BTreeEditorNode _editorNode = _editorNodes[_index];

            for (int i = 0; i < _editorNode.m_Node.m_ChildCount; i++)
            {
                int _childIndex = _editorNode.m_Node.m_ChildNodes[i].m_Index;
                if (_nodeDesigners[_childIndex] == null)
                {
                    _nodeDesigners[_childIndex] = CreateBTreeNodeDesigner(_configNodes, _editorNodes, ref _nodeDesigners, _childIndex);
                }
            }
            BTreeNodeDesigner _node = new BTreeNodeDesigner(_editorNode);

            //_node.m_EditorNode = _editorNode;
            //_node.m_NodeName = _editorNode.m_Node.m_Name;
            //_node.m_ChildNodeList = new List<BTreeNodeDesigner>();
            //_node.m_ChildNodeConnectionList = new List<BTreeNodeConnection>();

            for (int i = 0; i < _editorNode.m_Node.m_ChildCount; i++)
            {
                int _childIndex = _editorNode.m_Node.m_ChildNodes[i].m_Index;
                _node.m_ChildNodeList.Add(_nodeDesigners[_childIndex]);
                BTreeNodeConnection _connection = new BTreeNodeConnection(_nodeDesigners[_childIndex], _node, NodeConnectionType.Outgoing);
                _node.m_ChildNodeConnectionList.Add(_connection);
            }
            return(_node);
        }
コード例 #2
0
        public void drawInspector(BTreeNodeDesigner _selectNode)
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Script:", new GUILayoutOption[] { GUILayout.Width(100) });
            string[] scripts = AssetDatabase.FindAssets("t:Script " + _selectNode.m_EditorNode.m_Node.GetType().Name);
            if (scripts != null && scripts.Length > 0)
            {
                string     path       = AssetDatabase.GUIDToAssetPath(scripts[0]);
                MonoScript monoScript = (MonoScript)AssetDatabase.LoadAssetAtPath(path, typeof(MonoScript));
                EditorGUILayout.ObjectField("", monoScript, typeof(MonoScript), false);
            }
            GUILayout.EndHorizontal();

            //if (GUILayout.Button(BTreeEditorUtility.GearTexture, BTreeEditorUtility.TransparentButtonGUIStyle, new GUILayoutOption[0]))
            //{
            //    GenericMenu genericMenu = new GenericMenu();
            //    genericMenu.AddItem(new GUIContent("Edit Script"), false, new GenericMenu.MenuFunction2(openInFileEditor), _selectNode.m_EditorNode.m_Node);
            //    //genericMenu.AddItem(new GUIContent("Reset"), false, new GenericMenu.MenuFunction2(this.resetTask), _selectNode);
            //    genericMenu.ShowAsContext();
            //}
            var  _node     = _selectNode.m_EditorNode.m_Node;
            Type _nodeType = _selectNode.m_EditorNode.m_Node.GetType();

            FieldInfo[] fields = _nodeType.GetFields(BindingFlags.Instance | BindingFlags.Public);
            for (int i = fields.Length - 1; i >= 0; i--)
            {
                DrawValue(_node, fields[i]);
            }
            GUILayout.Label("Precondition:");
            int index = -1;

            _node.m_NodePrecondition = DrawPrecondition(_node.GetNodePrecondition(), 0, ref index);
            GUILayout.FlexibleSpace();
        }
コード例 #3
0
 public static BTreeNodeDesigner[] CreateBTreeNodeDesignerFromConfig(BTreeEditorTreeConfig _config)
 {
     BTreeNodeDesigner[] _nodeDesigners = new BTreeNodeDesigner[_config.m_EditorNodes.Length];
     BTreeEditorNode[]   _editorNodes   = CreateBTreeEditorNode(_config);
     //递归创建节点
     for (int i = 0; i < _nodeDesigners.Length; i++)
     {
         if (_nodeDesigners[i] == null)
         {
             _nodeDesigners[i] = CreateBTreeNodeDesigner(_config.m_EditorNodes, _editorNodes, ref _nodeDesigners, i);
         }
     }
     //初始化父节点与连线
     for (int i = 0; i < _nodeDesigners.Length; i++)
     {
         var _editorNode = _editorNodes[i];
         if (_editorNode.m_Node.m_ParentNode != null)
         {
             int _parentIndex = _editorNode.m_Node.m_ParentNode.m_Index;
             _nodeDesigners[i].m_ParentNode = _nodeDesigners[_parentIndex];
             BTreeNodeConnection _connection = new BTreeNodeConnection(_nodeDesigners[i], _nodeDesigners[_parentIndex], NodeConnectionType.Incoming);
             _nodeDesigners[i].m_ParentNodeConnection = _connection;
         }
     }
     return(_nodeDesigners);
 }
コード例 #4
0
        //递归绘制节点
        private bool drawNodeChildren(BTreeNodeDesigner nodeDesigner, Vector2 offset, bool disabledNode)
        {
            if (nodeDesigner == null)
            {
                return(false);
            }
            bool result = false;

            if (nodeDesigner.drawNode(offset, false, disabledNode))
            {
                result = true;
            }
            if (nodeDesigner.m_ChildNodeList != null)
            {
                for (int i = 0; i < nodeDesigner.m_ChildNodeList.Count; i++)
                {
                    var _child = nodeDesigner.m_ChildNodeList[i];
                    if (drawNodeChildren(_child, offset, _child.m_EditorNode.m_Disable))
                    {
                        result = true;
                    }
                }
            }
            return(result);
        }
コード例 #5
0
 public BTreeNodeDesigner nodeChildrenAt(BTreeNodeDesigner nodeDesigner, Vector2 point, Vector2 offset)
 {
     if (nodeDesigner.contains(point, offset, true))
     {
         return(nodeDesigner);
     }
     if (nodeDesigner.m_IsParent)
     {
         if (nodeDesigner.m_ChildNodeList != null)
         {
             for (int i = 0; i < nodeDesigner.m_ChildNodeList.Count; i++)
             {
                 BTreeNodeDesigner result;
                 if (nodeDesigner.m_ChildNodeList[i] != null)
                 {
                     result = nodeChildrenAt(nodeDesigner.m_ChildNodeList[i], point, offset);
                     if (result != null)
                     {
                         return(result);
                     }
                 }
             }
         }
     }
     return(null);
 }
コード例 #6
0
        public static BTreeEditorTreeConfig CreateEditorTreeConfigFromRootEditorNode(BTreeNodeDesigner _rootEditorNode)
        {
            TreeConfig            _treeConfig       = BTreeNodeFactory.CreateConfigFromBTreeRoot(_rootEditorNode.m_EditorNode.m_Node);
            BTreeEditorTreeConfig _treeEditorConfig = new BTreeEditorTreeConfig(_treeConfig);
            int index = 0;

            CreateEditorNodeConfigFromRootEditorNode(_rootEditorNode, ref _treeEditorConfig.m_EditorNodes, ref index);

            return(_treeEditorConfig);
        }
コード例 #7
0
 private void dragTask(BTreeNodeDesigner nodeDesigner, Vector2 delta, bool dragChildren, bool hasDragged)
 {
     nodeDesigner.movePosition(delta);
     if (nodeDesigner.m_IsParent && dragChildren)
     {
         for (int i = 0; i < nodeDesigner.m_ChildNodeList.Count; i++)
         {
             dragTask(nodeDesigner.m_ChildNodeList[i], delta, dragChildren, hasDragged);
         }
     }
 }
コード例 #8
0
 public void AddParentConnectionLine(BTreeNodeDesigner orgNode)
 {
     BTreeNodeConnection line = new BTreeNodeConnection(this, orgNode, NodeConnectionType.Incoming);
     if (m_ParentNodeConnection != null)
     {
         m_ParentNodeConnection.m_OriginatingNodeDesigner.delectChildNode(this);
     }
     m_ParentNodeConnection = line;
     m_ParentNode = orgNode;
     markDirty();
 }
コード例 #9
0
 //加载
 public void load(BTreeEditorConfig _config)
 {
     m_RootNode = BTreeEditorNodeFactory.CreateBTreeNodeDesignerFromConfig(_config.m_RootNode)[0];
     m_RootNode.SetEntryDisplay(true);
     if (_config.m_DetachedNode != null)
     {
         m_DetachedNodes = new List <BTreeNodeDesigner>();
         for (int i = 0; i < _config.m_DetachedNode.Count; i++)
         {
             BTreeNodeDesigner _detachedNode = BTreeEditorNodeFactory.CreateBTreeNodeDesignerFromConfig(_config.m_DetachedNode[i])[0];
             m_DetachedNodes.Add(_detachedNode);
         }
     }
 }
コード例 #10
0
 public void delectChildNode(BTreeNodeDesigner childNodeDesigner)
 {
     m_ChildNodeList.Remove(childNodeDesigner);
     for (int i = 0; i < m_ChildNodeConnectionList.Count; i++)
     {
         if (m_ChildNodeConnectionList[i].m_DestinationNodeDesigner.Equals(childNodeDesigner))
         {
             m_ChildNodeConnectionList.RemoveAt(i);
             m_EditorNode.DelChildNode(childNodeDesigner.m_EditorNode);
             markDirty();
             break;
         }
     }
     childNodeDesigner.m_ParentNode = null;
 }
コード例 #11
0
 public static BTreeEditorNodeConfig CreateEditorNodeConfigFromRootEditorNode(BTreeNodeDesigner _rootEditorNode, ref BTreeEditorNodeConfig[] _editorNodes, ref int _index)
 {
     //int _index = _rootEditorNode.m_EditorNode.m_Node.m_Index;
     _editorNodes[_index].m_PosX    = _rootEditorNode.m_EditorNode.m_Pos.x;
     _editorNodes[_index].m_PosY    = _rootEditorNode.m_EditorNode.m_Pos.y;
     _editorNodes[_index].m_Disable = _rootEditorNode.m_EditorNode.m_Disable;
     if (_rootEditorNode.m_ChildNodeList != null)
     {
         for (int i = 0; i < _rootEditorNode.m_ChildNodeList.Count; i++)
         {
             _index = _index + 1;
             CreateEditorNodeConfigFromRootEditorNode(_rootEditorNode.m_ChildNodeList[i], ref _editorNodes, ref _index);
         }
     }
     return(_editorNodes[_index]);
 }
コード例 #12
0
 //递归绘制节点说明
 private void drawNodeCommentChildren(BTreeNodeDesigner nodeDesigner, Vector2 offset)
 {
     if (nodeDesigner == null)
     {
         return;
     }
     nodeDesigner.drawNodeComment(offset);
     if (nodeDesigner.m_ChildNodeList != null)
     {
         for (int i = 0; i < nodeDesigner.m_ChildNodeList.Count; i++)
         {
             var _child = nodeDesigner.m_ChildNodeList[i];
             drawNodeCommentChildren(_child, offset);
         }
     }
 }
コード例 #13
0
 private void SetNodeActive(BTreeNodeDesigner nodeDesigner, bool isEnable)
 {
     if (isEnable)
     {
         nodeDesigner.enable();
     }
     else
     {
         nodeDesigner.disable();
     }
     if (nodeDesigner.m_ChildNodeList != null)
     {
         for (int i = 0; i < nodeDesigner.m_ChildNodeList.Count; i++)
         {
             SetNodeActive(nodeDesigner.m_ChildNodeList[i], isEnable);
         }
     }
 }
コード例 #14
0
 //递归绘制连线
 private void drawNodeConnectionChildren(BTreeNodeDesigner nodeDesigner, Vector2 offset, float graphZoom, bool disabledNode)
 {
     if (nodeDesigner == null)
     {
         return;
     }
     if (!nodeDesigner.m_EditorNode.m_IsCollapsed)
     {
         nodeDesigner.drawNodeConnection(offset, graphZoom, nodeDesigner.m_EditorNode.m_Disable || disabledNode);
         if (nodeDesigner.m_ChildNodeList != null)
         {
             for (int i = 0; i < nodeDesigner.m_ChildNodeList.Count; i++)
             {
                 var _child = nodeDesigner.m_ChildNodeList[i];
                 drawNodeConnectionChildren(_child, offset, graphZoom, _child.m_EditorNode.m_Disable || disabledNode);
             }
         }
     }
 }
コード例 #15
0
 //删除节点
 public void delectNode(BTreeNodeDesigner nodeDesigner)
 {
     if (nodeDesigner.m_IsParent)
     {
         for (int i = 0; i < nodeDesigner.m_ChildNodeConnectionList.Count; i++)
         {
             BTreeNodeDesigner _destinationNodeDesigner = nodeDesigner.m_ChildNodeConnectionList[i].m_DestinationNodeDesigner;
             m_DetachedNodes.Add(_destinationNodeDesigner);
             _destinationNodeDesigner.m_ParentNode = null;
         }
     }
     if (nodeDesigner.m_ParentNode != null)
     {
         nodeDesigner.m_ParentNode.delectChildNode(nodeDesigner);
     }
     m_DetachedNodes.Remove(nodeDesigner);
     if (m_RootNode != null && m_RootNode.Equals(nodeDesigner))
     {
         m_RootNode = null;
     }
 }
コード例 #16
0
 //添加连线
 public void addSelectNodeLine(BTreeNodeDesigner destNode)
 {
     if (m_RootNode != null && m_RootNode.Equals(destNode))
     {
         return;
     }
     if (m_SelectedNodes != null && m_SelectedNodes.Count == 1)
     {
         m_SelectedNodes[0].AddChildNode(destNode);
     }
     if (m_DetachedNodes != null)
     {
         for (int i = 0; i < m_DetachedNodes.Count; i++)
         {
             if (m_DetachedNodes[i].Equals(destNode))
             {
                 m_DetachedNodes.RemoveAt(i);
             }
         }
     }
 }
コード例 #17
0
 public void AddChildNode(BTreeNodeDesigner destNode)
 {
     BTreeNodeConnection line = new BTreeNodeConnection(destNode, this, NodeConnectionType.Outgoing);
     if (m_ChildNodeConnectionList == null)
     {
         m_ChildNodeConnectionList = new List<BTreeNodeConnection>();
     }
     for (int i = 0; i < m_ChildNodeConnectionList.Count; i++)
     {
         if (m_ChildNodeConnectionList[i].m_DestinationNodeDesigner.Equals(destNode))
         {
             return;
         }
     }
     m_ChildNodeConnectionList.Add(line);
     m_ChildNodeList.Add(destNode);
     m_EditorNode.AddChildNode(destNode.m_EditorNode);
     destNode.AddParentConnectionLine(this);
     destNode.ReSetIndex();
     markDirty();
 }
コード例 #18
0
        //添加节点
        public BTreeNodeDesigner addNode(Type type, Vector2 position)
        {
            BTreeNode       _node       = (BTreeNode)type.GetConstructor(new Type[] { }).Invoke(new object[] { });
            BTreeEditorNode _editorNode = new BTreeEditorNode(_node);

            _editorNode.m_Pos = position;
            BTreeNodeDesigner _nodeDesigner = new BTreeNodeDesigner(_editorNode);

            if (m_RootNode == null)
            {
                m_RootNode = _nodeDesigner;
                _nodeDesigner.SetEntryDisplay(true);
            }
            else
            {
                if (m_DetachedNodes == null)
                {
                    m_DetachedNodes = new List <BTreeNodeDesigner>();
                }
                m_DetachedNodes.Add(_nodeDesigner);
            }
            return(_nodeDesigner);
        }
コード例 #19
0
 public BTreeNodeConnection(BTreeNodeDesigner _dest, BTreeNodeDesigner _orig, NodeConnectionType _type)
 {
     m_DestinationNodeDesigner = _dest;
     m_OriginatingNodeDesigner = _orig;
     m_NodeConnectionType      = _type;
 }
コード例 #20
0
 //选中
 public void select(BTreeNodeDesigner nodeDesigner)
 {
     m_SelectedNodes.Add(nodeDesigner);
     nodeDesigner.select();
 }
コード例 #21
0
 //取消选中
 public void deselect(BTreeNodeDesigner nodeDesigner)
 {
     m_SelectedNodes.Remove(nodeDesigner);
     nodeDesigner.deselect();
 }