VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_FA_GlyphHelper_Editor.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEditor;
5 
6 using AVR.UI.Utils;
7 using AVR.UEditor.Core;
8 
9 namespace AVR.UEditor.UI {
10  [CustomEditor(typeof(AVR_FA_GlyphHelper))]
11  public class AVR_FA_GlyphHelper_Editor : Editor
12  {
13  private enum FA_type
14  {
15  SOLID, BRAND, REGULAR
16  }
17 
18  FA_type ShowType = FA_type.SOLID;
19 
20  string unicode_input;
21 
22  List<int> regular_unicodes = new List<int>();
23  List<int> solid_unicodes = new List<int>();
24  List<int> brand_unicodes = new List<int>();
25 
29 
33 
37 
38  GUIStyle button_style;
39 
40  Vector2 scrollPos = Vector2.zero;
41 
42  bool show_glyphs = false;
43 
44  void OnEnable()
45  {
46  solid_static = AVR_EditorUtility.GetFont("/editor/editorfonts/font-awesome-solid-static");
47  solid_dynamic = AVR_EditorUtility.GetFont("/editor/editorfonts/font-awesome-solid");
48  solid_runtime = AVR_EditorUtility.GetFont("/editor/fonts/font-awesome-solid");
49 
50  regular_static = AVR_EditorUtility.GetFont("/editor/editorfonts/font-awesome-regular-static");
51  regular_dynamic = AVR_EditorUtility.GetFont("/editor/editorfonts/font-awesome-regular");
52  regular_runtime = AVR_EditorUtility.GetFont("/editor/fonts/font-awesome-regular");
53 
54  brand_static = AVR_EditorUtility.GetFont("/editor/editorfonts/font-awesome-brands-static");
55  brand_dynamic = AVR_EditorUtility.GetFont("/editor/editorfonts/font-awesome-brands");
56  brand_runtime = AVR_EditorUtility.GetFont("/editor/fonts/font-awesome-brands");
57 
58  solid_unicodes = new List<int>();
59  foreach (var c in solid_static.characterInfo)
60  {
61  solid_unicodes.Add(c.index);
62  }
63 
64  regular_unicodes = new List<int>();
65  foreach (var c in regular_static.characterInfo)
66  {
67  regular_unicodes.Add(c.index);
68  }
69 
70  brand_unicodes = new List<int>();
71  foreach (var c in brand_static.characterInfo)
72  {
73  brand_unicodes.Add(c.index);
74  }
75  }
76 
77  private void FromUnicode(Font UseFont) {
78  if (GUILayout.Button("Search Glyphs", GUILayout.Height(30)))
79  {
80  Application.OpenURL("https://fontawesome.com/v5.15/icons?d=gallery&p=2&s=brands,regular,solid&m=free");
81  }
82  using (new EditorGUILayout.HorizontalScope())
83  {
84  GUILayout.Label("Hex. Unicode:");
85  unicode_input = GUILayout.TextField(unicode_input);
86  if(GUILayout.Button("Set", GUILayout.Width(60))) {
87  ((AVR_FA_GlyphHelper)target).setup(UseFont, int.Parse(unicode_input, System.Globalization.NumberStyles.HexNumber));
88  }
89  }
90  }
91 
92  private void Glyphs(List<int> unicodes, Font DisplayFont, Font UseFont)
93  {
94  const float button_size = 30;
95  const int fontSize = 16;
96 
97  float max_width = Screen.width - button_size;
98 
99  float width_acc = 0.0f;
100 
101  button_style = new GUIStyle(GUI.skin.button);
102  button_style.margin = new RectOffset(0, 0, 0, 0);
103  button_style.fontSize = fontSize;
104  button_style.font = DisplayFont;
105 
106  scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(500), GUILayout.Width(max_width));
107  GUILayout.BeginHorizontal();
108  for (int i = 0; i < unicodes.Count; i++)
109  {
110  if (width_acc >= max_width)
111  {
112  GUILayout.EndHorizontal();
113  GUILayout.BeginHorizontal();
114  width_acc = 0.0f;
115  }
116 
117  int u = unicodes[i];
118 
119  if(GUILayout.Button(AVR_EditorUtility.Unicode_to_String(u), button_style, GUILayout.Width(button_size), GUILayout.Height(button_size))) {
120  ((AVR_FA_GlyphHelper)target).setup(UseFont, u);
121  show_glyphs = false;
122  }
123 
124  width_acc += button_size + 2; //+2 because inherently there is 1 pixel of padding on each side.
125  }
126  GUILayout.EndHorizontal();
127  EditorGUILayout.EndScrollView();
128  }
129 
130  public override void OnInspectorGUI()
131  {
132  using (new EditorGUILayout.HorizontalScope())
133  {
134  if (!show_glyphs && GUILayout.Button("Show Glyphs", GUILayout.Height(60)))
135  {
136  show_glyphs = true;
137  }
138 
139  if (show_glyphs && GUILayout.Button("Hide Glyphs", GUILayout.Height(60)))
140  {
141  show_glyphs = false;
142  }
143 
144  if (GUILayout.Button("Remove Helper", GUILayout.Height(60), GUILayout.Width(120)))
145  {
146  DestroyImmediate(target);
147  }
148  }
149 
150  EditorGUILayout.Space();
151 
152  if (show_glyphs)
153  {
154  EditorGUILayout.Space();
155 
156  using (new EditorGUILayout.HorizontalScope())
157  {
158  if (GUILayout.Button("Solid Glyphs", GUILayout.Height(30))) ShowType = FA_type.SOLID;
159  if (GUILayout.Button("Regular Glyphs", GUILayout.Height(30))) ShowType = FA_type.REGULAR;
160  if (GUILayout.Button("Brand Glyphs", GUILayout.Height(30))) ShowType = FA_type.BRAND;
161  }
162 
163  switch(ShowType) {
164  case FA_type.SOLID:
165  {
166  EditorGUILayout.Space();
167  FromUnicode(solid_runtime);
168  EditorGUILayout.Space();
169  Glyphs(solid_unicodes, solid_dynamic, solid_runtime);
170  break;
171  }
172  case FA_type.REGULAR:
173  {
174  EditorGUILayout.Space();
175  FromUnicode(regular_runtime);
176  EditorGUILayout.Space();
177  Glyphs(regular_unicodes, regular_dynamic, regular_runtime);
178  break;
179  }
180  case FA_type.BRAND:
181  {
182  EditorGUILayout.Space();
183  FromUnicode(brand_runtime);
184  EditorGUILayout.Space();
185  Glyphs(brand_unicodes, brand_dynamic, brand_runtime);
186  break;
187  }
188  }
189  }
190  }
191  }
192 }
static string Unicode_to_String(string unicode)
void Glyphs(List< int > unicodes, Font DisplayFont, Font UseFont)