Ejemplo n.º 1
0
 private void OnClickNodePoint(NENodePoint nodePoint)
 {
     if (m_cInNodePoint != null)
     {
         if (m_cInNodePoint.node != nodePoint.node && nodePoint.pointType == NENodePointType.Out)
         {
             m_cOutNodePoint = nodePoint;
             CreateConnection(m_cInNodePoint, m_cOutNodePoint);
             ClearNodePoints();
         }
     }
     else if (m_cOutNodePoint != null)
     {
         if (m_cOutNodePoint.node != nodePoint.node && nodePoint.pointType == NENodePointType.In)
         {
             m_cInNodePoint = nodePoint;
             CreateConnection(m_cInNodePoint, m_cOutNodePoint);
             ClearNodePoints();
         }
     }
     else
     {
         if (nodePoint.pointType == NENodePointType.In)
         {
             m_cInNodePoint = nodePoint;
         }
         else
         {
             m_cOutNodePoint = nodePoint;
         }
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
        public NENode(Vector2 position, object node)
        {
            this.node      = node;
            m_cNormalStyle = null;
            m_cSelectStyle = null;
            m_cCloseStyle  = null;
            m_cImg         = null;

            m_sName         = "";
            desc            = "";
            m_bShowInPoint  = true;
            m_bShowOutPoint = true;
            m_bShowClose    = true;
            if (this.node != null)
            {
                var type = this.node.GetType();
                m_sName = NENodeNameAttribute.GetName(type);
                desc    = NENodeDescAttribute.GetDesc(type);
                var    attributes = type.GetCustomAttributes(typeof(NENodeDataAttribute), true);
                object nodeData   = null;
                if (attributes.Length > 0)
                {
                    nodeData = this.node;
                }
                else
                {
                    var fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                    foreach (var item in fieldInfos)
                    {
                        if (item.GetCustomAttributes(typeof(NENodeDataAttribute), true).Length > 0)
                        {
                            nodeData = item.GetValue(this.node);
                            break;
                        }
                    }
                }
                if (nodeData != null)
                {
                    dataProperty = NEDataProperties.GetProperties(nodeData);
                }

                attributes = type.GetCustomAttributes(typeof(NENodeDisplayAttribute), true);
                if (attributes.Length > 0)
                {
                    NENodeDisplayAttribute displayAttribute = attributes[0] as NENodeDisplayAttribute;
                    m_bShowInPoint  = displayAttribute.showInPoint;
                    m_bShowOutPoint = displayAttribute.showOutPoint;
                    m_bShowClose    = displayAttribute.showClose;
                }
            }
            m_cStyle                         = m_cNormalStyle;
            m_cContentStyle                  = new GUIStyle();
            m_cContentStyle.fontSize         = 14;
            m_cContentStyle.normal.textColor = Color.white;
            m_cContentStyle.alignment        = TextAnchor.MiddleCenter;
            m_cExtendStyle                   = new GUIStyle();
            m_cExtendStyle.fontSize          = 10;
            m_cExtendStyle.normal.textColor  = Color.white;
            m_cExtendStyle.alignment         = TextAnchor.MiddleCenter;

            float width    = 100;
            float height   = 70;
            var   descSize = m_cContentStyle.CalcSize(new GUIContent(m_sName));

            width      = Mathf.Max(descSize.x, width);
            normalSize = new Vector2(width, height);

            extendSize = Vector2.zero;
            m_lstShowOnNodeProperty = new List <NEDataProperty>();
            if (dataProperty != null)
            {
                for (int i = 0; i < dataProperty.Length; i++)
                {
                    if (dataProperty[i].showOnNode)
                    {
                        var extSize = m_cExtendStyle.CalcSize(new GUIContent(dataProperty[i].Name + ":" + dataProperty[i].GetValue().ToString()));
                        if (extSize.x > extendSize.x)
                        {
                            extendSize.x = extSize.x;
                        }
                        extendSize.y += extSize.y;
                        m_lstShowOnNodeProperty.Add(dataProperty[i]);
                    }
                }
            }
            if (extendSize.y > 0)
            {
                extendSize.y += 10;
            }
            float rectWidth  = Mathf.Max(normalSize.x, extendSize.x) + 10;
            float rectHeight = normalSize.y + extendSize.y;

            rect = new Rect(position.x - width / 2, position.y - height / 2, rectWidth, rectHeight);

            if (m_bShowInPoint)
            {
                m_cInPoint = new NENodePoint(this, NENodePointType.In);
            }
            if (m_bShowOutPoint)
            {
                m_cOutPoint = new NENodePoint(this, NENodePointType.Out);
            }
        }
Ejemplo n.º 4
0
        private void CreateConnection(NENodePoint inPoint, NENodePoint outPoint)
        {
            NEConnection connection = new NEConnection(inPoint, outPoint);

            m_lstConnection.Add(connection);
        }
Ejemplo n.º 5
0
 private void ClearNodePoints()
 {
     m_cOutNodePoint = null;
     m_cInNodePoint  = null;
 }
Ejemplo n.º 6
0
 public NEConnection(NENodePoint inPoint, NENodePoint outPoint)
 {
     this.inPoint  = inPoint;
     this.outPoint = outPoint;
 }