18 public static class InteractionChecks {
19 public const float MAX_GRAVITY_MAGNITUDE = 4.905f;
22 public const float MAX_TIMESTEP = 1.0f / 60.0f;
24 public const float MAX_TIMESTEP = 1.0f / 90.0f;
27 private const string IGNORE_GRAVITY_CHECK_KEY =
"LeapIEIgnoreGravityCheck";
28 private const string IGNORE_TIMESTEP_CHECK_KEY =
"LeapIEIgnoreTimestepCheck";
29 private const string IGNORE_RIGID_HANDS_CHECK_KEY =
"LeapIEIgnoreRigidHandsCheck";
31 private const string SHOULD_LAUNCH_FOR_IE =
"LeapWindowPanelShouldLaunchForIE";
33 [InitializeOnLoadMethod]
34 private static void init() {
35 EditorApplication.delayCall += () =>
37 EditorPrefs.SetBool(SHOULD_LAUNCH_FOR_IE,
false);
38 if (EditorPrefs.GetBool(SHOULD_LAUNCH_FOR_IE, defaultValue:
true)) {
39 EditorPrefs.SetBool(SHOULD_LAUNCH_FOR_IE,
false);
44 EditorApplication.playModeStateChanged -= onPlayModeStateChanged;
45 EditorApplication.playModeStateChanged += onPlayModeStateChanged;
48 private static void onPlayModeStateChanged(PlayModeStateChange stateChange) {
49 if (stateChange == PlayModeStateChange.EnteredPlayMode) {
50 bool allChecksPassed = runAllChecks_NoGUI();
52 if (!allChecksPassed) {
58 [LeapProjectCheck(
"Interaction Engine", 10)]
59 public static bool CheckInteractionSettings() {
60 EditorGUILayout.LabelField(
"Interaction Engine", EditorStyles.boldLabel);
62 bool allChecksPassed = runAllChecks_WithGUI();
64 EditorGUILayout.Space();
66 if (allChecksPassed) {
67 EditorGUILayout.HelpBox(
"All settings are good for the Interaction Engine!",
74 #region Run All Checks
76 private static bool runAllChecks_NoGUI() {
77 bool allChecksPassed =
true;
79 allChecksPassed &= checkGravity();
81 allChecksPassed &= checkTimeStep();
83 allChecksPassed &= checkRigidHands();
85 return allChecksPassed;
88 private static bool runAllChecks_WithGUI() {
89 bool allChecksPassed =
true;
91 allChecksPassed &= checkGravityAndDrawGUI();
93 allChecksPassed &= checkTimeStepAndDrawGUI();
95 allChecksPassed &= checkRigidHandsAndDrawGUI();
97 if (!allChecksPassed && Application.isPlaying) {
98 EditorGUILayout.Space();
100 EditorGUILayout.HelpBox(
"Editor is currently in play-mode, so any project setting "
101 +
"changes will be reverted upon returning to edit-mode. You should return to "
102 +
"edit-mode if you want auto-fixes to stick.", MessageType.Warning);
105 return allChecksPassed;
110 #region Check Gravity
112 private static bool checkGravity() {
113 if (LeapProjectChecks.CheckIgnoredKey(IGNORE_GRAVITY_CHECK_KEY)) {
117 if (Mathf.Abs(
Physics.gravity.y) > MAX_GRAVITY_MAGNITUDE) {
125 private static bool checkGravityAndDrawGUI() {
126 var gravityOK = checkGravity();
130 EditorGUILayout.Space();
132 using (
new EditorGUILayout.HorizontalScope()) {
133 EditorGUILayout.HelpBox(
"Your gravity magnitude is " +
Physics.gravity.y
134 +
" which is stronger than the recommended value "
135 +
"of -4.905!\n\nGo to Edit/Project Settings/Physics "
136 +
"to change the magnitude.", MessageType.Warning);
138 if (GUILayout.Button(
"Auto-fix")) {
139 Physics.gravity = Vector3.down * MAX_GRAVITY_MAGNITUDE;
142 if (GUILayout.Button(
"Ignore")) {
143 LeapProjectChecks.SetIgnoredKey(IGNORE_GRAVITY_CHECK_KEY, ignore:
true);
153 #region Check Timestep
155 private static bool checkTimeStep() {
156 if (LeapProjectChecks.CheckIgnoredKey(IGNORE_TIMESTEP_CHECK_KEY)) {
160 if (Time.fixedDeltaTime > MAX_TIMESTEP + Mathf.Epsilon) {
168 private static bool checkTimeStepAndDrawGUI() {
169 var timeStepOK = checkTimeStep();
172 float roundedTimestep = (float)
Math.Round(MAX_TIMESTEP, 4);
174 EditorGUILayout.Space();
176 using (
new EditorGUILayout.HorizontalScope()) {
177 EditorGUILayout.HelpBox(
178 "Your fixed timestep is " + Time.fixedDeltaTime +
179 ", which is slower than the recommended value " +
180 "of " + roundedTimestep +
".\n\nGo to Edit/Project Settings/Time " +
181 "to change the fixed timestep.", MessageType.Warning);
183 if (GUILayout.Button(
"Auto-fix")) {
184 Time.fixedDeltaTime = roundedTimestep;
187 if (GUILayout.Button(
"Ignore")) {
188 LeapProjectChecks.SetIgnoredKey(IGNORE_TIMESTEP_CHECK_KEY, ignore:
true);
198 #region Check Rigid Hands
200 private static bool checkRigidHands() {
201 var unusedRigidHandObjects = (GameObject[])
null;
202 return checkRigidHands(out unusedRigidHandObjects);
205 private static bool checkRigidHands(out GameObject[] rigidHandObjects) {
206 if (LeapProjectChecks.CheckIgnoredKey(IGNORE_RIGID_HANDS_CHECK_KEY)) {
207 rigidHandObjects =
null;
212 .Select(x => x.gameObject).ToArray();
213 if (rigidHandObjects.Length != 0
222 private static bool checkRigidHandsAndDrawGUI() {
223 var rigidHandObjects = (GameObject[])
null;
224 var rigidHandsOK = checkRigidHands(out rigidHandObjects);
228 EditorGUILayout.Space();
230 using (
new EditorGUILayout.HorizontalScope()) {
231 EditorGUILayout.HelpBox(
232 "Rigid Hands AND an Interaction Manager are present in your scene. " +
233 "Rigid Hands are not compatible with the Interaction Engine and should " +
234 "never be used in tandem with it. You should remove them " +
235 "from your scene.", MessageType.Warning);
237 if (GUILayout.Button(
new GUIContent(
"Select Rigid Hands",
238 "Select RigidHand objects in the current scene."),
239 GUILayout.ExpandHeight(
true), GUILayout.MaxHeight(40F))) {
240 Selection.objects = rigidHandObjects;
243 if (GUILayout.Button(
"Ignore")) {
244 LeapProjectChecks.SetIgnoredKey(IGNORE_RIGID_HANDS_CHECK_KEY, ignore:
true);
UnityEngine.Object UnityObject
A Query object is a type of immutable ordered collection of elements that can be used to perform usef...