예제 #1
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);
            }
        }
예제 #2
0
        void OnGUI()
        {
            if (m_cToolBarBtnStyle == null)
            {
                m_cToolBarBtnStyle = new GUIStyle((GUIStyle)"toolbarbutton");
            }

            if (m_cToolBarPopupStyle == null)
            {
                m_cToolBarPopupStyle = new GUIStyle((GUIStyle)"ToolbarPopup");
            }

            float centerAreaWidth = position.width - leftAreaWidth - rightAreaWidth;

            if (centerAreaWidth < 0)
            {
                centerAreaWidth = 0;
            }

            //画布整体描述区域
            Rect leftArea = new Rect(0, titleHeight, leftAreaWidth, position.height - titleHeight);

            GUILayout.BeginArea(leftArea);
            GUILayout.Label("总描述", m_cToolBarBtnStyle, GUILayout.Width(leftArea.width));
            leftScrollPos = GUILayout.BeginScrollView(leftScrollPos, false, true);
            if (m_cRoot != null)
            {
                float oldWidth = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 50;
                NEDataProperties.Draw(m_cRoot.dataProperty, GUILayout.Width(leftArea.width - 50));
                EditorGUIUtility.labelWidth = oldWidth;
            }
            GUILayout.EndScrollView();
            GUILayout.EndArea();

            //画布区域
            Rect centerArea = new Rect(leftArea.width, titleHeight, centerAreaWidth, position.height - titleHeight);

            GUILayout.BeginArea(centerArea);
            m_cCanvas.Draw(centerArea);
            GUILayout.EndArea();

            //单个节点描述区域
            Rect rightArea = new Rect(leftArea.width + centerAreaWidth, titleHeight, rightAreaWidth, position.height - titleHeight);

            GUILayout.BeginArea(rightArea);
            GUILayout.Label("节点描述", m_cToolBarBtnStyle, GUILayout.Width(rightArea.width));
            rightScrollPos = GUILayout.BeginScrollView(rightScrollPos, false, true);
            float oldLabelWidth = EditorGUIUtility.labelWidth;

            if (m_cCanvas.selectNode != null && m_cCanvas.selectNode.dataProperty != null)
            {
                if (!string.IsNullOrEmpty(m_cCanvas.selectNode.desc))
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("节点描述:");
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    bool oldWordWrap = EditorStyles.textArea.wordWrap;
                    EditorStyles.textArea.wordWrap = true;
                    GUILayout.TextArea(m_cCanvas.selectNode.desc, GUILayout.Width(rightArea.width - 40), GUILayout.Height(60));
                    EditorStyles.textArea.wordWrap = oldWordWrap;
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUIUtility.labelWidth = 50;
                NEDataProperties.Draw(m_cCanvas.selectNode.dataProperty, GUILayout.Width(rightArea.width - 50));
            }
            EditorGUIUtility.labelWidth = oldLabelWidth;
            GUILayout.EndScrollView();
            GUILayout.EndArea();

            //标题区域
            Rect titleRect = new Rect(0, 0, position.width, titleHeight);

            m_cToolBarBtnStyle.fixedHeight   = titleRect.height;
            m_cToolBarPopupStyle.fixedHeight = titleRect.height;
            GUILayout.BeginArea(titleRect);
            //GUILayout.Label("", tt,GUILayout.Width(50),GUILayout.Height(20));
            GUILayout.BeginHorizontal();
            GUILayout.Label("", m_cToolBarBtnStyle, GUILayout.Width(10));
            int oldTreeComposeIndex = m_nTreeComposeIndex;

            m_nTreeComposeIndex = EditorGUILayout.Popup(m_nTreeComposeIndex, m_arrComposeDesc, m_cToolBarPopupStyle, GUILayout.Width(100));
            if (oldTreeComposeIndex != m_nTreeComposeIndex)
            {
                Load(NEConfig.arrTreeComposeData[m_nTreeComposeIndex]);
            }
            GUILayout.Label("", m_cToolBarBtnStyle, GUILayout.Width(position.width - 10 - 100 - 50 - 50 - 50 - 10));
            if (GUILayout.Button("创建", m_cToolBarBtnStyle, GUILayout.Width(50)))
            {
                CreateTreeByTreeData(null);
            }
            if (GUILayout.Button("加载", m_cToolBarBtnStyle, GUILayout.Width(50)))
            {
                LoadTreeByTreeData();
            }
            if (GUILayout.Button("保存", m_cToolBarBtnStyle, GUILayout.Width(50)))
            {
                SaveTreeToTreeData();
            }
            GUILayout.Label("", m_cToolBarBtnStyle, GUILayout.Width(10));
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            if (GUI.changed)
            {
                Repaint();
            }
        }