Пример #1
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();
        }
Пример #2
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();
                }
            }
        }
Пример #3
0
 private void DoTopSection(bool anySelected)
 {
     GUI.Label(new Rect(6f, 4f, 110f, 20f), "Select Icon");
     EditorGUI.BeginDisabledGroup(!anySelected);
     if (GUI.Button(new Rect(93f, 6f, 43f, 12f), this.m_NoneButtonContent, IconSelector.m_Styles.noneButton))
     {
         EditorGUIUtility.SetIconForObject(this.m_TargetObject, (Texture2D)null);
         EditorUtility.ForceReloadInspectors();
         AnnotationWindow.IconChanged();
     }
     EditorGUI.EndDisabledGroup();
 }
Пример #4
0
        void SetIconForSelectedObjects(Texture2D icon)
        {
            Undo.RecordObjects(m_TargetObjectList, "Set Icon On GameObject");

            foreach (var target in m_TargetObjectList)
            {
                EditorGUIUtility.SetIconForObject(target, icon);
            }
            SetMultipleSelectedIcons();
            EditorUtility.ForceReloadInspectors();
            AnnotationWindow.IconChanged();
        }
Пример #5
0
        private void DoTopSection(bool anySelected)
        {
            Rect position = new Rect(6f, 4f, 110f, 20f);

            GUI.Label(position, "Select Icon");
            using (new EditorGUI.DisabledScope(!anySelected))
            {
                Rect rect2 = new Rect(93f, 6f, 43f, 12f);
                if (GUI.Button(rect2, this.m_NoneButtonContent, m_Styles.noneButton))
                {
                    EditorGUIUtility.SetIconForObject(this.m_TargetObject, null);
                    EditorUtility.ForceReloadInspectors();
                    AnnotationWindow.IconChanged();
                }
            }
        }
Пример #6
0
        void DoTopSection(bool anySelected)
        {
            Rect selectIconRect = new Rect(6, 4, 110, 20);

            GUI.Label(selectIconRect, "Select Icon");

            // Draw selection background if none is selected
            using (new EditorGUI.DisabledScope(!anySelected))
            {
                Rect noneButtonRect = new Rect(93, 6, 43, 12);
                if (GUI.Button(noneButtonRect, m_NoneButtonContent, m_Styles.noneButton))
                {
                    EditorGUIUtility.SetIconForObject(m_TargetObject, null);
                    EditorUtility.ForceReloadInspectors();
                    AnnotationWindow.IconChanged();
                }
            }
        }
Пример #7
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();
                }
            }
        }
Пример #8
0
        internal void OnGUI()
        {
            if (m_Styles == null)
            {
                m_Styles = new Styles();
            }
            if ((Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape))
            {
                this.CloseWindow();
            }
            Texture2D iconForObject = EditorGUIUtility.GetIconForObject(this.m_TargetObject);
            bool      isLabelIcon   = false;

            if (Event.current.type == EventType.Repaint)
            {
                iconForObject = this.ConvertLargeIconToSmallIcon(iconForObject, ref isLabelIcon);
            }
            Event     current = Event.current;
            EventType type    = current.type;

            GUI.BeginGroup(new Rect(0f, 0f, base.position.width, base.position.height), m_Styles.background);
            this.DoTopSection(iconForObject != null);
            GUILayout.Space(22f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(1f);
            GUI.enabled = false;
            GUILayout.Label("", m_Styles.seperator, new GUILayoutOption[0]);
            GUI.enabled = true;
            GUILayout.Space(1f);
            GUILayout.EndHorizontal();
            GUILayout.Space(3f);
            if (this.m_ShowLabelIcons)
            {
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(6f);
                for (int k = 0; k < (this.m_LabelIcons.Length / 2); k++)
                {
                    this.DoButton(this.m_LabelIcons[k], iconForObject, true);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(5f);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(6f);
                for (int m = this.m_LabelIcons.Length / 2; m < this.m_LabelIcons.Length; m++)
                {
                    this.DoButton(this.m_LabelIcons[m], iconForObject, true);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(3f);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(1f);
                GUI.enabled = false;
                GUILayout.Label("", m_Styles.seperator, new GUILayoutOption[0]);
                GUI.enabled = true;
                GUILayout.Space(1f);
                GUILayout.EndHorizontal();
                GUILayout.Space(3f);
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(9f);
            for (int i = 0; i < (this.m_SmallIcons.Length / 2); i++)
            {
                this.DoButton(this.m_SmallIcons[i], iconForObject, false);
            }
            GUILayout.Space(3f);
            GUILayout.EndHorizontal();
            GUILayout.Space(6f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(9f);
            for (int j = this.m_SmallIcons.Length / 2; j < this.m_SmallIcons.Length; j++)
            {
                this.DoButton(this.m_SmallIcons[j], iconForObject, false);
            }
            GUILayout.Space(3f);
            GUILayout.EndHorizontal();
            GUILayout.Space(6f);
            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.7f);
            bool flag2     = false;
            int  controlID = GUIUtility.GetControlID(s_HashIconSelector, FocusType.Keyboard);

            if (GUILayout.Button(EditorGUIUtility.TempContent("Other..."), new GUILayoutOption[0]))
            {
                GUIUtility.keyboardControl = controlID;
                flag2 = true;
            }
            GUI.backgroundColor = new Color(1f, 1f, 1f, 1f);
            GUI.EndGroup();
            if (flag2)
            {
                ObjectSelector.get.Show(this.m_TargetObject, typeof(Texture2D), null, false);
                ObjectSelector.get.objectSelectorID = controlID;
                GUI.backgroundColor = new Color(1f, 1f, 1f, 0.7f);
                current.Use();
                GUIUtility.ExitGUI();
            }
            if ((type == EventType.ExecuteCommand) && (((current.commandName == "ObjectSelectorUpdated") && (ObjectSelector.get.objectSelectorID == controlID)) && (GUIUtility.keyboardControl == controlID)))
            {
                Texture2D currentObject = ObjectSelector.GetCurrentObject() as Texture2D;
                EditorGUIUtility.SetIconForObject(this.m_TargetObject, currentObject);
                GUI.changed = true;
                current.Use();
            }
        }
Пример #9
0
        internal void OnGUI()
        {
            if (IconSelector.m_Styles == null)
            {
                IconSelector.m_Styles = new IconSelector.Styles();
            }
            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                this.CloseWindow();
            }
            Texture2D texture2D = EditorGUIUtility.GetIconForObject(this.m_TargetObject);
            bool      flag      = false;

            if (Event.current.type == EventType.Repaint)
            {
                texture2D = this.ConvertLargeIconToSmallIcon(texture2D, ref flag);
            }
            Event     current = Event.current;
            EventType type    = current.type;

            GUI.BeginGroup(new Rect(0f, 0f, base.position.width, base.position.height), IconSelector.m_Styles.background);
            this.DoTopSection(texture2D != null);
            GUILayout.Space(22f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(1f);
            GUI.enabled = false;
            GUILayout.Label("", IconSelector.m_Styles.seperator, new GUILayoutOption[0]);
            GUI.enabled = true;
            GUILayout.Space(1f);
            GUILayout.EndHorizontal();
            GUILayout.Space(3f);
            if (this.m_ShowLabelIcons)
            {
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(6f);
                for (int i = 0; i < this.m_LabelIcons.Length / 2; i++)
                {
                    this.DoButton(this.m_LabelIcons[i], texture2D, true);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(5f);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(6f);
                for (int j = this.m_LabelIcons.Length / 2; j < this.m_LabelIcons.Length; j++)
                {
                    this.DoButton(this.m_LabelIcons[j], texture2D, true);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(3f);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(1f);
                GUI.enabled = false;
                GUILayout.Label("", IconSelector.m_Styles.seperator, new GUILayoutOption[0]);
                GUI.enabled = true;
                GUILayout.Space(1f);
                GUILayout.EndHorizontal();
                GUILayout.Space(3f);
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(9f);
            for (int k = 0; k < this.m_SmallIcons.Length / 2; k++)
            {
                this.DoButton(this.m_SmallIcons[k], texture2D, false);
            }
            GUILayout.Space(3f);
            GUILayout.EndHorizontal();
            GUILayout.Space(6f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(9f);
            for (int l = this.m_SmallIcons.Length / 2; l < this.m_SmallIcons.Length; l++)
            {
                this.DoButton(this.m_SmallIcons[l], texture2D, false);
            }
            GUILayout.Space(3f);
            GUILayout.EndHorizontal();
            GUILayout.Space(6f);
            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.7f);
            bool flag2     = false;
            int  controlID = GUIUtility.GetControlID(IconSelector.s_HashIconSelector, FocusType.Keyboard);

            if (GUILayout.Button(EditorGUIUtility.TempContent("Other..."), new GUILayoutOption[0]))
            {
                GUIUtility.keyboardControl = controlID;
                flag2 = true;
            }
            GUI.backgroundColor = new Color(1f, 1f, 1f, 1f);
            GUI.EndGroup();
            if (flag2)
            {
                ObjectSelector.get.Show(this.m_TargetObject, typeof(Texture2D), null, false);
                ObjectSelector.get.objectSelectorID = controlID;
                GUI.backgroundColor = new Color(1f, 1f, 1f, 0.7f);
                current.Use();
                GUIUtility.ExitGUI();
            }
            if (type == EventType.ExecuteCommand)
            {
                string commandName = current.commandName;
                if (commandName == "ObjectSelectorUpdated" && ObjectSelector.get.objectSelectorID == controlID && GUIUtility.keyboardControl == controlID)
                {
                    Texture2D icon = ObjectSelector.GetCurrentObject() as Texture2D;
                    Undo.RecordObject(this.m_TargetObject, "Set Icon On GameObject");
                    EditorGUIUtility.SetIconForObject(this.m_TargetObject, icon);
                    GUI.changed = true;
                    current.Use();
                }
            }
        }
Пример #10
0
        internal void OnGUI()
        {
            // Here due to static vars being thrown out when reloading assemblies
            if (m_Styles == null)
            {
                m_Styles = new Styles();
            }

            // Escape pressed?
            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                CloseWindow();
            }

            Texture2D selectedIcon          = EditorGUIUtility.GetIconForObject(m_TargetObject);
            bool      isSelectionALabelIcon = false;

            if (Event.current.type == EventType.Repaint)
            {
                selectedIcon = ConvertLargeIconToSmallIcon(selectedIcon, ref isSelectionALabelIcon);
            }

            Event     evt       = Event.current;
            EventType eventType = evt.type;

            GUI.BeginGroup(new Rect(0, 0, position.width, position.height), m_Styles.background);

            DoTopSection(selectedIcon != null);

            GUILayout.Space(22);
            GUILayout.BeginHorizontal();
            GUILayout.Space(1);
            GUI.enabled = false;
            GUILayout.Label("", m_Styles.seperator);
            GUI.enabled = true;
            GUILayout.Space(1);
            GUILayout.EndHorizontal();
            GUILayout.Space(3);

            if (m_ShowLabelIcons)
            {
                // Label icons
                GUILayout.BeginHorizontal();
                GUILayout.Space(6);
                for (int i = 0; i < m_LabelIcons.Length / 2; ++i)
                {
                    DoButton(m_LabelIcons[i], selectedIcon, true);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(5);

                GUILayout.BeginHorizontal();
                GUILayout.Space(6);
                for (int i = m_LabelIcons.Length / 2; i < m_LabelIcons.Length; ++i)
                {
                    DoButton(m_LabelIcons[i], selectedIcon, true);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(3);
                GUILayout.BeginHorizontal();
                GUILayout.Space(1);
                GUI.enabled = false;
                GUILayout.Label("", m_Styles.seperator);
                GUI.enabled = true;
                GUILayout.Space(1);
                GUILayout.EndHorizontal();
                GUILayout.Space(3);
            }

            // Small icons
            GUILayout.BeginHorizontal();
            GUILayout.Space(9);
            for (int i = 0; i < m_SmallIcons.Length / 2; ++i)
            {
                DoButton(m_SmallIcons[i], selectedIcon, false);
            }
            GUILayout.Space(3);
            GUILayout.EndHorizontal();

            GUILayout.Space(6);

            GUILayout.BeginHorizontal();
            GUILayout.Space(9);
            for (int i = m_SmallIcons.Length / 2; i < m_SmallIcons.Length; ++i)
            {
                DoButton(m_SmallIcons[i], selectedIcon, false);
            }
            GUILayout.Space(3);
            GUILayout.EndHorizontal();
            GUILayout.Space(6);

            // Object selector section
            GUI.backgroundColor = new Color(1, 1, 1, 0.7f);
            bool clicked = false;
            int  id      = GUIUtility.GetControlID(s_HashIconSelector, FocusType.Keyboard);

            if (GUILayout.Button(s_Other))
            {
                GUIUtility.keyboardControl = id;
                clicked = true;
            }
            GUI.backgroundColor = new Color(1, 1, 1, 1);
            GUI.EndGroup();

            if (clicked)
            {
                ObjectSelector.get.Show(m_TargetObject, typeof(Texture2D), null, false);
                ObjectSelector.get.objectSelectorID = id;
                GUI.backgroundColor = new Color(1, 1, 1, 0.7f);
                evt.Use();
                GUIUtility.ExitGUI();
            }

            // Check for icon selected from ObjectSelector
            switch (eventType)
            {
            case EventType.ExecuteCommand:
                string commandName = evt.commandName;
                if (commandName == ObjectSelector.ObjectSelectorUpdatedCommand && ObjectSelector.get.objectSelectorID == id && GUIUtility.keyboardControl == id)
                {
                    Texture2D icon = ObjectSelector.GetCurrentObject() as Texture2D;
                    Undo.RecordObject(m_TargetObject, "Set Icon On GameObject");
                    EditorGUIUtility.SetIconForObject(m_TargetObject, icon);

                    GUI.changed = true;
                    evt.Use();
                }
                break;
            }
        }
Пример #11
0
        internal void OnGUI()
        {
            if (IconSelector.m_Styles == null)
            {
                IconSelector.m_Styles = new IconSelector.Styles();
            }
            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                this.CloseWindow();
            }
            Texture2D texture2D   = EditorGUIUtility.GetIconForObject(this.m_TargetObject);
            bool      isLabelIcon = false;

            if (Event.current.type == EventType.Repaint)
            {
                texture2D = this.ConvertLargeIconToSmallIcon(texture2D, ref isLabelIcon);
            }
            Event     current = Event.current;
            EventType type    = current.type;

            GUI.BeginGroup(new Rect(0.0f, 0.0f, this.position.width, this.position.height), IconSelector.m_Styles.background);
            this.DoTopSection((UnityEngine.Object)texture2D != (UnityEngine.Object)null);
            GUILayout.Space(22f);
            GUILayout.BeginHorizontal();
            GUILayout.Space(1f);
            GUI.enabled = false;
            GUILayout.Label(string.Empty, IconSelector.m_Styles.seperator, new GUILayoutOption[0]);
            GUI.enabled = true;
            GUILayout.Space(1f);
            GUILayout.EndHorizontal();
            GUILayout.Space(3f);
            if (this.m_ShowLabelIcons)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(6f);
                for (int index = 0; index < this.m_LabelIcons.Length / 2; ++index)
                {
                    this.DoButton(this.m_LabelIcons[index], texture2D, true);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(5f);
                GUILayout.BeginHorizontal();
                GUILayout.Space(6f);
                for (int index = this.m_LabelIcons.Length / 2; index < this.m_LabelIcons.Length; ++index)
                {
                    this.DoButton(this.m_LabelIcons[index], texture2D, true);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(3f);
                GUILayout.BeginHorizontal();
                GUILayout.Space(1f);
                GUI.enabled = false;
                GUILayout.Label(string.Empty, IconSelector.m_Styles.seperator, new GUILayoutOption[0]);
                GUI.enabled = true;
                GUILayout.Space(1f);
                GUILayout.EndHorizontal();
                GUILayout.Space(3f);
            }
            GUILayout.BeginHorizontal();
            GUILayout.Space(9f);
            for (int index = 0; index < this.m_SmallIcons.Length / 2; ++index)
            {
                this.DoButton(this.m_SmallIcons[index], texture2D, false);
            }
            GUILayout.Space(3f);
            GUILayout.EndHorizontal();
            GUILayout.Space(6f);
            GUILayout.BeginHorizontal();
            GUILayout.Space(9f);
            for (int index = this.m_SmallIcons.Length / 2; index < this.m_SmallIcons.Length; ++index)
            {
                this.DoButton(this.m_SmallIcons[index], texture2D, false);
            }
            GUILayout.Space(3f);
            GUILayout.EndHorizontal();
            GUILayout.Space(6f);
            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.7f);
            bool flag      = false;
            int  controlId = GUIUtility.GetControlID(IconSelector.s_HashIconSelector, FocusType.Keyboard);

            if (GUILayout.Button(EditorGUIUtility.TempContent("Other...")))
            {
                GUIUtility.keyboardControl = controlId;
                flag = true;
            }
            GUI.backgroundColor = new Color(1f, 1f, 1f, 1f);
            GUI.EndGroup();
            if (flag)
            {
                ObjectSelector.get.Show(this.m_TargetObject, typeof(Texture2D), (SerializedProperty)null, false);
                ObjectSelector.get.objectSelectorID = controlId;
                GUI.backgroundColor = new Color(1f, 1f, 1f, 0.7f);
                current.Use();
                GUIUtility.ExitGUI();
            }
            if (type != EventType.ExecuteCommand || !(current.commandName == "ObjectSelectorUpdated") || (ObjectSelector.get.objectSelectorID != controlId || GUIUtility.keyboardControl != controlId))
            {
                return;
            }
            EditorGUIUtility.SetIconForObject(this.m_TargetObject, ObjectSelector.GetCurrentObject() as Texture2D);
            GUI.changed = true;
            current.Use();
        }