Skip to content

Commit

Permalink
Merge pull request #737 from leapmotion/ie-devx-patch-fix
Browse files Browse the repository at this point in the history
Add Various DevX warnings when Importing the Interaction Engine to a Fresh Project
  • Loading branch information
testmasterbright authored Jun 10, 2017
2 parents f53ee8a + 1b7b022 commit 870fbc3
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Leap.Unity.Interaction {

[Serializable]
public class InteractionControllerSet : SerializableHashSet<InteractionController> { }

[DisallowMultipleComponent]
[ExecuteInEditMode]
public class InteractionManager : MonoBehaviour, IRuntimeGizmoComponent {
Expand All @@ -38,7 +38,7 @@ public class InteractionManager : MonoBehaviour, IRuntimeGizmoComponent {
public ReadonlyHashSet<InteractionController> interactionControllers {
get { return _interactionControllers; }
}

[Header("Interaction Settings")]

[SerializeField]
Expand Down Expand Up @@ -202,11 +202,35 @@ void OnValidate() {
if (!Application.isPlaying && _autoGenerateLayers) {
generateAutomaticLayers();
}

refreshInteractionControllers();
}

void Awake() {
#if UNITY_EDITOR
if (InteractionPreferences.shouldPrompForGravity && Application.isPlaying) {
float magnitude = Physics.gravity.y;
if (Mathf.Abs(magnitude) > InteractionPreferences.MAX_GRAVITY_MAGNITUDE) {
if (!EditorUtility.DisplayDialog("Gravity magnitude too strong!", "Your gravity magnitude is " + magnitude + " which is stronger than the recommended value of -4.905!\n\nGo to Edit->Project Settings->Physics to change the magnitude.", "Ok", "Don't Show Again")) {
InteractionPreferences.shouldPrompForGravity = false;
}
EditorApplication.isPlaying = false;
return;
}
}

if (InteractionPreferences.shouldPrompForPhysicsTimestep && Application.isPlaying) {
if (Time.fixedDeltaTime > InteractionPreferences.MAX_TIMESTEP + Mathf.Epsilon) {
float roundedTimestep = (float)Math.Round(InteractionPreferences.MAX_TIMESTEP, 4);
if (!EditorUtility.DisplayDialog("Timestep too slow!", "Your fixed timestep is " + Time.fixedDeltaTime + ", which is slower than the recommended value of " + roundedTimestep + ".\n\nGo to Edit->ProjectSettings->Time to change the fixed timestep.", "Ok", "Don't Show Again")) {
InteractionPreferences.shouldPrompForPhysicsTimestep = false;
}
EditorApplication.isPlaying = false;
return;
}
}
#endif

refreshInteractionControllers();

if (!Application.isPlaying) return;
Expand All @@ -221,21 +245,21 @@ void Awake() {
_prevPosition = this.transform.position;
_prevRotation = this.transform.rotation;

#if UNITY_EDITOR
#if UNITY_EDITOR
if (_drawControllerRuntimeGizmos == true) {
if (FindObjectOfType<RuntimeGizmoManager>() == null) {
Debug.LogWarning("'_drawControllerRuntimeGizmos' is enabled, but there is no "
+ "RuntimeGizmoManager in your scene. Please add one if you'd "
+ "like to render gizmos in the editor and in your headset.");
}
}
#endif
#endif
}

void OnDisable() {
#if UNITY_EDITOR
#if UNITY_EDITOR
if (!Application.isPlaying) return;
#endif
#endif

foreach (var intController in _interactionControllers) {
// Disables the colliders in the interaction controller;
Expand All @@ -249,24 +273,24 @@ void OnDisable() {
}

void Update() {
#if UNITY_EDITOR
#if UNITY_EDITOR
refreshInteractionControllers();
#endif
#endif
}

void FixedUpdate() {
OnPrePhysicalUpdate();

refreshInteractionControllers();

#if UNITY_EDITOR
#if UNITY_EDITOR
if (!Application.isPlaying) return;
#endif
#endif

using (new ProfilerSample("Interaction Manager FixedUpdate", this.gameObject)) {
// Ensure scale information is up-to-date.
_scale = this.transform.lossyScale.x;

// Update each interaction controller (Leap hands or supported VR controllers).
fixedUpdateInteractionControllers();

Expand Down Expand Up @@ -521,7 +545,7 @@ private void checkSustainingGrasps(ReadonlyHashSet<InteractionController> intera
contactedObject.StayGrasped(contactingIntControllers);
});
}

private delegate bool StateChangeCheckFunc(InteractionController controller, out IInteractionBehaviour obj);
private delegate bool MultiStateChangeCheckFunc(InteractionController controller, out HashSet<IInteractionBehaviour> objs);

Expand All @@ -536,7 +560,7 @@ private void remapInteractionObjectStateChecks(ReadonlyHashSet<InteractionContro
Action<IInteractionBehaviour, List<InteractionController>> actionPerInteractionObject) {

// Ensure the object->controllers buffer is non-null (ThreadStatic quirk) and clean.
if (s_objControllersMap == null) s_objControllersMap = new Dictionary<IInteractionBehaviour,List<InteractionController>>();
if (s_objControllersMap == null) s_objControllersMap = new Dictionary<IInteractionBehaviour, List<InteractionController>>();
s_objControllersMap.Clear();

// In a nutshell, this remaps methods per-controller that output an interaction object if the controller changed that object's state
Expand Down Expand Up @@ -714,7 +738,7 @@ public bool hasMovingFrameOfReference {
}

// Support for a moving frame of reference.
private Vector3 _prevPosition = Vector3.zero;
private Vector3 _prevPosition = Vector3.zero;
private Quaternion _prevRotation = Quaternion.identity;

private void updateMovingFrameOfReferenceSupport() {
Expand All @@ -728,8 +752,8 @@ private void updateMovingFrameOfReferenceSupport() {
/// frame of reference is moving.
/// </summary>
public void TransformAheadByFixedUpdate(Vector3 position, Quaternion rotation, out Vector3 newPosition, out Quaternion newRotation) {
Vector3 worldDisplacement = this.transform.position - _prevPosition;
Quaternion worldRotation = this.transform.rotation * Quaternion.Inverse(_prevRotation);
Vector3 worldDisplacement = this.transform.position - _prevPosition;
Quaternion worldRotation = this.transform.rotation * Quaternion.Inverse(_prevRotation);
newPosition = ((worldRotation * (position - this.transform.position + worldDisplacement))) + this.transform.position;
newRotation = worldRotation * rotation;
}
Expand Down Expand Up @@ -780,11 +804,9 @@ protected void generateAutomaticLayers() {
if (string.IsNullOrEmpty(layerName)) {
if (_interactionLayer == -1) {
_interactionLayer = i;
}
else if (_interactionNoContactLayer == -1) {
} else if (_interactionNoContactLayer == -1) {
_interactionNoContactLayer = i;
}
else if (_contactBoneLayer == -1) {
} else if (_contactBoneLayer == -1) {
_contactBoneLayer = i;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,12 @@ private void fixedUpdateGraspButtonState() {

if (!_graspButtonLastFrame) {
if (graspAxisOverride == null) {
graspButton = Input.GetAxis(graspButtonAxis) > graspDepressedValue;
try {
graspButton = Input.GetAxis(graspButtonAxis) > graspDepressedValue;
} catch {
Debug.LogError("INPUT AXIS NOT SET UP. Go to your Input Manager and add a definition for " + graspButtonAxis + " on the " + (isLeft ? "9" : "10") + "th Joystick Axis.");
graspButton = Input.GetKey(isLeft ? KeyCode.JoystickButton14: KeyCode.JoystickButton15);
}
}
else {
graspButton = graspAxisOverride() > graspDepressedValue;
Expand All @@ -570,7 +575,12 @@ private void fixedUpdateGraspButtonState() {
}

if (graspAxisOverride == null) {
graspButton = Input.GetAxis(graspButtonAxis) > graspReleasedValue;
try {
graspButton = Input.GetAxis(graspButtonAxis) > graspDepressedValue;
} catch {
Debug.LogError("INPUT AXIS NOT SET UP. Go to your Input Manager and add a definition for " + graspButtonAxis + " on the " + (isLeft ? "9" : "10") + "th Joystick Axis.");
graspButton = Input.GetKey(isLeft ? KeyCode.JoystickButton14 : KeyCode.JoystickButton15);
}
}
else {
graspButton = graspAxisOverride() > graspReleasedValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Leap.Unity.Interaction.Internal {

#if UNITY_EDITOR
public static class InteractionPreferences {
public const float MAX_GRAVITY_MAGNITUDE = 4.905f;

#if UNITY_ANDROID
public const float MAX_TIMESTEP = 1.0f / 60.0f;
#else
public const float MAX_TIMESTEP = 1.0f / 90.0f;
#endif

public const string PROMPT_FOR_GRAVITY_KEY = "InteractionEngine_ShouldPrompForGravity";
public const string PROMPT_FOR_PHYSICS_TIMESTEP = "InteractionEngine_ShouldPrompForTimestep";

private static GUIContent _gravityPrompContent;
private static GUIContent _timestepPrompContent;

static InteractionPreferences() {
_gravityPrompContent = new GUIContent("Validate Gravity Magnitude", "Should prompt the user if the magnitude of the gravity vector is higher than the recommended amount?");
_timestepPrompContent = new GUIContent("Validate Physics Timestep", "Should prompt the user if the physics timestep is larger then the recommended value?");
}

public static bool shouldPrompForGravity {
get {
return EditorPrefs.GetBool(PROMPT_FOR_GRAVITY_KEY, defaultValue: true);
}
set {
EditorPrefs.SetBool(PROMPT_FOR_GRAVITY_KEY, value);
}
}

public static bool shouldPrompForPhysicsTimestep {
get {
return EditorPrefs.GetBool(PROMPT_FOR_PHYSICS_TIMESTEP, defaultValue: true);
}
set {
EditorPrefs.SetBool(PROMPT_FOR_PHYSICS_TIMESTEP, value);
}
}

[PreferenceItem("Leap Interaction")]
private static void preferencesGUI() {
bool newGravityValue = EditorGUILayout.Toggle(_gravityPrompContent, shouldPrompForGravity);
if (newGravityValue != shouldPrompForGravity) {
shouldPrompForGravity = newGravityValue;
}

bool newTimestepValue = EditorGUILayout.Toggle(_timestepPrompContent, shouldPrompForPhysicsTimestep);
if (newTimestepValue != shouldPrompForPhysicsTimestep) {
shouldPrompForPhysicsTimestep = newTimestepValue;
}
}
}
#endif
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 870fbc3

Please sign in to comment.