Example #1
0
        /// <summary>
        /// Draws the node inspector.
        /// <param name="target">The node that is being inspected.</param>
        /// </summary>
        public void DrawNode(ActionNode target)
        {
            // Create style?
            if (s_Styles == null)
            {
                s_Styles = new NodeEditor.Styles();
            }

            if (target == null)
            {
                m_SerializedNode    = null;
                m_Target            = null;
                m_TargetContent     = GUIContent.none;
                m_TargetIconContent = GUIContent.none;
                m_TargetType        = string.Empty;
            }
            // The target node has changed?
            else if (m_SerializedNode == null || m_SerializedNode.target != target)
            {
                m_SerializedNode = new SerializedNode(target);
                m_Target         = target;

                Type targetType = m_Target.GetType();
                m_TargetType = " (" + targetType.Name + ")";
                var nodeInfo = AttributeUtility.GetAttribute <NodeInfoAttribute>(targetType, false) ?? new NodeInfoAttribute();
                m_TargetContent     = new GUIContent(target.name + m_TargetType, null, nodeInfo.description);
                m_TargetIconContent = new GUIContent(IconUtility.GetIcon(targetType));

                // Update Values
                m_SerializedNode.Update();
            }

            // The serialized node is not null?
            if (m_SerializedNode != null)
            {
                // Draw node title
                this.DrawTitle();

                if (m_Target != null && BehaviourWindow.IsVisible(m_Target.instanceID))
                {
                    // Draw node properties
                    this.OnInspectorGUI();

                    // Update target content?
                    if (Event.current.type == EventType.Used && m_Target != null)
                    {
                        m_TargetContent.text = m_Target.name + m_TargetType;
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Override this function to create your own custom title.
        /// </summary>
        public virtual void DrawTitle()
        {
            EditorGUI.BeginChangeCheck();

            // Get a rect for the title
            Rect position = GUILayoutUtility.GetRect(GUIContent.none, s_Styles.titlebar);

            // Get a control id for the title
            int controlID = GUIUtility.GetControlID(s_Styles.titleHash, EditorGUIUtility.native, position);

            GUIStyle titlebar      = s_Styles.titlebar;
            GUIStyle titlebarText  = s_Styles.titlebarText;
            Rect     rect          = new Rect(position.x + (float)titlebar.padding.left, position.y + (float)titlebar.padding.top, 16f, 16f);
            Rect     gearRect      = new Rect(position.xMax - (float)titlebar.padding.right - 2f - 16f, rect.y, 16f, 16f);
            Rect     referenceRect = gearRect;

            referenceRect.x -= 18f;

            Rect position2 = new Rect(rect.xMax + 2f + 2f + 16f, rect.y, 100f, rect.height);

            position2.xMax = referenceRect.xMin - 2f;

            // This node is visible?
            bool isVisible = BehaviourWindow.IsVisible(m_Target.instanceID);

            // Get the current event
            Event current = Event.current;

            if (current.type == EventType.Repaint)
            {
                GUIStyle.none.Draw(rect, m_TargetIconContent, controlID, isVisible);
                titlebarText.Draw(position2, m_TargetContent, controlID, isVisible);
                titlebarText.Draw(referenceRect, s_Styles.helpContent, controlID, isVisible);
                titlebarText.Draw(gearRect, s_Styles.popupContent, controlID, isVisible);
                titlebar.Draw(position, GUIContent.none, controlID, isVisible);
            }
            else if (current.type == EventType.MouseDown)
            {
                if (position.Contains(current.mousePosition))
                {
                    // Show online help?
                    if (referenceRect.Contains(current.mousePosition))
                    {
                        this.OpenNodeReference();
                        current.Use();
                    }
                    // Not left mouse button or clicked on the gear?
                    else if (current.button != 0 || gearRect.Contains(current.mousePosition))
                    {
                        // Show context menu
                        this.ShowNodeContextMenu();
                        current.Use();
                    }
                    // Foldout focus
                    else
                    {
                        GUIUtility.hotControl      = controlID;
                        GUIUtility.keyboardControl = controlID;
                        current.Use();
                    }
                }
            }
            // Foldout logic; toggle the value of isVisible
            else if (current.type == EventType.MouseUp)
            {
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;

                    BehaviourWindow.SetVisible(m_Target.instanceID, !isVisible);

                    current.Use();
                }
            }

            EditorGUI.EndChangeCheck();
        }