public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(m_Size); EditorGUILayout.PropertyField(m_Color); icon.UpdateScale(); if (GUILayout.Button("Pick an Icon")) { IconPickerWindow.Show(icon.text, (t) => icon.text = t); } if (GUILayout.Button("Pick Material Design Color")) { ColorPickerWindow.Show(icon.color, (t) => icon.color = t); } serializedObject.ApplyModifiedProperties(); }
static public void Show(string preSelect, System.Action <string> callback) { selfW = (IconPickerWindow)EditorWindow.GetWindow <IconPickerWindow>(true); selfW.titleContent = new GUIContent("Pick an Icon"); selfW.minSize = new Vector2(410, 529); selfW.maxSize = new Vector2(410, 529); labelStyle = new GUIStyle(); var fontGUID = AssetDatabase.FindAssets("Roboto-Light")[0]; labelStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(fontGUID)); iconStyle = new GUIStyle(); fontGUID = AssetDatabase.FindAssets("MaterialIcons-Regular")[0]; iconStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(fontGUID)); iconStyle.normal.textColor = MaterialDesignColorset.grey600; iconTextStyle = new GUIStyle(); fontGUID = AssetDatabase.FindAssets("Roboto-Medium")[0]; iconTextStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(fontGUID)); iconTextStyle.alignment = TextAnchor.LowerCenter; iconTextStyle.normal.textColor = MaterialDesignColorset.grey600; iconTextStyle.fontSize = 12; buttonStyle = new GUIStyle(); selfW.onSelectionChanged = callback; List <string> tempList = new List <string>(); foreach (string s in IconsData.iconsUnicode) { tempList.Add(System.Text.RegularExpressions.Regex.Unescape(@"\u" + s)); } if (tempList.Contains(preSelect)) { selfW.selected = preSelect; selfW.selectedID = tempList.IndexOf(selfW.selected); int lineOfSelection = selfW.selectedID / itemPerLine - 1; selfW.scrollPosition = new Vector2(0f, lineOfSelection * (iconSize + spacing)); } selfW.ShowUtility(); }