AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
AutoConfigureWindow.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.Collections.Generic;
5 using System.Linq;
6 using UnityEditor;
7 using UnityEngine;
8 
9 namespace HoloToolkit.Unity
10 {
14  public abstract class AutoConfigureWindow<TSetting> : EditorWindow
15  {
16  #region Member Fields
17 
18  private Dictionary<TSetting, bool> values = new Dictionary<TSetting, bool>();
19  private Dictionary<TSetting, string> names = new Dictionary<TSetting, string>();
20  private Dictionary<TSetting, string> descriptions = new Dictionary<TSetting, string>();
21 
22  private string statusMessage = string.Empty;
23  private Vector2 scrollPosition = Vector2.zero;
24  private GUIStyle wrapStyle;
25 
26  #endregion // Member Fields
27 
28  #region Internal Methods
29 
30  private void SettingToggle(TSetting setting)
31  {
32  EditorGUI.BeginChangeCheck();
33 
34  // Draw and update setting flag
35  values[setting] = GUILayout.Toggle(values[setting], new GUIContent(names[setting]));
36 
37  if (EditorGUI.EndChangeCheck())
38  {
39  OnGuiChanged();
40  }
41 
42  // If this control is the one under the mouse, update the status message
43  if (Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
44  {
45  StatusMessage = descriptions[setting];
46  Repaint();
47  }
48  }
49 
53  private string StatusMessage { get { return statusMessage; } set { statusMessage = value; } }
54 
58  private void SelectAll()
59  {
60  var keys = values.Keys.ToArray();
61  for (int iKey = 0; iKey < keys.Length; iKey++)
62  {
63  Values[keys[iKey]] = true;
64  }
65  }
66 
70  private void SelectNone()
71  {
72  var keys = values.Keys.ToArray();
73  for (int iKey = 0; iKey < keys.Length; iKey++)
74  {
75  Values[keys[iKey]] = false;
76  }
77  }
78 
79  #endregion // Internal Methods
80 
81  #region Overridables / Event Triggers
82 
86  protected abstract void ApplySettings();
87 
91  protected abstract void LoadSettings();
92 
96  protected abstract void LoadStrings();
97 
101  protected abstract void OnGuiChanged();
102 
103  #endregion // Overridables / Event Triggers
104 
105  #region Overrides / Event Handlers
106 
110  protected virtual void Awake()
111  {
112  wrapStyle = new GUIStyle("label")
113  {
114  wordWrap = true,
115  richText = true
116  };
117  }
118 
119  protected virtual void OnEnable()
120  {
121  LoadStrings();
122  LoadSettings();
123  }
124 
128  protected virtual void OnGUI()
129  {
130  // Begin Settings Section
131  GUILayout.BeginVertical(EditorStyles.helpBox);
132 
133  // Individual Settings
134  var keys = values.Keys.ToArray();
135  for (int iKey = 0; iKey < keys.Length; iKey++)
136  {
137  SettingToggle(keys[iKey]);
138  }
139 
140  // End Settings Section
141  GUILayout.EndVertical();
142 
143  // Status box area
144  GUILayout.BeginVertical(EditorStyles.helpBox);
145  scrollPosition = GUILayout.BeginScrollView(scrollPosition);
146  GUILayout.Label(statusMessage, wrapStyle);
147  GUILayout.EndScrollView();
148  GUILayout.EndVertical();
149 
150  // Buttons
151  GUILayout.BeginHorizontal(EditorStyles.miniButtonRight);
152  bool selectAllClicked = GUILayout.Button("Select All");
153  bool selectNoneClicked = GUILayout.Button("Select None");
154  bool applyClicked = GUILayout.Button("Apply");
155  GUILayout.EndHorizontal();
156 
157  // Clicked?
158  if (selectAllClicked)
159  {
160  SelectAll();
161  }
162 
163  if (selectNoneClicked)
164  {
165  SelectNone();
166  }
167 
168  if (applyClicked)
169  {
170  ApplySettings();
171  }
172  }
173 
174  #endregion // Overrides / Event Handlers
175 
176  #region Protected Properties
177 
181  protected Dictionary<TSetting, string> Descriptions
182  {
183  get
184  {
185  return descriptions;
186  }
187 
188  set
189  {
190  descriptions = value;
191  }
192  }
193 
197  protected Dictionary<TSetting, string> Names
198  {
199  get
200  {
201  return names;
202  }
203 
204  set
205  {
206  names = value;
207  }
208  }
209 
213  protected Dictionary<TSetting, bool> Values
214  {
215  get
216  {
217  return values;
218  }
219 
220  set
221  {
222  values = value;
223  }
224  }
225 
226  #endregion // Protected Properties
227  }
228 }
virtual void Awake()
Called when the window is created.
virtual void OnGUI()
Renders the GUI
Base class for auto configuration build windows.