IconButton() static private method

static private IconButton ( int id, GUIContent content, GUIStyle style ) : bool
id int
content UnityEngine.GUIContent
style UnityEngine.GUIStyle
return bool
示例#1
0
        private void DoButton(GUIContent content, Texture2D selectedIcon, bool labelIcon)
        {
            int controlID = GUIUtility.GetControlID(s_HashIconSelector, FocusType.Keyboard);

            if (content.image == selectedIcon)
            {
                Rect  position = GUILayoutUtility.topLevel.PeekNext();
                float num2     = 2f;
                position.x     -= num2;
                position.y     -= num2;
                position.width  = selectedIcon.width + (2f * num2);
                position.height = selectedIcon.height + (2f * num2);
                GUI.Label(position, GUIContent.none, !labelIcon ? m_Styles.selection : m_Styles.selectionLabel);
            }
            if (EditorGUILayout.IconButton(controlID, content, GUIStyle.none, new GUILayoutOption[0]))
            {
                Texture2D icon = this.ConvertSmallIconToLargeIcon((Texture2D)content.image, labelIcon);
                EditorGUIUtility.SetIconForObject(this.m_TargetObject, icon);
                EditorUtility.ForceReloadInspectors();
                AnnotationWindow.IconChanged();
                if (Event.current.clickCount == 2)
                {
                    this.CloseWindow();
                }
            }
        }
示例#2
0
        private void DoButton(GUIContent content, Texture2D selectedIcon, bool labelIcon)
        {
            int controlId = GUIUtility.GetControlID(IconSelector.s_HashIconSelector, FocusType.Keyboard);

            if ((UnityEngine.Object)content.image == (UnityEngine.Object)selectedIcon)
            {
                Rect  position = GUILayoutUtility.topLevel.PeekNext();
                float num      = 2f;
                position.x     -= num;
                position.y     -= num;
                position.width  = (float)selectedIcon.width + 2f * num;
                position.height = (float)selectedIcon.height + 2f * num;
                GUI.Label(position, GUIContent.none, !labelIcon ? IconSelector.m_Styles.selection : IconSelector.m_Styles.selectionLabel);
            }
            if (!EditorGUILayout.IconButton(controlId, content, GUIStyle.none))
            {
                return;
            }
            EditorGUIUtility.SetIconForObject(this.m_TargetObject, this.ConvertSmallIconToLargeIcon((Texture2D)content.image, labelIcon));
            EditorUtility.ForceReloadInspectors();
            AnnotationWindow.IconChanged();
            if (Event.current.clickCount != 2)
            {
                return;
            }
            this.CloseWindow();
        }
示例#3
0
        void DoButton(GUIContent content, Texture2D selectedIcon, bool labelIcon)
        {
            int controlID = GUIUtility.GetControlID(s_HashIconSelector, FocusType.Keyboard);

            // Draw selection background if this is the selected icon
            if (content.image == selectedIcon)
            {
                // When placing our selection background we assume that icons rendered from top left corner
                Rect  rect = GUILayoutUtility.topLevel.PeekNext();
                float pad  = 2;
                rect.x     -= pad;
                rect.y     -= pad;
                rect.width  = selectedIcon.width + 2 * pad;
                rect.height = selectedIcon.height + 2 * pad;
                GUI.Label(rect, GUIContent.none, labelIcon ? m_Styles.selectionLabel : m_Styles.selection);
            }

            // Do icon
            if (EditorGUILayout.IconButton(controlID, content, GUIStyle.none))
            {
                // Map to new icon
                Texture2D largeIcon = ConvertSmallIconToLargeIcon((Texture2D)content.image, labelIcon);
                SetIconForSelectedObjects(largeIcon);

                // Close on double click
                if (Event.current.clickCount == 2)
                {
                    CloseWindow();
                }
            }
        }
示例#4
0
        void DoButton(GUIContent content, Texture2D selectedIcon, bool labelIcon)
        {
            int controlID = GUIUtility.GetControlID(s_HashIconSelector, FocusType.Keyboard);

            // Draw selection background if this is the selected icon
            if (content.image == selectedIcon)
            {
                // When placing our selection background we assume that icons rendered from top left corner
                Rect  rect = GUILayoutUtility.topLevel.PeekNext();
                float pad  = 2;
                rect.x     -= pad;
                rect.y     -= pad;
                rect.width  = selectedIcon.width + 2 * pad;
                rect.height = selectedIcon.height + 2 * pad;
                GUI.Label(rect, GUIContent.none, labelIcon ? m_Styles.selectionLabel : m_Styles.selection);
            }

            // Do icon
            if (EditorGUILayout.IconButton(controlID, content, GUIStyle.none))
            {
                // Map to new icon
                Texture2D largeIcon = ConvertSmallIconToLargeIcon((Texture2D)content.image, labelIcon);
                Undo.RecordObject(m_TargetObject, "Set Icon On GameObject");
                EditorGUIUtility.SetIconForObject(m_TargetObject, largeIcon);

                // We assume that we are setting icon in an inspector or annotation window (todo: make repaint delegate)
                EditorUtility.ForceReloadInspectors();
                AnnotationWindow.IconChanged();

                // Close on double click
                if (Event.current.clickCount == 2)
                {
                    CloseWindow();
                }
            }
        }