VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
_AVR_Core_EditorUtility.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEditor;
5 
6 /// <summary>
7 /// Namespace of the arc-vr-core (UnityEditor) package
8 /// </summary>
9 namespace AVR.UEditor.Core {
10  [ExecuteInEditMode]
11  public static class AVR_EditorUtility
12  {
13  private static Font fa_cache => _fa_cache!=null ? _fa_cache : _fa_cache = GetFont("/editor/fonts/font-awesome");
14  private static Font _fa_cache;
15 
16  private static Font fab_cache => _fab_cache != null ? _fab_cache : _fab_cache = GetFont("/editor/fonts/font-awesome-brands");
17  private static Font _fab_cache;
18 
19  public static GameObject InstantiatePrefabAsChild(Transform parent, string settings_token) {
20  Object prefab = AssetDatabase.LoadAssetAtPath(AVR.Core.AVR_Settings.get_string(settings_token), typeof(GameObject));
21  if (prefab == null)
22  {
23  AVR.Core.AVR_DevConsole.error("There is a prefab missing at: " + AVR.Core.AVR_Settings.get_string(settings_token));
24  return null;
25  }
26  else
27  {
28  GameObject o = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
29  o.transform.SetParent(parent);
30  o.transform.localPosition = Vector3.zero;
31  o.transform.localRotation = Quaternion.identity;
32  AVR.Core.AVR_DevConsole.success("Instantiated Prefab. Token: " + settings_token);
33  return o;
34  }
35  }
36 
37  public static Font GetFont(string settings_token) {
38  return (Font)AssetDatabase.LoadAssetAtPath(AVR.Core.AVR_Settings.get_string(settings_token), typeof(Font));
39  }
40 
41  public static string Unicode_to_String(string unicode) {
42  return ((char)int.Parse(unicode, System.Globalization.NumberStyles.HexNumber)).ToString();
43  }
44 
45  public static string Unicode_to_String(int unicode) {
46  return ((char)unicode).ToString();
47  }
48 
49  public static bool FAButton(string unicode, bool isBrandIcon=false, int buttonSize=25) {
50  var style = new GUIStyle(GUI.skin.button);
51  style.font = isBrandIcon ? fab_cache : fa_cache;
52  style.fontSize = Mathf.Max(7, buttonSize - 12);
53  return GUILayout.Button(Unicode_to_String(unicode), style, GUILayout.Width(buttonSize), GUILayout.Height(buttonSize));
54  }
55 
56  public static void FALabel(string unicode, bool isBrandIcon = false, int buttonSize = 25)
57  {
58  var style = new GUIStyle(GUI.skin.label);
59  style.font = isBrandIcon ? fab_cache : fa_cache;
60  style.fontSize = Mathf.Max(7, buttonSize - 12);
61  GUILayout.Label(Unicode_to_String(unicode), style, GUILayout.Width(buttonSize), GUILayout.Height(buttonSize));
62  }
63 
64  public static void Documentation_Url(string page) {
65  if(FAButton("f02d")) {
66  string path = System.IO.Path.GetFullPath(AVR.Core.AVR_Settings.get_string("/editor/documentationPath") + page);
67  Application.OpenURL("file:///"+path);
68  }
69  }
70 
71  public static void EventsSettings_Button(AVR.Core.AVR_Component component) {
72  if (FAButton("f0e7"))
73  {
74  AVR_Component_EventsWizard.CreateWizard(component);
75  }
76  }
77 
78 #if AVR_NET
79  public static void NetworkSetting_Button(AVR.Core.AVR_Component component) {
80  if(FAButton("f6ff")) {
81  AVR_Component_NetworkWizard.CreateWizard(component);
82  }
83  }
84 #endif
85  }
86 }
static string Unicode_to_String(int unicode)
static void Documentation_Url(string page)
static bool FAButton(string unicode, bool isBrandIcon=false, int buttonSize=25)
static void FALabel(string unicode, bool isBrandIcon=false, int buttonSize=25)
static Font GetFont(string settings_token)
static void EventsSettings_Button(AVR.Core.AVR_Component component)
static GameObject InstantiatePrefabAsChild(Transform parent, string settings_token)
static string Unicode_to_String(string unicode)