Exemple #1
0
 private void HandleNodeMenu(NENode node, Vector2 mousePosition)
 {
     GUI.changed = true;
     //GenericMenu menu = new GenericMenu();
     //menu.AddItem(new GUIContent("删除节点"), false, () => { m_lstNode.Remove(node); });
     //menu.ShowAsContext();
 }
Exemple #2
0
        public NENode CreateNode(Vector2 pos, object data)
        {
            NENode node = new NENode(pos, data);

            m_lstNode.Add(node);
            return(node);
        }
 public NENodePoint(NENode node, NENodePointType pointType)
 {
     this.node      = node;
     this.pointType = pointType;
     this.rect      = new Rect(0, 0, 40, 16);
     m_cBtnStyle    = null;
 }
Exemple #4
0
 public NEConnection CreateConnect(NENode beginNode, NENode endNode)
 {
     if (beginNode.outPoint != null && endNode.inPoint != null)
     {
         NEConnection connection = new NEConnection(endNode.inPoint, beginNode.outPoint);
         m_lstConnection.Add(connection);
         return(connection);
     }
     return(null);
 }
Exemple #5
0
        private NENode GetNodeByPosition(Vector2 pos)
        {
            NENode selectNode = null;

            for (int i = 0; i < m_lstNode.Count; i++)
            {
                if (m_lstNode[i].rect.Contains(pos))
                {
                    selectNode = m_lstNode[i];
                    break;
                }
            }
            return(selectNode);
        }
Exemple #6
0
        //按照位置排序
        private int NodeSort(NENode a, NENode b)
        {
            int res = 0;

            if (a.rect.center.x - b.rect.center.x > 0)
            {
                res = 1;
            }
            else if (a.rect.center.x - b.rect.center.x < 0)
            {
                res = -1;
            }
            return(res);
        }
Exemple #7
0
 private void SelectNode(NENode node)
 {
     for (int i = 0; i < m_lstNode.Count; i++)
     {
         if (m_lstNode[i] == node)
         {
             m_lstNode[i].SetSelected(true);
         }
         else
         {
             if (m_lstNode[i].isSelected)
             {
                 m_lstNode[i].SetSelected(false);
             }
         }
     }
     m_cSelectedNode = node;
 }
Exemple #8
0
 private void OnClickNodeRemove(NENode node)
 {
     if (m_cDragNode == node)
     {
         m_cDragNode = null;
     }
     if (m_cSelectedNode == node)
     {
         m_cSelectedNode = null;
     }
     m_lstNode.Remove(node);
     for (int i = m_lstConnection.Count - 1; i > -1; i--)
     {
         if (m_lstConnection[i].inPoint.node == node || m_lstConnection[i].outPoint.node == node)
         {
             m_lstConnection.RemoveAt(i);
         }
     }
     GUI.changed = true;
 }
Exemple #9
0
        private NENode CreateNENode(NEData neData)
        {
            if (neData.data == null)
            {
                Debug.LogError("neData.data == null");
                return(null);
            }
            object neNode     = CreateNENodeByData(neData.data);
            NENode parentNode = m_cCanvas.CreateNode(neData.editorPos, neNode);

            if (neData.lstChild != null)
            {
                for (int i = 0; i < neData.lstChild.Count; i++)
                {
                    NENode       childNode  = CreateNENode(neData.lstChild[i]);
                    NEConnection connection = m_cCanvas.CreateConnect(parentNode, childNode);
                }
            }
            return(parentNode);
        }
Exemple #10
0
        private NEData GetNodeNEData(NENode node, List <NEConnection> lst, List <NENode> handNodes)
        {
            if (handNodes.Contains(node))
            {
                Debug.LogError("树的连线进入死循环,节点=" + node.node.GetType());
                return(null);
            }
            handNodes.Add(node);

            INENode neNode = node.node as INENode;
            NEData  neData = new NEData();

            neData.data      = neNode.data;
            neData.editorPos = node.rect.center;

            List <NENode> lstSubNode = new List <NENode>();

            for (int i = 0; i < lst.Count; i++)
            {
                NEConnection connection = lst[i];
                if (connection.outPoint.node == node)
                {
                    NENode childNode = connection.inPoint.node;
                    lstSubNode.Add(childNode);
                }
            }
            lstSubNode.Sort(NodeSort);
            for (int i = 0; i < lstSubNode.Count; i++)
            {
                NENode childNode   = lstSubNode[i];
                NEData childNEData = GetNodeNEData(childNode, lst, handNodes);
                if (neData.lstChild == null)
                {
                    neData.lstChild = new List <NEData>();
                }
                neData.lstChild.Add(childNEData);
            }

            return(neData);
        }
Exemple #11
0
        private void Load(NETreeComposeType conposeType)
        {
            NEData neData = null;

            if (m_cRoot != null)
            {
                foreach (var item in NEConfig.arrTreeComposeData)
                {
                    if (item.rootType == m_cRoot.node.GetType())
                    {
                        if (item == conposeType)
                        {
                            neData = GetCurrentTreeNEData();
                        }
                        break;
                    }
                }
                m_cRoot = null;
            }
            NEUtil.LoadTreeComposeTypes(conposeType, out m_lstNodeType, out m_lstNodeDataType);

            //移除根节点
            List <Type> lst = new List <Type>();

            for (int i = 0; i < m_lstNodeType.Count; i++)
            {
                if (!IsRootType(m_lstNodeType[i]))
                {
                    lst.Add(m_lstNodeType[i]);
                }
            }
            if (m_cCanvas != null)
            {
                m_cCanvas.Dispose();
            }
            m_cCanvas = new NECanvas(lst, CreateNENodeByNENodeType);
            CreateTreeByTreeData(neData);
        }
Exemple #12
0
        private NENode CreateTreeByTreeData(NEData neData)
        {
            if (m_cCanvas != null)
            {
                m_cCanvas.Clear();
            }
            NENode node = null;

            if (neData == null)
            {
                var     composeData = NEConfig.arrTreeComposeData[m_nTreeComposeIndex];
                object  data        = CreateNENodeByNENodeType(composeData.rootType);
                Vector2 center      = m_cCanvas.scrollViewRect.center;
                node = m_cCanvas.CreateNode(center, data);
            }
            else
            {
                node = CreateNENode(neData);
            }
            m_cRoot = node;
            FocusCanvasCenterPosition();
            return(node);
        }
Exemple #13
0
 public NECanvas(List <Type> lstNodeType, Func <Type, object> createNodeDataFunc)
 {
     m_fCreateNodeFunc = createNodeDataFunc;
     m_dicNodeType     = new Dictionary <string, List <Type> >();
     if (lstNodeType != null)
     {
         for (int i = 0; i < lstNodeType.Count; i++)
         {
             List <Type> lst        = null;
             var         attributes = lstNodeType[i].GetCustomAttributes(typeof(NENodeCategoryAttribute), true);
             if (attributes.Length > 0)
             {
                 string category = ((NENodeCategoryAttribute)attributes[0]).category;
                 if (!m_dicNodeType.TryGetValue(category, out lst))
                 {
                     lst = new List <Type>();
                     m_dicNodeType.Add(category, lst);
                 }
             }
             else
             {
                 if (!m_dicNodeType.TryGetValue("", out lst))
                 {
                     lst = new List <Type>();
                     m_dicNodeType.Add("", lst);
                 }
             }
             lst.Add(lstNodeType[i]);
         }
     }
     scrollPos       = new Vector2(scrollViewRect.width / 2f, scrollViewRect.height / 2f);
     m_cSelectedNode = null;
     m_cDragNode     = null;
     m_cInNodePoint  = null;
     m_cOutNodePoint = null;
 }
Exemple #14
0
        private void HandleEvent(Event e)
        {
            Rect rect       = new Rect(scrollPos.x, scrollPos.y, m_sPosition.width, m_sPosition.height);
            bool isInWindow = rect.Contains(e.mousePosition);

            //左键按下
            if (e.button == 0)
            {
                switch (e.type)
                {
                case EventType.MouseDown:
                    if (isInWindow)
                    {
                        NENode selectNode = GetNodeByPosition(e.mousePosition);
                        if (selectNode != m_cSelectedNode)
                        {
                            SelectNode(selectNode);
                            GUI.changed = true;
                        }
                        m_cDragNode = selectNode;
                        e.Use();
                    }
                    break;

                case EventType.MouseUp:
                    m_cDragNode = null;
                    break;

                case EventType.MouseDrag:
                    if (isInWindow && null != m_cDragNode)
                    {
                        //m_cDragNode.MovePosition(e.delta);
                        m_cDragNode.SetPosition(e.mousePosition);
                        e.Use();
                        GUI.changed = true;
                    }
                    break;
                }
            }
            //右键按下
            else if (e.button == 1)
            {
                if (m_cInNodePoint != null || m_cOutNodePoint != null)
                {
                    ClearNodePoints();
                    GUI.changed = true;
                    e.Use();
                }
                else if (isInWindow)
                {
                    NENode selectNode = GetNodeByPosition(e.mousePosition);
                    if (selectNode != null)
                    {
                        HandleNodeMenu(selectNode, e.mousePosition);
                        e.Use();
                    }
                    else
                    {
                        HandleBlankMenu(e.mousePosition);
                        e.Use();
                    }
                }
            }
        }