forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoConfigureWindow.cs
More file actions
166 lines (144 loc) · 4.83 KB
/
AutoConfigureWindow.cs
File metadata and controls
166 lines (144 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace HoloToolkit.Unity
{
/// <summary>
/// Base class for auto configuration build windows.
/// </summary>
public abstract class AutoConfigureWindow<TSetting> : EditorWindow
{
#region Member Variables
private Dictionary<TSetting, bool> values = new Dictionary<TSetting, bool>();
private Dictionary<TSetting, string> names = new Dictionary<TSetting, string>();
private Dictionary<TSetting, string> descriptions = new Dictionary<TSetting, string>();
private string statusMessage = string.Empty;
private Vector2 scrollPosition = Vector2.zero;
private GUIStyle wrapStyle;
#endregion // Member Variables
#region Internal Methods
private void SettingToggle(TSetting setting)
{
// Draw and update setting flag
values[setting] = GUILayout.Toggle(values[setting], new GUIContent(names[setting]));
// If this control is the one under the mouse, update the status message
if ((Event.current.type == EventType.Repaint) && (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)))
{
StatusMessage = descriptions[setting];
Repaint();
}
}
#endregion // Internal Methods
#region Overridables / Event Triggers
/// <summary>
/// Called when settings should be applied.
/// </summary>
protected abstract void ApplySettings();
/// <summary>
/// Called when settings should be loaded.
/// </summary>
protected abstract void LoadSettings();
/// <summary>
/// Called when string names and descriptions should be loaded.
/// </summary>
protected abstract void LoadStrings();
#endregion // Overridables / Event Triggers
#region Overrides / Event Handlers
/// <summary>
/// Called when the window is created.
/// </summary>
protected virtual void Awake()
{
wrapStyle = new GUIStyle() { wordWrap = true };
}
protected virtual void OnEnable()
{
LoadStrings();
LoadSettings();
}
/// <summary>
/// Renders the GUI
/// </summary>
protected virtual void OnGUI()
{
// Begin Settings Section
GUILayout.BeginVertical(EditorStyles.helpBox);
// Individual Settings
var keys = values.Keys.ToArray();
for (int iKey = 0; iKey < keys.Length; iKey++)
{
SettingToggle(keys[iKey]);
}
// End Settings Section
GUILayout.EndVertical();
// Status box area
GUILayout.BeginVertical(EditorStyles.helpBox);
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
GUILayout.Label(statusMessage, wrapStyle);
GUILayout.EndScrollView();
GUILayout.EndVertical();
// Apply button
GUILayout.BeginVertical(EditorStyles.miniButtonRight);
bool applyClicked = GUILayout.Button("Apply");
GUILayout.EndVertical();
// Clicked?
if (applyClicked)
{
ApplySettings();
Close();
}
}
#endregion // Overrides / Event Handlers
#region Public Properties
/// <summary>
/// Gets the descriptions of the settings.
/// </summary>
public Dictionary<TSetting, string> Descriptions
{
get
{
return descriptions;
}
set
{
descriptions = value;
}
}
/// <summary>
/// Gets the names of the settings.
/// </summary>
public Dictionary<TSetting, string> Names
{
get
{
return names;
}
set
{
names = value;
}
}
/// <summary>
/// Gets the values of the settings.
/// </summary>
public Dictionary<TSetting, bool> Values
{
get
{
return values;
}
set
{
values = value;
}
}
/// <summary>
/// Gets or sets the status message displayed at the bottom of the window.
/// </summary>
public string StatusMessage { get { return statusMessage; } set { statusMessage = value; } }
#endregion // Public Properties
}
}