11using System.Collections.Generic;
12using System.Reflection;
35 [AttributeUsage(AttributeTargets.Method, AllowMultiple =
false)]
50 public static class LeapProjectChecks {
52 private struct ProjectCheck {
53 public Func<bool> checkFunc;
57 private static List<ProjectCheck> _projectChecks =
null;
59 private static void ensureChecksLoaded() {
60 if (_projectChecks !=
null) {
64 _projectChecks =
new List<ProjectCheck>();
66 var assemblies = AppDomain.CurrentDomain.GetAssemblies();
67 foreach (var type
in assemblies.Query().SelectMany(a => a.GetTypes())) {
68 foreach (var method
in type.GetMethods(BindingFlags.Public
69 | BindingFlags.NonPublic
70 | BindingFlags.Static)) {
71 var attributes = method.GetCustomAttributes(typeof(LeapProjectCheckAttribute),
73 if (attributes.Length == 0) {
77 var attribute = attributes[0] as LeapProjectCheckAttribute;
78 _projectChecks.Add(
new ProjectCheck() {
80 if (!method.IsStatic) {
81 Debug.LogError(
"Invalid project check definition; project checks must "
82 +
"be static methods.");
85 else if (method.ReturnType == typeof(
bool)) {
86 return (
bool)method.Invoke(
null,
null);
97 _projectChecks.Sort((a, b) => a.attribute.order.CompareTo(b.attribute.order));
104 public static void DrawProjectChecksGUI() {
106 ensureChecksLoaded();
108 bool allChecksPassed =
true;
109 foreach (var projectCheck
in _projectChecks) {
111 using (
new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) {
112 allChecksPassed &= projectCheck.checkFunc();
117 if (_ignoredKeys !=
null && _ignoredKeys.Count > 0) {
118 EditorGUILayout.Space();
119 using (
new EditorGUILayout.HorizontalScope()) {
120 GUILayout.FlexibleSpace();
122 using (
new EditorGUILayout.VerticalScope()) {
124 GUILayout.Label(
"Some project checks have been ignored.");
127 if (GUILayout.Button(
new GUIContent(
"Reset Ignore Flags",
128 "Un-ignore any project checks that have been ignored."))) {
129 ClearAllIgnoredKeys();
132 EditorGUILayout.Space();
138 #region Ignored Keys via Editor Prefs
140 private const string IGNORED_KEYS_PREF =
"LeapUnityWindow_IgnoredKeys";
143 private static HashSet<string> _backingIgnoredKeys =
null;
146 private static HashSet<string> _ignoredKeys {
149 if (_backingIgnoredKeys ==
null) {
151 = splitBySemicolonToSet(EditorPrefs.GetString(IGNORED_KEYS_PREF));
153 return _backingIgnoredKeys;
160 public static bool CheckIgnoredKey(
string editorPrefKey) {
162 return _ignoredKeys.Contains(editorPrefKey);
168 public static void SetIgnoredKey(
string editorPrefKey,
bool ignore) {
171 _ignoredKeys.Add(editorPrefKey);
174 _ignoredKeys.Remove(editorPrefKey);
177 uploadignoredKeyChangesToEditorPrefs();
181 public static void ClearAllIgnoredKeys() {
183 _ignoredKeys.Clear();
185 uploadignoredKeyChangesToEditorPrefs();
193 private static HashSet<string> splitBySemicolonToSet(
string ignoredKeys_semicolonDelimited) {
194 var keys = ignoredKeys_semicolonDelimited;
195 var
set =
new HashSet<string>();
196 foreach (var key
in keys.Split(
new char[] {
';' },
197 StringSplitOptions.RemoveEmptyEntries)) {
203 private static string joinBySemicolon(HashSet<string> keys) {
204 return string.Join(
";", keys.Query().ToArray());
207 private static void uploadignoredKeyChangesToEditorPrefs() {
209 EditorPrefs.SetString(IGNORED_KEYS_PREF, joinBySemicolon(_ignoredKeys));
Add this attribute to a settings check. This method will be called often while the Leap Motion Unity ...
LeapProjectCheckAttribute(string header, int order)