AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
EditorGUILayoutExtensions.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using System.Globalization;
6 using UnityEditor;
7 using UnityEngine;
8 
9 namespace HoloToolkit.Unity
10 {
14  public static class EditorGUILayoutExtensions
15  {
16  public static bool Button(string text, params GUILayoutOption[] options)
17  {
18  return Button(text, GUI.skin.button, options);
19  }
20 
21  public static bool Button(string text, GUIStyle style, params GUILayoutOption[] options)
22  {
23  EditorGUILayout.BeginHorizontal();
24  GUILayout.Space(EditorGUIExtensions.Indent);
25  bool pressed = GUILayout.Button(text, style, options);
26  EditorGUILayout.EndHorizontal();
27  return pressed;
28  }
29 
30  public static void Label(string text, params GUILayoutOption[] options)
31  {
32  Label(text, EditorStyles.label, options);
33  }
34 
35  public static void Label(string text, GUIStyle style, params GUILayoutOption[] options)
36  {
37  EditorGUILayout.BeginHorizontal();
38  GUILayout.Space(EditorGUIExtensions.Indent);
39  GUILayout.Label(text, style, options);
40  EditorGUILayout.EndHorizontal();
41  }
42 
43  public static T ObjectField<T>(GUIContent guiContent, T value, bool allowSceneObjects = false, GUILayoutOption[] guiLayoutOptions = null)
44  {
45  object objValue = value;
46 
47  if (objValue == null)
48  {
49  // We want to return null so we can display our blank field.
50  return (T)objValue;
51  }
52 
53  Type valueType = objValue.GetType();
54  if (valueType == typeof(Material))
55  {
56  objValue = EditorGUILayout.ObjectField(guiContent, (Material)objValue, typeof(Material), allowSceneObjects, guiLayoutOptions);
57  }
58  else if (valueType == typeof(SceneAsset))
59  {
60  objValue = EditorGUILayout.ObjectField(guiContent, (SceneAsset)objValue, typeof(SceneAsset), allowSceneObjects, guiLayoutOptions);
61  }
62  else if (objValue is UnityEngine.Object)
63  {
64  objValue = EditorGUILayout.ObjectField(guiContent, (UnityEngine.Object)objValue, valueType, allowSceneObjects, guiLayoutOptions);
65  }
66  else
67  {
68  throw new ArgumentException(
69  string.Format(
70  CultureInfo.InvariantCulture,
71  "Unimplemented value type: {0}.",
72  valueType),
73  "value");
74  }
75 
76  return (T)objValue;
77  }
78  }
79 }
static void Label(string text, GUIStyle style, params GUILayoutOption[] options)
static bool Button(string text, params GUILayoutOption[] options)
Extensions for the UnityEditor.EditorGUILayout class.
static bool Button(string text, GUIStyle style, params GUILayoutOption[] options)
UnityEngine.UI.Button Button
Extensions for the UnityEnditor.EditorGUI class.
static void Label(string text, params GUILayoutOption[] options)