Beispiel #1
0
 public BTNodeDesigner NodeChildrenAt(BTNodeDesigner nodeDesigner, Vector2 point, Vector2 offset)
 {
     if (nodeDesigner.Contains(point, offset, true))
     {
         return(nodeDesigner);
     }
     if (nodeDesigner.IsParent)
     {
         if (nodeDesigner.mChildNodeList != null)
         {
             for (int i = 0; i < nodeDesigner.mChildNodeList.Count; i++)
             {
                 BTNodeDesigner result;
                 if (nodeDesigner.mChildNodeList[i] != null)
                 {
                     result = NodeChildrenAt(nodeDesigner.mChildNodeList[i], point, offset);
                     if (result != null)
                     {
                         return(result);
                     }
                 }
             }
         }
     }
     return(null);
 }
 public static BTNodeDesigner[] CreateBTreeNodeDesignerFromConfig(BTEditorTreeConfig _config)
 {
     BTNodeDesigner[] _nodeDesigners = new BTNodeDesigner[_config.mEditorNodes.Length];
     BTEditorNode[]   _editorNodes   = CreateBTreeEditorNode(_config);
     //递归创建节点
     for (int i = 0; i < _nodeDesigners.Length; i++)
     {
         if (_nodeDesigners[i] == null)
         {
             _nodeDesigners[i] = CreateBTreeNodeDesigner(_config.mEditorNodes, _editorNodes, ref _nodeDesigners, i);
         }
     }
     //初始化父节点与连线
     for (int i = 0; i < _nodeDesigners.Length; i++)
     {
         var _editorNode = _editorNodes[i];
         if (_editorNode.mNode.parent != null)
         {
             int _parentIndex = _editorNode.mNode.parent.index;
             _nodeDesigners[i].mParentNode = _nodeDesigners[_parentIndex];
             BTNodeConnection _connection = new BTNodeConnection(_nodeDesigners[i], _nodeDesigners[_parentIndex], NodeConnectionType.Incoming);
             _nodeDesigners[i].mParentNodeConnection = _connection;
         }
     }
     return(_nodeDesigners);
 }
Beispiel #3
0
        public void DrawInspector(BTNodeDesigner _selectNode)
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Script:", new GUILayoutOption[] { GUILayout.Width(100) });
            string[] scripts = AssetDatabase.FindAssets("t:Script " + _selectNode.mEditorNode.mNode.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.mEditorNode.mNode;
            Type _nodeType = _selectNode.mEditorNode.mNode.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.SetPrecondition(DrawPrecondition(_node.precondition, 0, ref index));
            GUILayout.FlexibleSpace();
        }
Beispiel #4
0
        //鼠标左键down
        private bool LeftMouseDown(int clickCount)
        {
            Vector2 point;

            if (!GetMousePositionInGraph(out point))
            {
                mIsConnectingLine = false;
                return(false);
            }
            var            nodeDesigner = mGraphDesigner.NodeAt(point, mGraphOffset);
            BTNodeDesigner _selectNode  = null;

            if (mGraphDesigner.mSelectedNodes != null && mGraphDesigner.mSelectedNodes.Count > 0)
            {
                _selectNode = mGraphDesigner.mSelectedNodes[0];
            }
            if (mIsConnectingLine && nodeDesigner != null && nodeDesigner != _selectNode)
            {
                mGraphDesigner.AddSelectNodeLine(nodeDesigner);
            }
            mGraphDesigner.ClearNodeSelection();
            if (nodeDesigner != null)
            {
                mGraphDesigner.Select(nodeDesigner);
                mNodeClicked = true;
            }
            mIsConnectingLine = false;
            return(true);
        }
Beispiel #5
0
        //递归绘制节点
        private bool DrawNodeChildren(BTNodeDesigner nodeDesigner, Vector2 offset, bool disabledNode)
        {
            if (nodeDesigner == null)
            {
                return(false);
            }
            bool result = false;

            if (nodeDesigner.DrawNode(offset, false, disabledNode))
            {
                result = true;
            }
            if (nodeDesigner.mChildNodeList != null)
            {
                for (int i = 0; i < nodeDesigner.mChildNodeList.Count; i++)
                {
                    var _child = nodeDesigner.mChildNodeList[i];
                    if (DrawNodeChildren(_child, offset, _child.mEditorNode.mDisable))
                    {
                        result = true;
                    }
                }
            }
            return(result);
        }
        public static BTNodeDesigner CreateBTreeNodeDesigner(BTEditorNodeConfig[] _configNodes, BTEditorNode[] _editorNodes, ref BTNodeDesigner[] _nodeDesigners, int _index)
        {
            BTEditorNode _editorNode = _editorNodes[_index];

            for (int i = 0; i < _editorNode.mNode.childCount; i++)
            {
                int _childIndex = _editorNode.mNode.children[i].index;
                if (_nodeDesigners[_childIndex] == null)
                {
                    _nodeDesigners[_childIndex] = CreateBTreeNodeDesigner(_configNodes, _editorNodes, ref _nodeDesigners, _childIndex);
                }
            }
            BTNodeDesigner _node = new BTNodeDesigner(_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.mNode.childCount; i++)
            {
                int _childIndex = _editorNode.mNode.children[i].index;
                _node.mChildNodeList.Add(_nodeDesigners[_childIndex]);
                BTNodeConnection _connection = new BTNodeConnection(_nodeDesigners[_childIndex], _node, NodeConnectionType.Outgoing);
                _node.mChildNodeConnectionList.Add(_connection);
            }
            return(_node);
        }
        public static BTEditorTreeConfig CreateEditorTreeConfigFromRootEditorNode(BTNodeDesigner _rootEditorNode)
        {
            TreeConfig         _treeConfig       = BTFactory.CreateConfigFromBTreeRoot(_rootEditorNode.mEditorNode.mNode);
            BTEditorTreeConfig _treeEditorConfig = new BTEditorTreeConfig(_treeConfig);
            int index = 0;

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

            return(_treeEditorConfig);
        }
Beispiel #8
0
 private void DragTask(BTNodeDesigner nodeDesigner, Vector2 delta, bool dragChildren, bool hasDragged)
 {
     nodeDesigner.MovePosition(delta);
     if (nodeDesigner.IsParent && dragChildren)
     {
         for (int i = 0; i < nodeDesigner.mChildNodeList.Count; i++)
         {
             DragTask(nodeDesigner.mChildNodeList[i], delta, dragChildren, hasDragged);
         }
     }
 }
Beispiel #9
0
        //绘制图形区域
        private bool DrawGraphArea()
        {
            Vector2 vector = GUI.BeginScrollView(new Rect(mGraphRect.x, mGraphRect.y, mGraphRect.width + BTEditorUtility.ScrollBarSize, mGraphRect.height + BTEditorUtility.ScrollBarSize), mGraphScrollPosition, new Rect(0f, 0f, mGraphScrollSize.x, mGraphScrollSize.y), true, true);

            if (vector != mGraphScrollPosition && Event.current.type != EventType.DragUpdated && Event.current.type != EventType.Ignore)
            {
                mGraphOffset        -= (vector - mGraphScrollPosition) / mGraphZoom;
                mGraphScrollPosition = vector;
                //mGraphDesigner.graphDirty();
            }
            GUI.EndScrollView();
            GUI.Box(mGraphRect, "", BTEditorUtility.GraphBackgroundGUIStyle);

            BTEditorZoomArea.Begin(mGraphRect, mGraphZoom);
            Vector2 mousePosition;

            if (!GetMousePositionInGraph(out mousePosition))
            {
                mousePosition = new Vector2(-1f, -1f);
            }
            bool result = false;

            if (mGraphDesigner.DrawNodes(mousePosition, mGraphOffset, mGraphZoom))
            {
                result = true;
            }
            if (mIsConnectingLine)
            {
                var            _curNode    = mGraphDesigner.NodeAt(mousePosition, mGraphOffset);
                BTNodeDesigner _selectNode = null;
                if (mGraphDesigner.mSelectedNodes != null && mGraphDesigner.mSelectedNodes.Count > 0)
                {
                    _selectNode = mGraphDesigner.mSelectedNodes[0];
                }
                Vector2 des   = mousePosition;
                Color   color = Color.green;
                if (_curNode != null)
                {
                    if (_curNode.mIsEntryDisplay == false && (_selectNode != null && _curNode != _selectNode))
                    {
                        des = _curNode.mEditorNode.mPos;
                    }
                    else
                    {
                        color = Color.red;
                    }
                }

                mGraphDesigner.DrawTempConnection(des, mGraphOffset, mGraphZoom, color);
            }
            BTEditorZoomArea.End();
            return(result);
        }
Beispiel #10
0
        public void AddParentConnectionLine(BTNodeDesigner orgNode)
        {
            BTNodeConnection line = new BTNodeConnection(this, orgNode, NodeConnectionType.Incoming);

            if (mParentNodeConnection != null)
            {
                mParentNodeConnection.mOriginatingNodeDesigner.DeleteChildNode(this);
            }
            mParentNodeConnection = line;
            mParentNode           = orgNode;
            MarkDirty();
        }
Beispiel #11
0
 //加载
 public void Load(BTEditorConfig _config)
 {
     mRootNode = BTEditorNodeFactory.CreateBTreeNodeDesignerFromConfig(_config.mRootNode)[0];
     mRootNode.SetEntryDisplay(true);
     if (_config.mDetachedNode != null)
     {
         mDetachedNodes = new List <BTNodeDesigner>();
         for (int i = 0; i < _config.mDetachedNode.Count; i++)
         {
             BTNodeDesigner _detachedNode = BTEditorNodeFactory.CreateBTreeNodeDesignerFromConfig(_config.mDetachedNode[i])[0];
             mDetachedNodes.Add(_detachedNode);
         }
     }
 }
Beispiel #12
0
 public void DeleteChildNode(BTNodeDesigner childNodeDesigner)
 {
     mChildNodeList.Remove(childNodeDesigner);
     for (int i = 0; i < mChildNodeConnectionList.Count; i++)
     {
         if (mChildNodeConnectionList[i].mDestinationNodeDesigner.Equals(childNodeDesigner))
         {
             mChildNodeConnectionList.RemoveAt(i);
             mEditorNode.RemoveChildNode(childNodeDesigner.mEditorNode);
             MarkDirty();
             break;
         }
     }
     childNodeDesigner.mParentNode = null;
 }
 public static BTEditorNodeConfig CreateEditorNodeConfigFromRootEditorNode(BTNodeDesigner _rootEditorNode, ref BTEditorNodeConfig[] _editorNodes, ref int _index)
 {
     //int _index = _rootEditorNode.m_EditorNode.m_Node.m_Index;
     _editorNodes[_index].mPosX    = _rootEditorNode.mEditorNode.mPos.x;
     _editorNodes[_index].mPosY    = _rootEditorNode.mEditorNode.mPos.y;
     _editorNodes[_index].mDisable = _rootEditorNode.mEditorNode.mDisable;
     if (_rootEditorNode.mChildNodeList != null)
     {
         for (int i = 0; i < _rootEditorNode.mChildNodeList.Count; i++)
         {
             _index = _index + 1;
             CreateEditorNodeConfigFromRootEditorNode(_rootEditorNode.mChildNodeList[i], ref _editorNodes, ref _index);
         }
     }
     return(_editorNodes[_index]);
 }
Beispiel #14
0
 //递归绘制节点说明
 private void DrawNodeCommentChildren(BTNodeDesigner nodeDesigner, Vector2 offset)
 {
     if (nodeDesigner == null)
     {
         return;
     }
     nodeDesigner.DrawNodeComment(offset);
     if (nodeDesigner.mChildNodeList != null)
     {
         for (int i = 0; i < nodeDesigner.mChildNodeList.Count; i++)
         {
             var _child = nodeDesigner.mChildNodeList[i];
             DrawNodeCommentChildren(_child, offset);
         }
     }
 }
Beispiel #15
0
 private void SetNodeActive(BTNodeDesigner nodeDesigner, bool isEnable)
 {
     if (isEnable)
     {
         nodeDesigner.Enable();
     }
     else
     {
         nodeDesigner.Disable();
     }
     if (nodeDesigner.mChildNodeList != null)
     {
         for (int i = 0; i < nodeDesigner.mChildNodeList.Count; i++)
         {
             SetNodeActive(nodeDesigner.mChildNodeList[i], isEnable);
         }
     }
 }
Beispiel #16
0
 //递归绘制连线
 private void DrawNodeConnectionChildren(BTNodeDesigner nodeDesigner, Vector2 offset, float graphZoom, bool disabledNode)
 {
     if (nodeDesigner == null)
     {
         return;
     }
     if (!nodeDesigner.mEditorNode.mIsCollapsed)
     {
         nodeDesigner.DrawNodeConnection(offset, graphZoom, nodeDesigner.mEditorNode.mDisable || disabledNode);
         if (nodeDesigner.mChildNodeList != null)
         {
             for (int i = 0; i < nodeDesigner.mChildNodeList.Count; i++)
             {
                 var _child = nodeDesigner.mChildNodeList[i];
                 DrawNodeConnectionChildren(_child, offset, graphZoom, _child.mEditorNode.mDisable || disabledNode);
             }
         }
     }
 }
Beispiel #17
0
        public void AddChildNode(BTNodeDesigner destNode)
        {
            BTNodeConnection line = new BTNodeConnection(destNode, this, NodeConnectionType.Outgoing);

            if (mChildNodeConnectionList == null)
            {
                mChildNodeConnectionList = new List <BTNodeConnection>();
            }
            for (int i = 0; i < mChildNodeConnectionList.Count; i++)
            {
                if (mChildNodeConnectionList[i].mDestinationNodeDesigner.Equals(destNode))
                {
                    return;
                }
            }
            mChildNodeConnectionList.Add(line);
            mChildNodeList.Add(destNode);
            mEditorNode.AddChildNode(destNode.mEditorNode);
            destNode.AddParentConnectionLine(this);
            MarkDirty();
        }
Beispiel #18
0
 //删除节点
 public void DeleteNode(BTNodeDesigner nodeDesigner)
 {
     if (nodeDesigner.IsParent)
     {
         for (int i = 0; i < nodeDesigner.mChildNodeConnectionList.Count; i++)
         {
             BTNodeDesigner _destinationNodeDesigner = nodeDesigner.mChildNodeConnectionList[i].mDestinationNodeDesigner;
             mDetachedNodes.Add(_destinationNodeDesigner);
             _destinationNodeDesigner.mParentNode = null;
         }
     }
     if (nodeDesigner.mParentNode != null)
     {
         nodeDesigner.mParentNode.DeleteChildNode(nodeDesigner);
     }
     mDetachedNodes.Remove(nodeDesigner);
     if (mRootNode != null && mRootNode.Equals(nodeDesigner))
     {
         mRootNode = null;
     }
 }
Beispiel #19
0
 //添加连线
 public void AddSelectNodeLine(BTNodeDesigner destNode)
 {
     if (mRootNode != null && mRootNode.Equals(destNode))
     {
         return;
     }
     if (mSelectedNodes != null && mSelectedNodes.Count == 1)
     {
         mSelectedNodes[0].AddChildNode(destNode);
     }
     if (mDetachedNodes != null)
     {
         for (int i = 0; i < mDetachedNodes.Count; i++)
         {
             if (mDetachedNodes[i].Equals(destNode))
             {
                 mDetachedNodes.RemoveAt(i);
             }
         }
     }
 }
Beispiel #20
0
        //添加节点
        public BTNodeDesigner AddNode(Type type, Vector2 position)
        {
            BTNode       _node       = (BTNode)type.GetConstructor(new Type[] { }).Invoke(new object[] { });
            BTEditorNode _editorNode = new BTEditorNode(_node);

            _editorNode.mPos = position;
            BTNodeDesigner _nodeDesigner = new BTNodeDesigner(_editorNode);

            if (mRootNode == null)
            {
                mRootNode = _nodeDesigner;
                _nodeDesigner.SetEntryDisplay(true);
            }
            else
            {
                if (mDetachedNodes == null)
                {
                    mDetachedNodes = new List <BTNodeDesigner>();
                }
                mDetachedNodes.Add(_nodeDesigner);
            }
            return(_nodeDesigner);
        }
Beispiel #21
0
 //选中
 public void Select(BTNodeDesigner nodeDesigner)
 {
     mSelectedNodes.Add(nodeDesigner);
     nodeDesigner.Select();
 }
Beispiel #22
0
 public BTNodeConnection(BTNodeDesigner _dest, BTNodeDesigner _orig, NodeConnectionType _type)
 {
     mDestinationNodeDesigner = _dest;
     mOriginatingNodeDesigner = _orig;
     NodeConnectionType       = _type;
 }
Beispiel #23
0
 //取消选中
 public void Deselect(BTNodeDesigner nodeDesigner)
 {
     mSelectedNodes.Remove(nodeDesigner);
     nodeDesigner.Deselect();
 }