diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseGrabbable.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseGrabbable.cs index ebb750b901a..34c3579e564 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseGrabbable.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseGrabbable.cs @@ -1,36 +1,24 @@ -using System; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; - -/// -/// //Intended Usage// -/// Attach a "grabbable_x" script (a script that inherits from this) to any object that is meant to be grabbed -/// create more specific grab behavior by adding additional scripts/components to the game object, such as scalableObject, rotatableObject, throwableObject -/// - -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { - public enum GrabStateEnum - { - Inactive, - Single, - Multi, - } - - public enum GrabStyleEnum - { - Exclusive, - Multi - } - + /// + /// //Intended Usage// + /// Attach a "grabbable_x" script (a script that inherits from this) to any object that is meant to be grabbed + /// create more specific grab behavior by adding additional scripts/components to the game object, such as scalableObject, rotatableObject, throwableObject + /// public abstract class BaseGrabbable : MonoBehaviour { - public Action OnGrabStateChange; - public Action OnContactStateChange; - public Action OnGrabbed; - public Action OnReleased; + public event Action OnGrabStateChange; + public event Action OnContactStateChange; + public event Action OnGrabbed; + public event Action OnReleased; public BaseGrabber GrabberPrimary { @@ -40,7 +28,6 @@ public BaseGrabber GrabberPrimary } } - public BaseGrabber[] ActiveGrabbers { get @@ -65,11 +52,11 @@ public GrabStateEnum GrabState get { if (activeGrabbers.Count > 1) + { return GrabStateEnum.Multi; - else if (activeGrabbers.Count > 0) - return GrabStateEnum.Single; - else - return GrabStateEnum.Inactive; + } + + return activeGrabbers.Count > 0 ? GrabStateEnum.Single : GrabStateEnum.Inactive; } } @@ -89,7 +76,32 @@ public GrabStateEnum ContactState } } - public virtual bool TryGrabWith (BaseGrabber grabber) + /// + /// Grabbers that could potentially grab this object + /// This list is maintained by the grabbers + /// + protected HashSet availableGrabbers = new HashSet(); + + /// + /// Grabbers that are currently grabbing this object + /// The top-most grabber is the primary grabber + /// + protected List activeGrabbers = new List(); + + //left protected unless we have the occasion to use them publicly, then switch to public access + [SerializeField] + protected Transform grabSpot; + + [SerializeField] + protected GrabStyleEnum grabStyle = GrabStyleEnum.Exclusive; + + private GrabStateEnum prevGrabState = GrabStateEnum.Inactive; + private GrabStateEnum prevContactState = GrabStateEnum.Inactive; + private Vector3 velocity; + private Vector3 averageVelocity; + private Vector3 previousVel; + + public virtual bool TryGrabWith(BaseGrabber grabber) { // TODO error checking, mult-grab checking if (GrabState != GrabStateEnum.Inactive) @@ -104,14 +116,17 @@ public virtual bool TryGrabWith (BaseGrabber grabber) // Remove from grabbable list and detatch activeGrabbers.Remove(primary); DetachFromGrabber(primary); - } else { + } + else + { // If we can't, it's a no-go return false; } break; - - default: + case GrabStyleEnum.Multi: break; + default: + throw new ArgumentOutOfRangeException(); } } @@ -136,6 +151,7 @@ public void RemoveContact(BaseGrabber availableObject) } //the next three functions provide basic behaviour. Extend from this base script in order to provide more specific functionality. + protected virtual void AttachToGrabber(BaseGrabber grabber) { // By default this does nothing @@ -164,18 +180,19 @@ protected virtual void StartGrab(BaseGrabber grabber) // Otherwise just push the grabber activeGrabbers.Add(grabber); } + // Attach ourselves to this grabber AttachToGrabber(grabber); if (OnGrabbed != null) + { OnGrabbed(this); + } } /// /// As long as the grabber script (usually attached to the controller, but not always) reports more than one grabber, /// we stay inside of StayGrab. /// - /// - /// protected virtual IEnumerator StayGrab() { yield return null; @@ -191,19 +208,22 @@ protected virtual IEnumerator StayGrab() { Debug.Log("no longer being grabbed by active grabber"); if (activeGrabbers[i] != null) + { DetachFromGrabber(activeGrabbers[i]); + } + activeGrabbers.RemoveAt(i); } } yield return null; } + EndGrab(); } /// /// Grab end fires off a GrabEnded event, but also cleans up some of the variables associated with an active grab, such /// as which grabber was grabbing this object and so forth. /// - /// protected virtual void EndGrab() { if (OnReleased != null) @@ -217,17 +237,16 @@ protected virtual void EndGrab() /// protected virtual void OnGrabStay() { - } protected virtual void Start() { - } protected virtual void Update() { - if (prevGrabState != GrabState && OnGrabStateChange != null) { + if (prevGrabState != GrabState && OnGrabStateChange != null) + { Debug.Log("Calling on grab change in grabbable"); OnGrabStateChange(this); } @@ -240,31 +259,6 @@ protected virtual void Update() prevGrabState = GrabState; prevContactState = ContactState; - } - - - /// - /// Grabbers that could potentially grab this object - /// This list is maintained by the grabbers - /// - protected HashSet availableGrabbers = new HashSet(); - /// - /// Grabbers that are currently grabbing this object - /// The top-most grabber is the primary grabber - /// - protected List activeGrabbers = new List(); - - //left protected unless we have the occasion to use them publicly, then switch to public access - [SerializeField] - protected Transform grabSpot; - [SerializeField] - protected GrabStyleEnum grabStyle = GrabStyleEnum.Exclusive; - - private GrabStateEnum prevGrabState = GrabStateEnum.Inactive; - private GrabStateEnum prevContactState = GrabStateEnum.Inactive; - private Vector3 velocity; - private Vector3 averageVelocity; - private Vector3 previousVel; } } \ No newline at end of file diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseGrabber.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseGrabber.cs index 6307b42ca7e..bbd76016e7b 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseGrabber.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseGrabber.cs @@ -1,32 +1,21 @@ -using System; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR.WSA.Input; - -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { - public struct ControllerReleaseData - { - public Vector3 vel; - public Vector3 angVel; - - public ControllerReleaseData(Vector3 _vel, Vector3 _angVel) - { - vel = _vel; - angVel = _angVel; - } - } - - /// /// Intended usage: scripts that inherit from this can be attached to the controller, or any object with a collider /// that needs to be grabbing or carrying other objects. /// public abstract class BaseGrabber : MonoBehaviour { - public Action OnGrabStateChange; - public Action OnContactStateChange; + public event Action OnGrabStateChange; + public event Action OnContactStateChange; public InteractionSourceHandedness Handedness { get { return handedness; } set { handedness = value; } } @@ -38,11 +27,11 @@ public GrabStateEnum GrabState get { if (grabbedObjects.Count > 1) + { return GrabStateEnum.Multi; - else if (grabbedObjects.Count > 0) - return GrabStateEnum.Single; - else - return GrabStateEnum.Inactive; + } + + return grabbedObjects.Count > 0 ? GrabStateEnum.Single : GrabStateEnum.Inactive; } } @@ -60,7 +49,7 @@ public GrabStateEnum ContactState } /// - /// If not grabattachpoint is specified, use the gameobject transform by default + /// If not grab attach point is specified, use the GameObject transform by default /// public Transform GrabHandle { @@ -72,7 +61,24 @@ public Transform GrabHandle public float Strength { get { return strength; } } - public bool IsGrabbing (BaseGrabbable grabbable) + [SerializeField] + protected Transform grabAttachSpot; + + [SerializeField] + protected float strength = 1.0f; + + protected HashSet grabbedObjects = new HashSet(); + protected List contactObjects = new List(); + + protected float grabForgivenessRadius; + + private GrabStateEnum prevGrabState = GrabStateEnum.Inactive; + private GrabStateEnum prevContactState = GrabStateEnum.Inactive; + + [SerializeField] + protected InteractionSourceHandedness handedness; + + public bool IsGrabbing(BaseGrabbable grabbable) { return grabbedObjects.Contains(grabbable); } @@ -81,28 +87,30 @@ public bool IsGrabbing (BaseGrabbable grabbable) /// Attempts to transfer ownership of grabbable object to another grabber /// Can override to 'lock' objects to a grabber, if desired /// - /// - /// + /// + /// /// - public virtual bool CanTransferOwnershipTo(BaseGrabbable grabbable, BaseGrabber otherGrabber) + public virtual bool CanTransferOwnershipTo(BaseGrabbable ownerGrab, BaseGrabber otherGrabber) { - Debug.Log("Transferring ownership of " + grabbable.name + " to grabber " + otherGrabber.name); - grabbedObjects.Remove(grabbable); + Debug.Log("Transferring ownership of " + ownerGrab.name + " to grabber " + otherGrabber.name); + grabbedObjects.Remove(ownerGrab); return true; } /// /// If the correct grabbing button is pressed, we add to grabbedObjects. /// - /// protected virtual void GrabStart() { // Clean out the list of available objects list for (int i = contactObjects.Count - 1; i >= 0; i--) { if ((contactObjects[i] == null || !contactObjects[i].isActiveAndEnabled) && !grabbedObjects.Contains(contactObjects[i])) + { contactObjects.RemoveAt(i); + } } + // If there are any left after pruning if (contactObjects.Count > 0) { @@ -121,13 +129,12 @@ protected virtual void GrabStart() /// Grab behaviour depends on the combination of GrabState, and a grabbable trigger entered /// protected virtual void GrabEnd() - { + { grabbedObjects.Clear(); } protected virtual void OnEnable() { - } protected virtual void OnDisable() @@ -153,48 +160,49 @@ protected void AddContact(BaseGrabbable availableObject) /// /// - protected void RemoveContact (BaseGrabbable availableObject) + protected void RemoveContact(BaseGrabbable availableObject) { contactObjects.Remove(availableObject); availableObject.RemoveContact(this); - if (contactObjects.Contains (availableObject)) + if (contactObjects.Contains(availableObject)) { - + // What's supposed to happen here? } } /// /// Sorts by distance from grab point to grab handle by default /// - protected virtual void SortAvailable () + protected virtual void SortAvailable() { - contactObjects.Sort (delegate (BaseGrabbable b1, BaseGrabbable b2) { + contactObjects.Sort(delegate (BaseGrabbable b1, BaseGrabbable b2) + { return Vector3.Distance(b1.GrabPoint, GrabHandle.position).CompareTo(Vector3.Distance(b1.GrabPoint, GrabHandle.position)); }); } void Update() { - #if UNITY_EDITOR - if (UnityEditor.Selection.activeGameObject == gameObject) + if (Application.isEditor) { - if (Input.GetKeyDown(KeyCode.G)) + if (UnityEditor.Selection.activeGameObject == gameObject) { - if (GrabState == GrabStateEnum.Inactive) - { - Debug.Log("Grab start"); - GrabStart(); - } - else + if (Input.GetKeyDown(KeyCode.G)) { - Debug.Log("Grab end"); - GrabEnd(); + if (GrabState == GrabStateEnum.Inactive) + { + Debug.Log("Grab start"); + GrabStart(); + } + else + { + Debug.Log("Grab end"); + GrabEnd(); + } } } } - #endif - if (prevGrabState != GrabState && OnGrabStateChange != null) { @@ -211,25 +219,5 @@ void Update() prevGrabState = GrabState; prevContactState = ContactState; } - - - //variable declaration - [SerializeField] - protected Transform grabAttachSpot; - [SerializeField] - protected float strength = 1.0f; - - protected HashSet grabbedObjects = new HashSet(); - protected List contactObjects = new List(); - - protected float grabForgivenessRadius; - - private GrabStateEnum prevGrabState = GrabStateEnum.Inactive; - private GrabStateEnum prevContactState = GrabStateEnum.Inactive; - [SerializeField] - protected InteractionSourceHandedness handedness; - - - } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseScalable.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseScalable.cs index d1b9081694e..134a754638b 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseScalable.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseScalable.cs @@ -1,18 +1,34 @@ -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.Collections; using UnityEngine; -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// class responsible for two hand scale. Objects with a child of this class attached /// public abstract class BaseScalable : MonoBehaviour { + [SerializeField] + private bool scaleByDistance = true; + + [SerializeField] + private BaseGrabbable grabbable; + + private bool readyToScale; + private float snapShotOfScale; + private int minScalarNumForScale = 2; + private bool currentlyScaling; + private float snapShotDistance; + protected virtual void Awake() { if (grabbable == null) + { grabbable = gameObject.GetComponent(); + } } /// @@ -39,10 +55,9 @@ public void AttemptScale() if (GetComponent().ActiveGrabbers.Length >= minScalarNumForScale) { - - //Distance - //snapshot a standard distance that the controls are when the scalable object is engaged - //That standard distance between controllers corresponds to the localScale * scaleMultiplier + // Distance + // snapshot a standard distance that the controls are when the scalable object is engaged + // That standard distance between controllers corresponds to the localScale * scaleMultiplier if (scaleByDistance) { if (activeGrabbers.Length >= minScalarNumForScale) @@ -62,8 +77,8 @@ public void AttemptScale() /// /// Adding a grabber object to the list of scalars means adding it to the list of scalars and always attempting a scale if there are enough scalars attached /// - /// - public void OnGrabbed(BaseGrabbable grabbable) + /// + public void OnGrabbed(BaseGrabbable baseGrab) { if (!currentlyScaling) { @@ -72,11 +87,10 @@ public void OnGrabbed(BaseGrabbable grabbable) } /// - /// scaling can be amplified by increasing the scaling mulitplier + /// scaling can be amplified by increasing the scaling multiplier /// scaling functionality can also be modified by recording a distance from the user. /// (For example, an object that is further away might scale up more because it is further away from the user) /// - /// public virtual IEnumerator PerformScaling() { currentlyScaling = true; @@ -99,20 +113,11 @@ public virtual IEnumerator PerformScaling() transform.localScale = Vector3.one * ((currDistance / snapShotDistance) * snapShotOfScale) /*scaleMultiplier */ /* distFromUser*/; } + yield return 0; } + currentlyScaling = false; - yield return null; } - [SerializeField] - private bool scaleByDistance = true; - private bool readyToScale; - private float snapShotOfScale; - private int minScalarNumForScale = 2; - private bool currentlyScaling; - private float snapShotDistance; - - [SerializeField] - private BaseGrabbable grabbable; } } diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseThrowable.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseThrowable.cs index 9dbb025e9fb..0e7e4f49fa1 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseThrowable.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseThrowable.cs @@ -1,26 +1,52 @@ -using UnityEngine; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. -namespace MRTK.Grabbables { +using UnityEngine; + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables +{ /// /// The abstract class that defines the minimum amount of content for any throwable object /// Variables declared at the bottom /// - public abstract class BaseThrowable : MonoBehaviour { public float ThrowMultiplier { get { return throwMultiplier; } set { throwMultiplier = value; } } + public bool ZeroGravityThrow { get { return zeroGravityThrow; } set { zeroGravityThrow = value; } } - public bool Thrown { get { return thrown; } set { thrown = value; } } - //To get velocity info straight from controller + public bool Thrown { get { return thrown; } set { thrown = value; } } + + // To get velocity info straight from controller public Vector3 LatestControllerThrowVelocity { get; set; } public Vector3 LatestControllerThrowAngularVelocity { get; set; } - //not implemented yet. lower priority + // TODO: Not implemented yet. lower priority public AnimationCurve VelocityOverTime { get { return velocityOverTime; } set { velocityOverTime = value; } } + public AnimationCurve UpDownCurveOverTime { get { return upDownCurveOverTime; } set { upDownCurveOverTime = value; } } + public AnimationCurve LeftRightCurveOverTime { get { return leftRightCurveOverTime; } set { leftRightCurveOverTime = value; } } + private BaseGrabbable grabbable; + + [SerializeField] + private float throwMultiplier = 1.0f; + + [SerializeField] + private bool zeroGravityThrow; + + [SerializeField] + private AnimationCurve velocityOverTime; + + [SerializeField] + private AnimationCurve upDownCurveOverTime; + + [SerializeField] + private AnimationCurve leftRightCurveOverTime; + + private bool thrown; + protected virtual void Awake() { grabbable = GetComponent(); @@ -68,25 +94,5 @@ public virtual void Throw(BaseGrabbable grabber) Debug.Log("Throwing.."); thrown = true; } - - private BaseGrabbable grabbable; - - [SerializeField] - private float throwMultiplier = 1.0f; - - [SerializeField] - private bool zeroGravityThrow; - - [SerializeField] - private AnimationCurve velocityOverTime; - - [SerializeField] - private AnimationCurve upDownCurveOverTime; - - [SerializeField] - private AnimationCurve leftRightCurveOverTime; - - private bool thrown; - } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseUsable.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseUsable.cs index 64301296e0f..a0222880faa 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseUsable.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/BaseUsable.cs @@ -1,21 +1,27 @@ -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + using UnityEngine; using UnityEngine.XR.WSA.Input; -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// - /// A usable object is one that can be "used" or actiavated while being grabbed/carried + /// A usable object is one that can be "used" or activated while being grabbed/carried /// A gun and a remote control are examples: first grab, then press a different button to use /// public abstract class BaseUsable : MonoBehaviour { - public enum UseStateEnum - { - Inactive, - Active - } + [SerializeField] + private InteractionSourceHandedness handedness; + + /// + /// Assign a controller button to "use" the object + /// + [SerializeField] + private InteractionSourcePressType pressType; + + private UseStateEnum state; public UseStateEnum UseState { @@ -33,6 +39,7 @@ protected virtual void UseEnd() } //Subscribe GrabStart and GrabEnd to InputEvents for Grip + protected virtual void OnEnable() { InteractionManager.InteractionSourcePressed += UseInputStart; @@ -66,13 +73,5 @@ private void UseInputEnd(InteractionSourceReleasedEventArgs obj) UseEnd(); } } - - [SerializeField] - private InteractionSourceHandedness handedness; - //assign a controller button to "use" the object - [SerializeField] - private InteractionSourcePressType pressType; - - private UseStateEnum state; } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ControllerReleaseData.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ControllerReleaseData.cs new file mode 100644 index 00000000000..fc69220a3dc --- /dev/null +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ControllerReleaseData.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables +{ + public struct ControllerReleaseData + { + public Vector3 Velocity; + public Vector3 AngleVelocity; + + public ControllerReleaseData(Vector3 _vel, Vector3 _angVel) + { + Velocity = _vel; + AngleVelocity = _angVel; + } + } +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ControllerReleaseData.cs.meta b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ControllerReleaseData.cs.meta new file mode 100644 index 00000000000..25c16c4e095 --- /dev/null +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ControllerReleaseData.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 10e21d57710a439bb3576133f7cba266 +timeCreated: 1508206650 \ No newline at end of file diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/DuplicateAfterThrow.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/DuplicateAfterThrow.cs index 9aea1f3b7c6..e8c0250ec7f 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/DuplicateAfterThrow.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/DuplicateAfterThrow.cs @@ -1,13 +1,12 @@ -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + using UnityEngine; -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { - public class DuplicateAfterThrow : MonoBehaviour { - public GameObject ThrowObject; private Vector3 startPos; private Quaternion startRot; @@ -22,6 +21,7 @@ protected virtual void OnDisable() { grabbable.OnReleased -= SpawnDuplicate; } + protected virtual void Awake() { grabbable = GetComponent(); @@ -39,19 +39,17 @@ private void Start() /// For the demo only - if we throw an object, we respawn it at its initial location with the same throw properties as the previous one. /// This way a user can try out throw a few times /// - /// - void SpawnDuplicate(BaseGrabbable grabbable) + /// + private void SpawnDuplicate(BaseGrabbable baseGrab) { - GameObject thrwn = Instantiate(ThrowObject, startPos, Quaternion.identity) as GameObject; - thrwn.GetComponent().ZeroGravityThrow = GetComponent().ZeroGravityThrow; - thrwn.GetComponent().ThrowMultiplier = GetComponent().ThrowMultiplier; - thrwn.GetComponent().material.color = startColor; - thrwn.GetComponent().useGravity = true; - thrwn.transform.rotation = startRot; + GameObject thrown = Instantiate(ThrowObject, startPos, Quaternion.identity); + thrown.GetComponent().ZeroGravityThrow = GetComponent().ZeroGravityThrow; + thrown.GetComponent().ThrowMultiplier = GetComponent().ThrowMultiplier; + thrown.GetComponent().material.color = startColor; + thrown.GetComponent().useGravity = true; + thrown.transform.rotation = startRot; } private BaseGrabbable grabbable; } - - } diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ExtensionMethod.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ExtensionMethod.cs index 7e8f734bec9..d1ee58e90f9 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ExtensionMethod.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ExtensionMethod.cs @@ -1,13 +1,13 @@ -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + using UnityEngine; -using MRTK; -using MRTK.Grabbables; +using HoloToolkit.Unity.InputModule.Examples.Grabbables; using UnityEngine.XR.WSA.Input; -public static class ExtensionMethods { - - public static ControllerReleaseData GetThrowReleasedVelocityAndAngularVelocity(this Rigidbody rb, Vector3 centerOfMassOfRigidbody, InteractionSourcePose poseInfo) +public static class ExtensionMethods +{ + public static ControllerReleaseData GetThrowReleasedVelocityAndAngularVelocity(this Rigidbody _rigidbody, Vector3 centerOfMassOfRigidbody, InteractionSourcePose poseInfo) { Vector3 setVel = default(Vector3); Vector3 angVel = default(Vector3); @@ -22,11 +22,8 @@ public static ControllerReleaseData GetThrowReleasedVelocityAndAngularVelocity(t //vel = velocityOfController + angularVelOfController * distBetween grabbable center of mass and controllerPos; //setVel = controllerVelocity + controllerAngularVelocity + (controllerAngularVelocity *-1) * dist; setVel = controllerVelocity; - Debug.Log(" SetVal = ControllerVelocity ( " + controllerVelocity + ") controllerAngVel ((" + controllerAngularVelocity + ") * -1 )" + " * dist (" + dist+")"); + Debug.Log(" SetVal = ControllerVelocity ( " + controllerVelocity + ") controllerAngVel ((" + controllerAngularVelocity + ") * -1 )" + " * dist (" + dist + ")"); return new ControllerReleaseData(setVel, angVel); } - - - } diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStateEnum.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStateEnum.cs new file mode 100644 index 00000000000..71be63a5c5d --- /dev/null +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStateEnum.cs @@ -0,0 +1,15 @@ +/// +/// //Intended Usage// +/// Attach a "grabbable_x" script (a script that inherits from this) to any object that is meant to be grabbed +/// create more specific grab behavior by adding additional scripts/components to the game object, such as scalableObject, rotatableObject, throwableObject +/// + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables +{ + public enum GrabStateEnum + { + Inactive, + Single, + Multi, + } +} \ No newline at end of file diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStateEnum.cs.meta b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStateEnum.cs.meta new file mode 100644 index 00000000000..afe12b14e46 --- /dev/null +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStateEnum.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7589150cc984491ab5df2b7fa86798a6 +timeCreated: 1508205742 \ No newline at end of file diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStyleEnum.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStyleEnum.cs new file mode 100644 index 00000000000..f33916898ce --- /dev/null +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStyleEnum.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables +{ + public enum GrabStyleEnum + { + Exclusive, + Multi + } +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStyleEnum.cs.meta b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStyleEnum.cs.meta new file mode 100644 index 00000000000..295338d03eb --- /dev/null +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabStyleEnum.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7625ab8266b141988bc0401ad425c596 +timeCreated: 1508205746 \ No newline at end of file diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableChild.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableChild.cs index d5c792dc046..77cc4972126 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableChild.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableChild.cs @@ -1,12 +1,14 @@ -using UnityEngine; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. -namespace MRTK.Grabbables +using UnityEngine; + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// This type of grab makes the grabbed object a child of the grabber. /// This ensures a grabbed object perfectly follows the position and rotation of the grabbing object /// - public class GrabbableChild : BaseGrabbable { protected override void StartGrab(BaseGrabber grabber) @@ -37,4 +39,4 @@ protected override void DetachFromGrabber(BaseGrabber grabber) GetComponent().useGravity = true; } } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableColor.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableColor.cs index f39b6e9b590..360d9b4b791 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableColor.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableColor.cs @@ -1,34 +1,61 @@ -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; using UnityEngine; -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// Simple class to change the color of grabbable objects based on state /// public class GrabbableColor : MonoBehaviour { + [Header("Colors")] + [SerializeField] + private Color colorOnContactSingle = Color.blue; + + [SerializeField] + private Color colorOnContactMulti = Color.cyan; + + [SerializeField] + private Color colorOnGrabSingle = Color.yellow; + + [SerializeField] + private Color colorOnGrabMulti = Color.red; + + [Header("Objects")] + [SerializeField] + private Renderer targetRenderer; + + [SerializeField] + private BaseGrabbable grabbable; + + private Color originalColor; private void Awake() { if (grabbable == null) + { grabbable = GetComponent(); + } + if (targetRenderer == null) + { targetRenderer = gameObject.GetComponentInChildren(); + } originalColor = targetRenderer.material.color; grabbable.OnContactStateChange += RefreshColor; grabbable.OnGrabStateChange += RefreshColor; } - private void RefreshColor(BaseGrabbable g) + private void RefreshColor(BaseGrabbable baseGrab) { Color finalColor = originalColor; - switch (g.ContactState) + switch (baseGrab.ContactState) { case GrabStateEnum.Inactive: - default: break; case GrabStateEnum.Multi: @@ -38,12 +65,14 @@ private void RefreshColor(BaseGrabbable g) case GrabStateEnum.Single: finalColor = colorOnContactSingle; break; + + default: + throw new ArgumentOutOfRangeException(); } - switch (g.GrabState) + switch (baseGrab.GrabState) { case GrabStateEnum.Inactive: - default: break; case GrabStateEnum.Multi: @@ -53,27 +82,12 @@ private void RefreshColor(BaseGrabbable g) case GrabStateEnum.Single: finalColor = colorOnGrabSingle; break; + + default: + throw new ArgumentOutOfRangeException(); } targetRenderer.material.color = finalColor; } - - [Header("Colors")] - [SerializeField] - private Color colorOnContactSingle = Color.blue; - [SerializeField] - private Color colorOnContactMulti = Color.cyan; - [SerializeField] - private Color colorOnGrabSingle = Color.yellow; - [SerializeField] - private Color colorOnGrabMulti = Color.red; - - [Header("Objects")] - [SerializeField] - private Renderer targetRenderer; - [SerializeField] - private BaseGrabbable grabbable; - - private Color originalColor; } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableFixedJoint.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableFixedJoint.cs index 6792efcb496..ba685c490b6 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableFixedJoint.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableFixedJoint.cs @@ -1,26 +1,34 @@ -using System.Collections; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.Collections; using UnityEngine; -namespace MRTK.Grabbables + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// This type of grab creates a temporary fixed joint to attach the grabbed object to the grabber /// The fixed joint properties can be assigned here, because the joint will not be attached/visible until runtime /// - public class GrabbableFixedJoint : BaseGrabbable { - //expose the joint variables here for editing because the joint is added/destroyed at runtime + // expose the joint variables here for editing because the joint is added/destroyed at runtime // to understand how these variables work in greater depth see documentation for spring joint and fixed joint [SerializeField] protected float breakForce = 20; + [SerializeField] protected float breakTorque = 20; + [SerializeField] protected float tolerance = 0.01f; + [SerializeField] protected Vector3 jointAnchor; + [SerializeField] protected float minDistance; + [SerializeField] protected float maxDistance; @@ -36,7 +44,6 @@ protected override void AttachToGrabber(BaseGrabber grabber) joint.anchor = jointAnchor; joint.breakForce = breakForce; joint.breakTorque = breakTorque; - } protected override void DetachFromGrabber(BaseGrabber grabber) @@ -53,7 +60,6 @@ protected override void DetachFromGrabber(BaseGrabber grabber) protected IEnumerator DestroyJointAfterDelay(FixedJoint joint) { - yield return null; if (GrabState == GrabStateEnum.Inactive) { @@ -61,6 +67,5 @@ protected IEnumerator DestroyJointAfterDelay(FixedJoint joint) } yield return null; } - } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableMultiJoint.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableMultiJoint.cs index 6668d52ea8e..964a0024ff7 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableMultiJoint.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableMultiJoint.cs @@ -1,11 +1,15 @@ -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + using UnityEngine; -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { public class GrabbableMultiJoint : BaseGrabbable { + [SerializeField] + private float blendSpeed = 10f; + protected override void OnGrabStay() { base.OnGrabStay(); @@ -14,31 +18,31 @@ protected override void OnGrabStay() int numGrabbers = activeGrabbers.Count; float weightPerGrabber = 1f / numGrabbers; - //if (numGrabbers > 1) - //{ - foreach (Grabber activeGrabber in activeGrabbers) - { - averagePosition = Vector3.Lerp(averagePosition, activeGrabber.GrabHandle.position, weightPerGrabber); - averageRotation = Quaternion.Lerp(averageRotation, activeGrabber.GrabHandle.rotation, weightPerGrabber); - } - - transform.position = Vector3.Lerp(transform.position, averagePosition, Time.deltaTime * blendSpeed); - transform.rotation = Quaternion.Lerp(transform.rotation, averageRotation, Time.deltaTime * blendSpeed); - //} + for (var i = 0; i < activeGrabbers.Count; i++) + { + var activeGrabber = (Grabber)activeGrabbers[i]; + averagePosition = Vector3.Lerp(averagePosition, activeGrabber.GrabHandle.position, weightPerGrabber); + averageRotation = Quaternion.Lerp(averageRotation, activeGrabber.GrabHandle.rotation, weightPerGrabber); + } + + transform.position = Vector3.Lerp(transform.position, averagePosition, Time.deltaTime * blendSpeed); + transform.rotation = Quaternion.Lerp(transform.rotation, averageRotation, Time.deltaTime * blendSpeed); } //the next three functions provide basic behaviour. Extend from this base script in order to provide more specific functionality. + protected override void AttachToGrabber(BaseGrabber grabber) { GetComponent().isKinematic = true; - if(!activeGrabbers.Contains(grabber)) + if (!activeGrabbers.Contains(grabber)) + { activeGrabbers.Add(grabber); + } } protected override void DetachFromGrabber(BaseGrabber grabber) { Debug.Log("Detaching form grabber"); - } protected override void Update() @@ -50,9 +54,5 @@ protected override void Update() GetComponent().useGravity = true; } } - - - [SerializeField] - private float blendSpeed = 10f; } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSimple.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSimple.cs index e5517cd00be..40a9c2747d7 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSimple.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSimple.cs @@ -1,17 +1,26 @@ -using System.Collections; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + using UnityEngine; -namespace MRTK.Grabbables + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// This type of grab makes the grabbed object follow the position and rotation of the grabber, but does not create a parent child relationship /// - public class GrabbableSimple : BaseGrabbable { + private Rigidbody _rigidbody; + + [SerializeField] + private bool matchPosition = true; + [SerializeField] + private bool matchRotation = false; + protected override void Start() { base.Start(); - rb = GetComponent(); + _rigidbody = GetComponent(); } /// @@ -20,50 +29,63 @@ protected override void Start() protected override void StartGrab(BaseGrabber grabber) { base.StartGrab(grabber); - if (rb) - rb.useGravity = false; + if (_rigidbody) + { + _rigidbody.useGravity = false; + } } /// - /// On release turn garvity back on the so the object falls and set the target back to null + /// On release turn gravity back on the so the object falls and set the target back to null /// protected override void EndGrab() { - if (rb) + if (_rigidbody) { - rb.useGravity = true; + _rigidbody.useGravity = true; } + base.EndGrab(); } protected override void OnGrabStay() { - if(matchPosition) + if (matchPosition) + { transform.position = GrabberPrimary.GrabHandle.position; + } if (matchRotation) + { transform.rotation = GrabberPrimary.GrabHandle.rotation; + } } - //the next three functions provide basic behaviour. Extend from this base script in order to provide more specific functionality. + // The next two functions provide basic behaviour. Extend from this base script in order to provide more specific functionality. + protected override void AttachToGrabber(BaseGrabber grabber) { - GetComponent().isKinematic = true; + if (_rigidbody == null) + { + _rigidbody = GetComponent(); + } + + _rigidbody.isKinematic = true; if (!activeGrabbers.Contains(grabber)) + { activeGrabbers.Add(grabber); + } } protected override void DetachFromGrabber(BaseGrabber grabber) { - GetComponent().isKinematic = false; - GetComponent().useGravity = true; - } - - private Rigidbody rb; + if (_rigidbody == null) + { + _rigidbody = GetComponent(); + } - [SerializeField] - private bool matchPosition = true; - [SerializeField] - private bool matchRotation = false; + _rigidbody.isKinematic = false; + _rigidbody.useGravity = true; + } } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSnapToOrient.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSnapToOrient.cs index ab342ba3331..f50c9c50284 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSnapToOrient.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSnapToOrient.cs @@ -1,10 +1,13 @@ -using UnityEngine; -namespace MRTK.Grabbables +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// This type of grab uses a parent child relationship and also immediately orients the child's forward to the parent's forward position /// - public class GrabbableSnapToOrient : BaseGrabbable { protected override void StartGrab(BaseGrabber grabber) @@ -22,4 +25,4 @@ protected override void EndGrab() base.EndGrab(); } } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSpringJoint.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSpringJoint.cs index 0e4a5c5ad0f..71159ff934b 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSpringJoint.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableSpringJoint.cs @@ -1,7 +1,9 @@ -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.Collections; using UnityEngine; -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// This type of grab creates a temporary spring joint to attach the grabbed object to the grabber @@ -61,7 +63,9 @@ protected IEnumerator DestroyJointAfterDelay (SpringJoint joint) { yield return null; if (GrabState == GrabStateEnum.Inactive) + { Destroy(joint); + } } } } \ No newline at end of file diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableTrackFollow.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableTrackFollow.cs index 4df2027896c..35d0fea3c22 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableTrackFollow.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/GrabbableTrackFollow.cs @@ -1,6 +1,9 @@ -using UnityEngine; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. -namespace MRTK.Grabbables +using UnityEngine; + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// This type of grab makes the grabbed object track the position of the grabber @@ -39,4 +42,4 @@ protected override void OnGrabStay() transform.position = Vector3.Lerp(transform.position, GrabberPrimary.GrabHandle.position, Time.time / (lagAmount * 1000)); } } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/Grabber.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/Grabber.cs index 5191793549c..750cb08a271 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/Grabber.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/Grabber.cs @@ -1,15 +1,15 @@ -/// -/// Extends its behaviour from BaseGrabber. This is non-abstract script that's actually attached to the gameObject that will -/// be grabbing/carrying the object. -/// -/// -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + using UnityEngine; using UnityEngine.XR.WSA.Input; -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { + /// + /// Extends its behaviour from BaseGrabber. This is non-abstract script that's actually attached to the gameObject that will + /// be grabbing/carrying the object. + /// public class Grabber : BaseGrabber { ///Subscribe GrabStart and GrabEnd to InputEvents for GripPressed @@ -22,13 +22,11 @@ protected override void OnEnable() protected override void OnDisable() { - base.OnDisable(); InteractionManager.InteractionSourcePressed -= InteractionSourcePressed; InteractionManager.InteractionSourceReleased -= InteractionSourceReleased; + base.OnDisable(); } - - private void InteractionSourcePressed(InteractionSourcePressedEventArgs obj) { if (obj.pressType == pressType && obj.state.source.handedness == handedness) @@ -41,12 +39,8 @@ private void InteractionSourceReleased(InteractionSourceReleasedEventArgs obj) { if (obj.pressType == pressType && obj.state.source.handedness == handedness) { - - Vector3 velocity = default(Vector3); - Vector3 angularVelocity = default(Vector3); - TrySetThrowableObject(GrabbedObjects.Count > 0? GrabbedObjects[0]: null, obj.state.sourcePose); + TrySetThrowableObject(GrabbedObjects.Count > 0 ? GrabbedObjects[0] : null, obj.state.sourcePose); GrabEnd(); - } } @@ -58,14 +52,20 @@ protected virtual void OnTriggerEnter(Collider other) { Debug.Log("Entered trigger with " + other.name); if (((1 << other.gameObject.layer) & grabbableLayers.value) == 0) + { return; + } BaseGrabbable bg = other.GetComponent(); if (bg == null && other.attachedRigidbody != null) + { bg = other.attachedRigidbody.GetComponent(); + } if (bg == null) + { return; + } Debug.Log("Adding contact"); @@ -76,14 +76,20 @@ protected virtual void OnTriggerExit(Collider other) { Debug.Log("Exited trigger with " + other.name); if (((1 << other.gameObject.layer) & grabbableLayers.value) == 0) + { return; + } BaseGrabbable bg = other.GetComponent(); if (bg == null && other.attachedRigidbody != null) + { bg = other.attachedRigidbody.GetComponent(); + } if (bg == null) + { return; + } Debug.Log("Removing contact"); @@ -93,23 +99,29 @@ protected virtual void OnTriggerExit(Collider other) public bool TrySetThrowableObject(BaseGrabbable grabbable, InteractionSourcePose poseInfo) { if (grabbable == null) + { return false; + } if (!grabbable.GetComponent()) + { return false; + } if (!grabbable.GetComponent()) + { return false; + } Rigidbody rb = grabbable.GetComponent(); Debug.Log("name of our rb.center of mass ========= " + rb.name); - ControllerReleaseData contrlReleaseData = grabbable.GetComponent().GetThrowReleasedVelocityAndAngularVelocity(rb.centerOfMass, poseInfo); + ControllerReleaseData controlReleaseData = grabbable.GetComponent().GetThrowReleasedVelocityAndAngularVelocity(rb.centerOfMass, poseInfo); //grabbable.GetComponent().LatestControllerThrowVelocity = vel; //grabbable.GetComponent().LatestControllerThrowAngularVelocity = vel; - grabbable.GetComponent().LatestControllerThrowVelocity = contrlReleaseData.vel; - grabbable.GetComponent().LatestControllerThrowAngularVelocity = contrlReleaseData.angVel; + grabbable.GetComponent().LatestControllerThrowVelocity = controlReleaseData.Velocity; + grabbable.GetComponent().LatestControllerThrowAngularVelocity = controlReleaseData.AngleVelocity; return true; } diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/RotatableObject.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/RotatableObject.cs index f7fc4946f7f..48cbd6c7e67 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/RotatableObject.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/RotatableObject.cs @@ -1,52 +1,56 @@ -using System.Collections; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.Collections; using UnityEngine; using UnityEngine.XR.WSA.Input; - -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// ForceRotate inherits from BaseUsable because the object to be manipulated must first be /// pick up (grabbed) and is then "usable" /// - public class RotatableObject : BaseUsable { private Vector3 touchPositionFromController = Vector3.zero; + private BaseGrabbable baseGrabbable; protected override void OnEnable() { base.OnEnable(); + InteractionManager.InteractionSourceUpdated += GetTouchPadPosition; + if (baseGrabbable == null) + { + baseGrabbable = GetComponent(); + } } protected override void OnDisable() { - base.OnDisable(); InteractionManager.InteractionSourceUpdated -= GetTouchPadPosition; + base.OnDisable(); } /// /// In the BaseUsable class that this class inherits from, UseStarted begins checking for usage /// after the object is grabbed/picked up /// - /// - /// - protected override void UseStart() { - if (GetComponent().GrabberPrimary != null) + if (baseGrabbable.GrabberPrimary != null) { StartCoroutine(MakeRotate()); } - } - private IEnumerator MakeRotate( ) + private IEnumerator MakeRotate() { - while (UseState == UseStateEnum.Active && GetComponent().GrabberPrimary && touchPadPressed) { + while (UseState == UseStateEnum.Active && baseGrabbable.GrabberPrimary && touchPadPressed) + { transform.Rotate(touchPositionFromController); yield return 0; } @@ -56,16 +60,17 @@ private IEnumerator MakeRotate( ) private void GetTouchPadPosition(InteractionSourceUpdatedEventArgs obj) { - if (GetComponent().GrabberPrimary != null) + if (baseGrabbable.GrabberPrimary != null) { - Debug.Log( " obj.state.source.handedness =====" + obj.state.source.handedness+ " **** GrabberPriumary Handedness === " + GetComponent().GrabberPrimary.Handedness); - if (obj.state.source.handedness == GetComponent().GrabberPrimary.Handedness) + Debug.Log(" obj.state.source.handedness =====" + obj.state.source.handedness + " **** GrabberPriumary Handedness === " + baseGrabbable.GrabberPrimary.Handedness); + if (obj.state.source.handedness == baseGrabbable.GrabberPrimary.Handedness) { if (obj.state.touchpadTouched) { touchPositionFromController = obj.state.touchpadPosition; touchPadPressed = true; - } else + } + else { touchPadPressed = false; } @@ -75,4 +80,4 @@ private void GetTouchPadPosition(InteractionSourceUpdatedEventArgs obj) private bool touchPadPressed; } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ScalableObject.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ScalableObject.cs index 3f8fc293ea4..d8392aea326 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ScalableObject.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ScalableObject.cs @@ -1,7 +1,7 @@ - -using UnityEngine; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// Extends its behaviour from BaseScalable. This is a non-abstract script that's actually attached to scalable object @@ -9,6 +9,5 @@ namespace MRTK.Grabbables /// public class ScalableObject : BaseScalable { - } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ThrowableObject.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ThrowableObject.cs index 992b0309fe7..7b0339372cb 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ThrowableObject.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/ThrowableObject.cs @@ -1,7 +1,10 @@ -using System.Collections; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.Collections; using UnityEngine; -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// Extends its behaviour from BaseThrowable. This is a non-abstract script that can be attached to throwable object @@ -9,15 +12,14 @@ namespace MRTK.Grabbables /// public class ThrowableObject : BaseThrowable { - - public override void Throw(BaseGrabbable grabbable) { base.Throw(grabbable); //Vector3 vel = grabbable.GetAverageVelocity(); Vector3 vel = LatestControllerThrowVelocity; Vector3 angVel = LatestControllerThrowAngularVelocity; - if (GetComponent() || GetComponent()) { + if (GetComponent() || GetComponent()) + { StartCoroutine(ThrowDelay(vel, angVel, grabbable)); } else @@ -31,7 +33,7 @@ public override void Throw(BaseGrabbable grabbable) } } - IEnumerator ThrowDelay(Vector3 vel, Vector3 angVel, BaseGrabbable grabbable) + private IEnumerator ThrowDelay(Vector3 vel, Vector3 angVel, BaseGrabbable grabbable) { yield return null; GetComponent().velocity = vel * ThrowMultiplier; @@ -42,4 +44,4 @@ IEnumerator ThrowDelay(Vector3 vel, Vector3 angVel, BaseGrabbable grabbable) } } } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UsableObject.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UsableObject.cs index 0b7b697575b..0b610fe2b25 100644 --- a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UsableObject.cs +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UsableObject.cs @@ -1,7 +1,8 @@ -using System.Collections; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + using UnityEngine; -namespace MRTK.Grabbables +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables { /// /// Extends from BaseUsable. This is a non-abstract script that's actually attached to usable object @@ -14,10 +15,16 @@ public class UsableObject : BaseUsable protected override void OnEnable() { base.OnEnable(); + + Debug.Log("Do something here with the usable object..."); + Debug.LogWarning("Do something here with the usable object..."); } protected override void OnDisable() { + Debug.Log("Do something here with the usable object..."); + Debug.LogWarning("Do something here with the usable object..."); + base.OnDisable(); } @@ -32,7 +39,6 @@ protected override void UseEnd() { Debug.Log("End of Use on UsableObject..."); Debug.LogWarning("End of use on usable object..."); - } } -} \ No newline at end of file +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UseStateEnum.cs b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UseStateEnum.cs new file mode 100644 index 00000000000..36423559632 --- /dev/null +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UseStateEnum.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace HoloToolkit.Unity.InputModule.Examples.Grabbables +{ + public enum UseStateEnum + { + Inactive, + Active + } +} diff --git a/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UseStateEnum.cs.meta b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UseStateEnum.cs.meta new file mode 100644 index 00000000000..7c4c5c8b1c9 --- /dev/null +++ b/Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/Scripts/UseStateEnum.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8c51671d0af94c5786ee82f346fe967e +timeCreated: 1508206428 \ No newline at end of file diff --git a/Assets/HoloToolkit/UI.meta b/Assets/HoloToolkit/UI.meta deleted file mode 100644 index b153b3ef118..00000000000 --- a/Assets/HoloToolkit/UI.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: 8ed8def72dfb85348967b383883eab72 -folderAsset: yes -timeCreated: 1480375776 -licenseType: Free -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/HoloToolkit/UI/Textures.meta b/Assets/HoloToolkit/UI/Textures.meta deleted file mode 100644 index e554cff5b19..00000000000 --- a/Assets/HoloToolkit/UI/Textures.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: bf36f765bd852074bab3404177d5ed3e -folderAsset: yes -timeCreated: 1452822325 -licenseType: Pro -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/HoloToolkit/UI/Textures/MRTK_Logo.png b/Assets/HoloToolkit/UX/Textures/MRTK_Logo.png similarity index 100% rename from Assets/HoloToolkit/UI/Textures/MRTK_Logo.png rename to Assets/HoloToolkit/UX/Textures/MRTK_Logo.png diff --git a/Assets/HoloToolkit/UI/Textures/MRTK_Logo.png.meta b/Assets/HoloToolkit/UX/Textures/MRTK_Logo.png.meta similarity index 100% rename from Assets/HoloToolkit/UI/Textures/MRTK_Logo.png.meta rename to Assets/HoloToolkit/UX/Textures/MRTK_Logo.png.meta