├── LICENSE
├── README.md
├── doc
├── preview.png
└── sample.png
└── src
└── UnityMaterialIcons
├── .gitignore
├── Assets
├── MaterialIcons.meta
├── MaterialIcons
│ ├── Editor.meta
│ ├── Editor
│ │ ├── MaterialIconEditor.cs
│ │ ├── MaterialIconEditor.cs.meta
│ │ ├── MaterialIconSelectionWindow.cs
│ │ ├── MaterialIconSelectionWindow.cs.meta
│ │ ├── MenuOptions.cs
│ │ └── MenuOptions.cs.meta
│ ├── MaterialIcon.cs
│ ├── MaterialIcon.cs.meta
│ ├── MaterialIcons-Regular.ttf
│ ├── MaterialIcons-Regular.ttf.meta
│ ├── codepoints
│ ├── codepoints.meta
│ ├── readme.txt
│ └── readme.txt.meta
├── Sample.unity
└── Sample.unity.meta
└── ProjectSettings
├── AudioManager.asset
├── ClusterInputManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── GraphicsSettings.asset
├── InputManager.asset
├── NavMeshAreas.asset
├── NetworkManager.asset
├── PackageManagerSettings.asset
├── Physics2DSettings.asset
├── PresetManager.asset
├── ProjectSettings.asset
├── ProjectVersion.txt
├── QualitySettings.asset
├── SceneTemplateSettings.json
├── TagManager.asset
├── TimeManager.asset
├── TimelineSettings.asset
├── UnityConnectSettings.asset
├── VFXManager.asset
└── VersionControlSettings.asset
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | > [!WARNING]
2 | > This project is deprecated in favor of my new [Material Symbols](https://github.com/convalise/unity-material-symbols) one and will no longer be updated.
3 |
4 | # Unity Material Icons (legacy)
5 |
6 | Add-on that simplifies the usage of Google's Material Design icons font on Unity. The motivation is to have a lightweight set of standardized icons in order to provide the same pattern and design throughout the whole application UI improving UX.
7 |
8 | Supported Unity versions are 2017.1 or higher.
9 |
10 | ## Quickstart
11 |
12 | Simply import the package into Unity by downloading it from the [latest release](https://github.com/convalise/unity-material-icons/releases/latest).
13 |
14 | Then, add the MaterialIcon class to your GameObject and you are good to go.
15 |
16 | You can also add a new icon to the scene by right-clicking on the hierarchy window and selecting `Google > Material Icon`.
17 |
18 | ## Documentation
19 |
20 | The MaterialIcon class inherits from `UnityEngine.UI.Text`, so you have all properties and methods available [here](https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-Text.html) such as color and raycast target.
21 |
22 | You can set the icon programaticaly by setting the text to the properly Unicode escaped char (e.g., `icon.text = "\uE84D"`), or without unicode notation by using the provided sugar `iconUnicode` (e.g., `icon.iconUnicode = "E84D"`).
23 |
24 | ## Known issues
25 |
26 | The "goat" icon (unicode 10FFFD) is currently the only unsupported one due to surrogate-pair characters limitations.
27 |
28 | ## Credits
29 |
30 | This project was created by Conrado (https://github.com/convalise).
31 |
32 | It makes usage of the [Material Design icons project by Google](https://github.com/google/material-design-icons).\
33 | More information on the Google's project can be found at the [Material Icons Guide](http://google.github.io/material-design-icons/).
34 |
35 | ## License
36 |
37 | This software is licensed under **Apache License 2.0**. You can find the full text of the license [here](LICENSE).
38 |
--------------------------------------------------------------------------------
/doc/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/convalise/unity-material-icons/164c14f73de45f517cf5e4f106ef592ee9d7b557/doc/preview.png
--------------------------------------------------------------------------------
/doc/sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/convalise/unity-material-icons/164c14f73de45f517cf5e4f106ef592ee9d7b557/doc/sample.png
--------------------------------------------------------------------------------
/src/UnityMaterialIcons/.gitignore:
--------------------------------------------------------------------------------
1 | /*
2 | !/Assets/
3 | !/ProjectSettings/
4 | !/UnityPackageManager/
5 | !/.gitignore
--------------------------------------------------------------------------------
/src/UnityMaterialIcons/Assets/MaterialIcons.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1429708ae2e376a469b0488cdcd98d1b
3 | folderAsset: yes
4 | timeCreated: 1585147601
5 | licenseType: Free
6 | DefaultImporter:
7 | externalObjects: {}
8 | userData:
9 | assetBundleName:
10 | assetBundleVariant:
11 |
--------------------------------------------------------------------------------
/src/UnityMaterialIcons/Assets/MaterialIcons/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e7eb0eb9652214c49b7e30cfdd733e38
3 | folderAsset: yes
4 | timeCreated: 1585147601
5 | licenseType: Free
6 | DefaultImporter:
7 | externalObjects: {}
8 | userData:
9 | assetBundleName:
10 | assetBundleVariant:
11 |
--------------------------------------------------------------------------------
/src/UnityMaterialIcons/Assets/MaterialIcons/Editor/MaterialIconEditor.cs:
--------------------------------------------------------------------------------
1 |
2 | using UnityEngine;
3 | using UnityEditor;
4 | using System.Reflection;
5 |
6 | namespace Google.MaterialDesign.Icons
7 | {
8 |
9 | [CustomEditor(typeof(MaterialIcon), true), CanEditMultipleObjects]
10 | public class MaterialIconEditor : UnityEditor.UI.TextEditor
11 | {
12 | private static readonly Color darkColor = new Color(0.196f, 0.196f, 0.196f);
13 | private static readonly Color lightColor = new Color(0.804f, 0.804f, 0.804f);
14 |
15 | private SerializedProperty spText;
16 | private SerializedProperty spColor;
17 | private SerializedProperty spRaycastTarget;
18 | private SerializedProperty spAlignment;
19 | private SerializedProperty spFontScale;
20 |
21 | private MaterialIcon icon;
22 | private Font MaterialIconsRegular;
23 | private GUIStyle iconStyle;
24 | private GUIContent iconTooltip = new GUIContent();
25 | private GUIContent mixedContent = new GUIContent("\u2014", "Mixed Values");
26 |
27 | protected override void OnEnable()
28 | {
29 | base.OnEnable();
30 | icon = target as MaterialIcon;
31 |
32 | if(string.IsNullOrEmpty(icon.text))
33 | {
34 | icon.Init();
35 | }
36 |
37 | if(icon.font == null)
38 | {
39 | icon.LoadFont();
40 | }
41 |
42 | MaterialIconsRegular = icon.font;
43 |
44 | iconStyle = new GUIStyle();
45 | iconStyle.font = MaterialIconsRegular;
46 | iconStyle.fontSize = 42;
47 | iconStyle.alignment = TextAnchor.MiddleCenter;
48 | iconStyle.normal.textColor = iconStyle.active.textColor = iconStyle.focused.textColor = iconStyle.hover.textColor = EditorGUIUtility.isProSkin ? lightColor : darkColor;
49 |
50 | iconTooltip.tooltip = icon.iconUnicode;
51 |
52 | spText = serializedObject.FindProperty("m_Text");
53 | spColor = serializedObject.FindProperty("m_Color");
54 | spRaycastTarget = serializedObject.FindProperty("m_RaycastTarget");
55 | spAlignment = serializedObject.FindProperty("m_FontData.m_Alignment");
56 | spFontScale = serializedObject.FindProperty("_fontScale");
57 | }
58 |
59 | public override void OnInspectorGUI()
60 | {
61 | serializedObject.Update();
62 |
63 | if(MaterialIconsRegular == null)
64 | {
65 | EditorGUILayout.Space();
66 | EditorGUILayout.HelpBox("Could not find \"MaterialIcons-Regular\" font data.", MessageType.Error);
67 | }
68 |
69 | EditorGUILayout.Space();
70 |
71 | EditorGUI.BeginDisabledGroup(MaterialIconsRegular == null);
72 |
73 | Rect iconRect = GUILayoutUtility.GetRect(EditorGUIUtility.singleLineHeight * 3f, EditorGUIUtility.singleLineHeight * 3f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
74 | DoIconControl(iconRect, spText, () => {
75 | MaterialIconSelectionWindow.Init(MaterialIconsRegular, spText.stringValue, (selected) => {
76 | spText.stringValue = selected;
77 | serializedObject.ApplyModifiedProperties();
78 | iconTooltip.tooltip = icon.iconUnicode;
79 | Repaint();
80 | });
81 | });
82 |
83 | EditorGUI.EndDisabledGroup();
84 |
85 | EditorGUILayout.Space();
86 |
87 | EditorGUILayout.PropertyField(spColor);
88 | EditorGUILayout.PropertyField(spRaycastTarget);
89 |
90 | EditorGUILayout.Space();
91 |
92 | EditorGUILayout.PropertyField(spFontScale);
93 | Rect alignmentRect = GUILayoutUtility.GetRect(EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
94 | DoTextAlignmentControl(alignmentRect, spAlignment);
95 |
96 | serializedObject.ApplyModifiedProperties();
97 | }
98 |
99 | private void DoIconControl(Rect position, SerializedProperty text, System.Action callback)
100 | {
101 | bool mixedValues = (text.hasMultipleDifferentValues || ((text.stringValue != null) && (text.stringValue.Length > 1)));
102 | GUIContent guiContent = new GUIContent("Icon");
103 | EditorGUI.BeginProperty(position, guiContent, text);
104 | Rect rect = EditorGUI.PrefixLabel(position, guiContent);
105 | rect.width = rect.height;
106 | if(GUI.Button(rect, mixedValues ? mixedContent : iconTooltip))
107 | callback.Invoke();
108 | GUI.Label(rect, mixedValues ? string.Empty : text.stringValue, iconStyle);
109 | EditorGUI.EndProperty();
110 | }
111 |
112 | /// Reflection for the private synonymous method from the FontDataDrawer class.
113 | private static readonly MethodInfo DoHorizontalAlignmentControl = typeof(UnityEditor.UI.FontDataDrawer).GetMethod("DoHorizontalAligmentControl", BindingFlags.NonPublic | BindingFlags.Static);
114 |
115 | /// Reflection for the private synonymous method from the FontDataDrawer class.
116 | private static readonly MethodInfo DoVerticalAlignmentControl = typeof(UnityEditor.UI.FontDataDrawer).GetMethod("DoVerticalAligmentControl", BindingFlags.NonPublic | BindingFlags.Static);
117 |
118 | /// Workaround for the non-static private synonymous method from the FontDataDrawer class.
119 | private static void DoTextAlignmentControl(Rect position, SerializedProperty alignment)
120 | {
121 | try
122 | {
123 | GUIContent guiContent = new GUIContent("Alignment");
124 | EditorGUIUtility.SetIconSize(new Vector2(15f, 15f));
125 | EditorGUI.BeginProperty(position, guiContent, alignment);
126 | Rect rect = EditorGUI.PrefixLabel(position, guiContent);
127 | float size1 = 60f;
128 | float size2 = Mathf.Clamp(rect.width - size1 * 2f, 2f, 10f);
129 | Rect position2 = new Rect(rect.x, rect.y, size1, rect.height);
130 | Rect position3 = new Rect(position2.xMax + size2, rect.y, size1, rect.height);
131 | DoHorizontalAlignmentControl.Invoke(null, new object[] { position2, alignment });
132 | DoVerticalAlignmentControl.Invoke(null, new object[] { position3, alignment });
133 | EditorGUI.EndProperty();
134 | EditorGUIUtility.SetIconSize(Vector2.zero);
135 | }
136 | catch(System.Exception e)
137 | {
138 | Debug.LogException(e);
139 | }
140 | }
141 |
142 | }
143 |
144 | }
145 |
--------------------------------------------------------------------------------
/src/UnityMaterialIcons/Assets/MaterialIcons/Editor/MaterialIconEditor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 51028811296326e41a2930e85b26f4b3
3 | timeCreated: 1585147601
4 | licenseType: Free
5 | MonoImporter:
6 | externalObjects: {}
7 | serializedVersion: 2
8 | defaultReferences: []
9 | executionOrder: 0
10 | icon: {instanceID: 0}
11 | userData:
12 | assetBundleName:
13 | assetBundleVariant:
14 |
--------------------------------------------------------------------------------
/src/UnityMaterialIcons/Assets/MaterialIcons/Editor/MaterialIconSelectionWindow.cs:
--------------------------------------------------------------------------------
1 |
2 | using UnityEngine;
3 | using UnityEditor;
4 |
5 | using System.IO;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 |
9 | namespace Google.MaterialDesign.Icons
10 | {
11 |
12 | public class MaterialIconSelectionWindow : EditorWindow
13 | {
14 | private static readonly Color darkColor = new Color(0.196f, 0.196f, 0.196f);
15 | private static readonly Color lightColor = new Color(0.804f, 0.804f, 0.804f);
16 |
17 | private int iconSize = 58;
18 | private int labelHeight = 24;
19 | private int spacing = 10;
20 | private bool showNames = true;
21 | private Vector2 scrollPos = Vector2.zero;
22 | private string filterText = string.Empty;
23 | private bool filterGotFocus = false;
24 |
25 | private string selected;
26 | private string selectedName;
27 | private bool selectionKeep;
28 | private System.Action onSelectionChanged;
29 |
30 | private Font MaterialIconsRegular;
31 | private CodepointData[] codepointsCollection;
32 | private CodepointData[] filteredCollection;
33 |
34 | private GUIStyle toolbarSeachTextFieldStyle;
35 | private GUIStyle toolbarSeachCancelButtonStyle;
36 | private GUIStyle toolbarSeachCancelButtonEmptyStyle;
37 | private GUIStyle toolbarLabelStyle;
38 | private GUIStyle iconImageStyle;
39 | private GUIStyle iconLabelStyle;
40 | private GUIStyle iconSelectionStyle;
41 |
42 | public void LoadDependencies(Font MaterialIconsRegular)
43 | {
44 | showNames = EditorPrefs.GetBool(typeof(MaterialIconSelectionWindow) + ".showNames", true);
45 |
46 | if(MaterialIconsRegular == null)
47 | return;
48 |
49 | this.MaterialIconsRegular = MaterialIconsRegular;
50 |
51 | string fontPath = AssetDatabase.GetAssetPath(MaterialIconsRegular);
52 | string codepointsPath = Path.GetDirectoryName(fontPath) + "/codepoints";
53 |
54 | List tempList = new List();
55 |
56 | foreach(string codepoint in File.ReadAllLines(codepointsPath))
57 | {
58 | string[] data = codepoint.Split(' ');
59 | tempList.Add(new CodepointData(data[0], data[1]));
60 | }
61 |
62 | codepointsCollection = tempList.ToArray();
63 | filteredCollection = codepointsCollection;
64 |
65 | var temp = filteredCollection.FirstOrDefault(data => data.codeGUIContent.text == selected);
66 | if(temp != null)
67 | selectedName = temp.name;
68 | }
69 |
70 | public static void Init(Font MaterialIconsRegular, string preSelect, System.Action callback)
71 | {
72 | MaterialIconSelectionWindow window = EditorWindow.GetWindow(true);
73 | window.selected = preSelect;
74 | window.onSelectionChanged = callback;
75 | window.LoadDependencies(MaterialIconsRegular);
76 | }
77 |
78 | private void OnEnable()
79 | {
80 | base.titleContent = new GUIContent("Material Icon Selection");
81 | base.minSize = new Vector2((iconSize + labelHeight + spacing) * 5f + GUI.skin.verticalScrollbar.fixedWidth + 1f, (iconSize + labelHeight + spacing) * 6f + EditorStyles.toolbar.fixedHeight);
82 | selectionKeep = true;
83 | }
84 |
85 | private void OnGUI()
86 | {
87 | if((toolbarSeachTextFieldStyle == null) || (iconImageStyle == null))
88 | {
89 | toolbarSeachTextFieldStyle = new GUIStyle("ToolbarSeachTextField");
90 | toolbarSeachCancelButtonStyle = new GUIStyle("ToolbarSeachCancelButton");
91 | toolbarSeachCancelButtonEmptyStyle = new GUIStyle("ToolbarSeachCancelButtonEmpty");
92 | toolbarLabelStyle = new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleCenter };
93 | iconSelectionStyle = new GUIStyle("selectionrect");
94 | iconImageStyle = new GUIStyle() { font = MaterialIconsRegular, fontSize = iconSize - spacing - 10, alignment = TextAnchor.MiddleCenter };
95 | iconLabelStyle = new GUIStyle(EditorStyles.miniLabel) { alignment = TextAnchor.UpperCenter, wordWrap = true };
96 | iconImageStyle.padding = iconLabelStyle.padding = new RectOffset();
97 | iconImageStyle.normal.textColor = iconLabelStyle.normal.textColor = EditorGUIUtility.isProSkin ? lightColor : darkColor;
98 | }
99 |
100 | if(MaterialIconsRegular == null)
101 | {
102 | EditorGUILayout.HelpBox("Could not find \"MaterialIcons-Regular\" font data.", MessageType.Error);
103 | return;
104 | }
105 |
106 | if((codepointsCollection == null) || (codepointsCollection.Length == 0))
107 | {
108 | EditorGUILayout.HelpBox("Could not find \"codepoints\" font data.", MessageType.Error);
109 | return;
110 | }
111 |
112 | OnHeaderGUI();
113 | OnBodyGUI();
114 | }
115 |
116 | private void OnHeaderGUI()
117 | {
118 | Rect groupRect = new Rect(0f, 0f, base.position.width, EditorStyles.toolbar.fixedHeight);
119 | GUI.BeginGroup(groupRect);
120 |
121 | if(Event.current.type == EventType.Repaint)
122 | {
123 | EditorStyles.toolbar.Draw(groupRect, false, false, false, false);
124 | }
125 |
126 | Rect filterRect = new Rect(6f, 2f, groupRect.width - 6f - 20f - 64f - 6f, groupRect.height - 2f);
127 | Rect clearRect = new Rect(filterRect.x + filterRect.width, filterRect.y, 20f, filterRect.height);
128 |
129 | EditorGUI.BeginChangeCheck();
130 |
131 | GUI.SetNextControlName(typeof(MaterialIconSelectionWindow) + ".filterText");
132 | filterText = EditorGUI.TextField(filterRect, filterText, toolbarSeachTextFieldStyle);
133 |
134 | if(GUI.Button(clearRect, GUIContent.none, string.IsNullOrEmpty(filterText) ? toolbarSeachCancelButtonEmptyStyle : toolbarSeachCancelButtonStyle))
135 | {
136 | filterText = string.Empty;
137 | GUI.FocusControl(null);
138 | }
139 |
140 | if(!filterGotFocus)
141 | {
142 | EditorGUI.FocusTextInControl(typeof(MaterialIconSelectionWindow) + ".filterText");
143 | filterGotFocus = true;
144 | }
145 |
146 | if(EditorGUI.EndChangeCheck())
147 | {
148 | filteredCollection = codepointsCollection.Where(data => string.IsNullOrEmpty(filterText) || data.nameGUIContent.text.IndexOf(filterText, System.StringComparison.OrdinalIgnoreCase) >= 0).ToArray();
149 | selectionKeep = true;
150 | }
151 |
152 | Rect nameRect = new Rect(clearRect.x + clearRect.width, groupRect.y, 64f, groupRect.height);
153 | EditorGUI.BeginChangeCheck();
154 | showNames = EditorGUI.Toggle(nameRect, showNames, EditorStyles.toolbarButton);
155 | if(EditorGUI.EndChangeCheck())
156 | {
157 | GUI.FocusControl(null);
158 | EditorPrefs.SetBool(typeof(MaterialIconSelectionWindow) + ".showNames", showNames);
159 | }
160 | EditorGUI.LabelField(nameRect, "Names", toolbarLabelStyle);
161 |
162 | GUI.EndGroup();
163 | }
164 |
165 | private void OnBodyGUI()
166 | {
167 | Rect iconRect = new Rect(0f, 0f, iconSize + labelHeight, iconSize);
168 | Rect labelRect = new Rect(0f, 0f, iconRect.width, labelHeight);
169 | if(!showNames)
170 | {
171 | iconRect.width -= labelHeight;
172 | labelRect.height = 0f;
173 | }
174 | Rect buttonRect = new Rect(0f, 0f, iconRect.width + spacing, iconRect.height + labelRect.height + spacing);
175 |
176 | Rect groupRect = new Rect(0f, EditorStyles.toolbar.fixedHeight, base.position.width, base.position.height - EditorStyles.toolbar.fixedHeight);
177 | GUI.BeginGroup(groupRect);
178 |
179 | Rect scrollRect = new Rect(0f, 0f, groupRect.width, groupRect.height);
180 | int columns = Mathf.FloorToInt((scrollRect.width - GUI.skin.verticalScrollbar.fixedWidth) / (iconRect.width + spacing));
181 | Rect viewRect = new Rect(0f, 0f, scrollRect.width - GUI.skin.verticalScrollbar.fixedWidth, Mathf.Ceil(filteredCollection.Length / (float) columns) * (iconRect.height + labelRect.height + spacing));
182 |
183 | scrollPos = GUI.BeginScrollView(scrollRect, scrollPos, viewRect);
184 |
185 | for(int i = 0; i < filteredCollection.Length; i += columns)
186 | {
187 | for(int j = 0; j < columns; j++)
188 | {
189 | if((i + j) >= filteredCollection.Length)
190 | break;
191 |
192 | var data = filteredCollection[i + j];
193 |
194 | iconRect.x = (j * (iconRect.width + spacing)) + (spacing / 2f);
195 | iconRect.y = ((i / (float) columns) * (iconRect.height + labelRect.height + spacing)) + (spacing / 2f);
196 |
197 | labelRect.x = iconRect.x;
198 | labelRect.y = iconRect.y + iconRect.height;
199 |
200 | buttonRect.x = iconRect.x - (spacing / 2f);
201 | buttonRect.y = iconRect.y - (spacing / 2f);
202 |
203 | if(data.name == selectedName)
204 | {
205 | if(Event.current.type == EventType.Repaint)
206 | {
207 | iconSelectionStyle.Draw(buttonRect, false, true, true, true);
208 | }
209 |
210 | if(selectionKeep)
211 | {
212 | if(buttonRect.y + buttonRect.height > scrollPos.y + scrollRect.height)
213 | scrollPos.y = buttonRect.y + buttonRect.height - scrollRect.height;
214 | else if(buttonRect.y < scrollPos.y)
215 | scrollPos.y = buttonRect.y;
216 |
217 | selectionKeep = false;
218 | base.Repaint();
219 | }
220 | }
221 |
222 | GUI.Label(iconRect, data.codeGUIContent, iconImageStyle);
223 | if(showNames)
224 | GUI.Label(labelRect, data.nameGUIContent, iconLabelStyle);
225 |
226 | if(GUI.Button(buttonRect, GUIContent.none, GUIStyle.none))
227 | {
228 | GUI.FocusControl(null);
229 | bool shouldClose = data.codeGUIContent.text == selected;
230 | selected = data.codeGUIContent.text;
231 | selectedName = data.name;
232 | onSelectionChanged.Invoke(selected);
233 | if(shouldClose)
234 | base.Close();
235 | }
236 | }
237 | }
238 |
239 | GUI.EndScrollView();
240 | GUI.EndGroup();
241 |
242 | if(Event.current.type == EventType.KeyDown)
243 | {
244 | if(Event.current.keyCode == KeyCode.LeftArrow)
245 | {
246 | SelectRelative(-1);
247 | Event.current.Use();
248 | }
249 |
250 | if(Event.current.keyCode == KeyCode.RightArrow)
251 | {
252 | SelectRelative(+1);
253 | Event.current.Use();
254 | }
255 |
256 | if(Event.current.keyCode == KeyCode.UpArrow)
257 | {
258 | SelectRelative(-columns);
259 | Event.current.Use();
260 | }
261 |
262 | if(Event.current.keyCode == KeyCode.DownArrow)
263 | {
264 | SelectRelative(+columns);
265 | Event.current.Use();
266 | }
267 |
268 | if(Event.current.keyCode == KeyCode.PageUp)
269 | {
270 | SelectRelative(-(columns * 6));
271 | Event.current.Use();
272 | }
273 |
274 | if(Event.current.keyCode == KeyCode.PageDown)
275 | {
276 | SelectRelative(+(columns * 6));
277 | Event.current.Use();
278 | }
279 |
280 | if(Event.current.keyCode == KeyCode.Home)
281 | {
282 | SelectAbsolute(0);
283 | Event.current.Use();
284 | }
285 |
286 | if(Event.current.keyCode == KeyCode.End)
287 | {
288 | SelectAbsolute(filteredCollection.Length - 1);
289 | Event.current.Use();
290 | }
291 | }
292 | }
293 |
294 | private void SelectRelative(int delta)
295 | {
296 | SelectAbsolute(System.Array.FindIndex(filteredCollection, (data) => data.name == selectedName) + delta);
297 | }
298 |
299 | private void SelectAbsolute(int index)
300 | {
301 | index = Mathf.Clamp(index, 0, filteredCollection.Length - 1);
302 |
303 | selected = filteredCollection[index].codeGUIContent.text;
304 | selectedName = filteredCollection[index].name;
305 | onSelectionChanged.Invoke(selected);
306 | selectionKeep = true;
307 | base.Repaint();
308 | }
309 |
310 | [System.Serializable]
311 | public class CodepointData
312 | {
313 | public string name { get; private set; }
314 | public string code { get; private set; }
315 | public GUIContent nameGUIContent { get; private set; }
316 | public GUIContent codeGUIContent { get; private set; }
317 |
318 | public CodepointData(string name, string code)
319 | {
320 | this.name = name;
321 | this.code = code;
322 | this.nameGUIContent = new GUIContent(string.Format("{0} ({1})", name.ToLowerInvariant().Replace('_', ' '), code));
323 | this.codeGUIContent = new GUIContent(char.ConvertFromUtf32(System.Convert.ToInt32(this.code, 16)), this.nameGUIContent.text);
324 | }
325 |
326 | }
327 |
328 | }
329 |
330 | }
331 |
--------------------------------------------------------------------------------
/src/UnityMaterialIcons/Assets/MaterialIcons/Editor/MaterialIconSelectionWindow.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 92727dd8d82a3da4bae52be1180138e8
3 | timeCreated: 1585147601
4 | licenseType: Free
5 | MonoImporter:
6 | externalObjects: {}
7 | serializedVersion: 2
8 | defaultReferences: []
9 | executionOrder: 0
10 | icon: {instanceID: 0}
11 | userData:
12 | assetBundleName:
13 | assetBundleVariant:
14 |
--------------------------------------------------------------------------------
/src/UnityMaterialIcons/Assets/MaterialIcons/Editor/MenuOptions.cs:
--------------------------------------------------------------------------------
1 |
2 | using UnityEngine;
3 | using UnityEngine.EventSystems;
4 | using UnityEngine.UI;
5 | using UnityEditor;
6 |
7 | namespace Google.MaterialDesign.Icons
8 | {
9 |
10 | internal static class MenuOptions
11 | {
12 | [MenuItem("GameObject/Google/Material Icon", false, 10)]
13 | public static void CreateMaterialIcon(MenuCommand menuCommand)
14 | {
15 | GameObject parent = menuCommand.context as GameObject;
16 |
17 | if((parent == null) || (parent.GetComponentsInParent