AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ShaderGUIUtils.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 UnityEngine;
5 using UnityEditor;
6 
7 namespace HoloToolkit.Unity
8 {
12  public static class ShaderGUIUtils
13  {
14  public static readonly GUILayoutOption[] GUILayoutEmptyArray = new GUILayoutOption[0];
15 
16  public static int IndentAmount = 1;
17 
18  //re-implementation of MaterialEditor internal
19  public static Rect GetControlRectForSingleLine()
20  {
21  return EditorGUILayout.GetControlRect(true, 18f, EditorStyles.layerMaskField, GUILayoutEmptyArray);
22  }
23 
24  //re-implementation of EditorGUI internal
25  public static void GetRectsForMiniThumbnailField(Rect position, out Rect thumbRect, out Rect labelRect)
26  {
27  thumbRect = EditorGUI.IndentedRect(position);
28  thumbRect.y -= 1f;
29  thumbRect.height = 18f;
30  thumbRect.width = 32f;
31  float num = thumbRect.x + 30f;
32  labelRect = new Rect(num, position.y, thumbRect.x + EditorGUIUtility.labelWidth - num, position.height);
33  }
34 
35  public static void BeginHeaderProperty(MaterialEditor matEditor, string headerText, MaterialProperty prop)
36  {
37  matEditor.ShaderProperty(prop, GUIContent.none);
38  var rect = GUILayoutUtility.GetLastRect();
39  EditorGUI.indentLevel += IndentAmount;
40  EditorGUI.LabelField(rect, headerText, EditorStyles.boldLabel);
41  }
42 
43  public static void BeginHeader(string headerText)
44  {
45  EditorGUILayout.LabelField(headerText, EditorStyles.boldLabel);
46  EditorGUI.indentLevel += IndentAmount;
47  }
48 
49  public static void EndHeader()
50  {
51  EditorGUI.indentLevel -= IndentAmount;
52  }
53 
54  public static void HeaderSeparator()
55  {
56  EditorGUILayout.Separator();
57  EditorGUILayout.Separator();
58  }
59 
60  public static void SetKeyword(Material mat, string keyword, bool state)
61  {
62  if (state)
63  {
64  mat.EnableKeyword(keyword);
65  }
66  else
67  {
68  mat.DisableKeyword(keyword);
69  }
70  }
71 
72  public static bool TryGetToggle(Material material, string property, bool defaultVal)
73  {
74  if (material.HasProperty(property))
75  {
76  return material.GetFloat(property) == 1.0f;
77  }
78  return defaultVal;
79  }
80  }
81 }
static bool TryGetToggle(Material material, string property, bool defaultVal)
static void BeginHeaderProperty(MaterialEditor matEditor, string headerText, MaterialProperty prop)
static void BeginHeader(string headerText)
static void GetRectsForMiniThumbnailField(Rect position, out Rect thumbRect, out Rect labelRect)
static void SetKeyword(Material mat, string keyword, bool state)
Helper class for custom shader editors