void DrawIconPicker()
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            Dictionary <string, string> icons = MaterialVectorIcon.GetIcons();
            List <string> actualList          = new List <string>();

            if (!string.IsNullOrEmpty(searchInput))
            {
                foreach (string iconName in icons.Keys)
                {
                    if (iconName.Contains(searchInput))
                    {
                        actualList.Add(iconName);
                    }
                }
            }

            DrawIcons(icons, (actualList.Count > 0 ? actualList : icons.Keys.ToList()));

            EditorGUILayout.EndScrollView();

            if (doubleClicked)
            {
                doubleClicked     = false;
                selected          = null;
                previouslyClicked = "";
                Close();
            }
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            MaterialVectorIcon icon = target as MaterialVectorIcon;

            serializedObject.Update();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("raycast"));

            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Color"));

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Icon", GUILayout.Width(EditorGUIUtility.labelWidth));

            GUIStyle iconStyle = new GUIStyle(GUI.skin.label);

            iconStyle.font             = icon.font;
            iconStyle.border           = new RectOffset(5, 5, 5, 5);
            iconStyle.contentOffset    = new Vector2(0, 0);
            iconStyle.alignment        = icon.alignment;
            iconStyle.normal.textColor = (EditorGUIUtility.isProSkin ? Color.white : new Color(0.2f, 0.2f, 0.2f));

            if (Selection.gameObjects.Length < 2)
            {
                GUILayout.Label(new GUIContent(MaterialVectorIcon.Decode(icon.iconName), "Icon: " + icon.iconName), iconStyle, GUILayout.Width(20));
            }
            if (GUILayout.Button("Choose Icon"))
            {
                MaterialVectorIconEditorWindow.ShowWindow();
            }

            EditorGUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();
        }
        private void DrawIconPicker()
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            Dictionary <string, string> icons = MaterialVectorIcon.GetIcons();
            List <string> iconNameList        = new List <string>(icons.Keys);

            if (!string.IsNullOrEmpty(searchInput))
            {
                for (int i = 0; i < iconNameList.Count; i++)
                {
                    if (!iconNameList[i].ToLower().Contains(searchInput.ToLower()))
                    {
                        iconNameList.RemoveAt(i);
                        i--;
                    }
                }
            }
            DrawIcons(icons, iconNameList);

            EditorGUILayout.EndScrollView();
        }
        private void DrawIcons(Dictionary <string, string> icons, List <string> iconNameList)
        {
            string   name;
            float    elementWidth = 50;
            int      index        = 0;
            GUIStyle iconStyle    = new GUIStyle(GUI.skin.button);

            iconStyle.font             = Resources.Load <Font>("ASMaterialIcon/Fonts/MaterialIcons-Regular") as Font;
            iconStyle.border           = new RectOffset(5, 5, 5, 5);
            iconStyle.contentOffset    = new Vector2(0, 0);
            iconStyle.alignment        = TextAnchor.MiddleCenter;
            iconStyle.normal.textColor = (EditorGUIUtility.isProSkin ? Color.white : new Color(0.2f, 0.2f, 0.2f));

            while (iconNameList.Count > 0)
            {
                index++;
                name = iconNameList[0];
                iconNameList.RemoveAt(0);

                EditorGUILayout.BeginHorizontal();
                float remainingSpace = EditorGUIUtility.currentViewWidth - EditorGUIUtility.currentViewWidth / 10;
                while (iconNameList.Count > 0 && remainingSpace > elementWidth)
                {
                    Color oldColor = GUI.backgroundColor;
                    GUI.backgroundColor = Color.clear;
                    if (Selection.gameObjects != null)
                    {
                        for (int i = 0; i < Selection.gameObjects.Length; i++)
                        {
                            GameObject go = Selection.gameObjects[i];
                            if (go.GetComponent <MaterialVectorIcon>() != null)
                            {
                                MaterialVectorIcon icon = go.GetComponent <MaterialVectorIcon>();
                                if (name.Equals(icon.iconName))
                                {
                                    GUI.backgroundColor = new Color(1, 1, 1, 0.5f);
                                }
                            }
                        }
                    }
                    if (GUILayout.Button(new GUIContent(MaterialVectorIcon.Decode("\\u" + icons[name]), "Icon: " + name), iconStyle, GUILayout.Width(elementWidth), GUILayout.Height(50)))
                    {
                        if (Selection.gameObjects != null)
                        {
                            for (int i = 0; i < Selection.gameObjects.Length; i++)
                            {
                                GameObject go = Selection.gameObjects[i];
                                if (go.GetComponent <MaterialVectorIcon>() != null)
                                {
                                    MaterialVectorIcon icon = go.GetComponent <MaterialVectorIcon>();
                                    Undo.RecordObject(icon, "Changed icon of " + icon.name);
                                    icon.text     = MaterialVectorIcon.Decode("\\u" + icons[name]);
                                    icon.iconName = name;
                                    EditorUtility.SetDirty(icon);
                                }
                            }
                        }
                    }
                    GUI.backgroundColor = oldColor;
                    remainingSpace     -= elementWidth;
                    index++;
                    name = iconNameList[0];
                    iconNameList.RemoveAt(0);
                }
                EditorGUILayout.EndHorizontal();
            }
        }
        void DrawIcons(Dictionary <string, string> icons, List <string> iconNameList)
        {
            string   name;
            float    elementWidth = 60f;
            GUIStyle iconStyle    = new GUIStyle(GUI.skin.button);

            iconStyle.font             = Resources.Load <Font>("ASMaterialIcon/Fonts/MaterialIcons-Regular") as Font;
            iconStyle.fontSize         = 30;
            iconStyle.border           = new RectOffset(5, 5, 5, 5);
            iconStyle.contentOffset    = new Vector2(0, 0);
            iconStyle.alignment        = TextAnchor.MiddleCenter;
            iconStyle.normal.textColor = (EditorGUIUtility.isProSkin ? Color.white : new Color(0.2f, 0.2f, 0.2f));

            for (int y = 0; y < iconNameList.Count; y++)
            {
                EditorGUILayout.BeginHorizontal();

                float remainingSpace = EditorGUIUtility.currentViewWidth - EditorGUIUtility.currentViewWidth / 10;

                while (remainingSpace > elementWidth && y < iconNameList.Count)
                {
                    name = iconNameList[y];
                    Color oldColor = GUI.backgroundColor;
                    GUI.backgroundColor = Color.clear;

                    if (Selection.gameObjects != null)
                    {
                        foreach (GameObject selection in Selection.gameObjects.ToList())
                        {
                            if (selection.GetComponent <MaterialVectorIcon>())
                            {
                                if (name == selection.GetComponent <MaterialVectorIcon>().iconName)
                                {
                                    GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                                }
                            }
                            if (selected != null)
                            {
                                if (name == selected.stringValue)
                                {
                                    GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                                }
                            }
                        }
                    }


                    if (GUILayout.Button(new GUIContent(MaterialVectorIcon.Decode(name), "Icon: " + name), iconStyle, GUILayout.Width(elementWidth), GUILayout.Height(elementWidth)))
                    {
                        if (Selection.gameObjects != null)
                        {
                            foreach (GameObject selection in Selection.gameObjects.ToList())
                            {
                                MaterialVectorIcon mvi = selection.GetComponent <MaterialVectorIcon>();

                                if (mvi)
                                {
                                    Undo.RecordObject(mvi, "Changed icon of " + mvi.name);
                                    mvi.SetIcon(name);
                                    EditorUtility.SetDirty(mvi);

                                    doubleClicked = Time.realtimeSinceStartup < time && name == previouslyClicked;
                                }
                                else if (selected != null)
                                {
                                    Undo.RecordObject(selected.serializedObject.targetObject, "Changed icon of " + selected.serializedObject.ToString());
                                    selected.stringValue = name;
                                    selected.serializedObject.ApplyModifiedProperties();
                                    EditorUtility.SetDirty(selected.serializedObject.targetObject);

                                    doubleClicked = Time.realtimeSinceStartup < time && name == previouslyClicked;
                                }
                            }

                            time = Time.realtimeSinceStartup + 0.25f;
                            previouslyClicked = name;
                        }
                    }

                    GUI.backgroundColor = oldColor;
                    remainingSpace     -= elementWidth;
                    y++;
                }

                EditorGUILayout.EndHorizontal();
            }
        }