private void Throw(SteamVR_Controller.Device device) { var rigidbody = pickupObject.gameObject.GetComponent <Rigidbody>(); DestroyImmediate(joint); joint = null; pickupObject.isBeingPickedUp = false; pickupObject = null; var origin = trackedObj.origin ? trackedObj.origin : trackedObj.transform.parent; if (origin != null) { rigidbody.velocity = origin.TransformVector(device.velocity); rigidbody.angularVelocity = origin.TransformVector(device.angularVelocity); } else { rigidbody.velocity = device.velocity; rigidbody.angularVelocity = device.angularVelocity; } rigidbody.maxAngularVelocity = rigidbody.angularVelocity.magnitude; }
public TriggerData(AnimationClip anim, AudioClipProvider audio, ViveObjectProps objectProps = null, bool objectIsConsumed = false) { Anim = anim; Audio = audio; ObjectProps = objectProps; ObjectIsConsumed = objectIsConsumed; }
private static void TryAddObject(ObjectTrigger objectTrigger, ViveObjectProps prop) { if (prop.objectAudioProvider == null && prop.objectAnim == null) { return; } objectTrigger.SetObjectData(prop.objectAnim, prop.objectAudioProvider, prop.objectObject, prop.objectIsConsumed); }
private static void TryAddImpact(ObjectTrigger objectTrigger, ViveObjectProps prop) { if (prop.impactAudioProvider == null && prop.impactAnim == null) { return; } objectTrigger.SetImpactData(prop.impactAnim, prop.impactAudioProvider); }
private static void TryAddTouch(ObjectTrigger objectTrigger, ViveObjectProps prop) { if (prop.touchAudioProvider == null && prop.touchAnimation == null) { return; } objectTrigger.SetTouchData(prop.touchAnimation, prop.touchAudioProvider); }
private void OnTriggerStay(Collider other) { if (!Throwable.Is(other.gameObject) || joint != null || pickupObject != null) { return; } pickupObject = other.gameObject.GetComponent <ViveObjectProps>(); }
private void OnTriggerExit(Collider other) { if (joint != null || pickupObject == null) { return; } pickupObject.isBeingPickedUp = false; pickupObject = null; }
private static void TryAddHover(ObjectTrigger objectTrigger, ViveObjectProps prop) { TryAddEventTrigger( objectTrigger, prop, EventTriggerType.PointerEnter, v => v.enterAnimation, v => v.enterAudioProvider, ot => ot.Hover, (ot, anim, audio) => ot.SetHoverData(anim, audio)); }
private static void TryAddClick(ObjectTrigger objectTrigger, ViveObjectProps prop) { TryAddEventTrigger( objectTrigger, prop, EventTriggerType.PointerClick, v => v.clickAnimation, v => v.clickAudioProvider, ot => ot.Click, (ot, anim, audio) => ot.SetClickData(anim, audio)); }
private static void TryAddEventTrigger(ObjectTrigger objectTrigger, ViveObjectProps prop, EventTriggerType triggerType, Func <ViveObjectProps, AnimationClip> getAnim, Func <ViveObjectProps, AudioClipProvider> getAudio, Func <ObjectTrigger, UnityAction <BaseEventData> > getCallback, Action <ObjectTrigger, AnimationClip, AudioClipProvider> set) { Assert.IsNotNull(objectTrigger); Assert.IsNotNull(prop); Assert.IsNotNull(getAnim); Assert.IsNotNull(getAudio); Assert.IsNotNull(getCallback); Assert.IsNotNull(set); var anim = getAnim(prop); var audio = getAudio(prop); if (anim == null && audio == null) { return; } var go = objectTrigger.gameObject; //if collider is on a different object than the vive object props game object, add the event trigger to the object that has the collider bool hasLocalCollider = go.GetComponent <Collider>() == prop.objectCollider; if (!hasLocalCollider) { go = prop.objectCollider.gameObject; } var eventTrigger = go.SafeGetComponent <EventTrigger>(); var entry = new EventTrigger.Entry { eventID = triggerType }; entry.callback.AddListener(getCallback(objectTrigger)); eventTrigger.triggers.Add(entry); set(objectTrigger, anim, audio); }
private void SetData(out TriggerData data, AnimationClip anim, AudioClipProvider audio, ViveObjectProps objectProps = null, bool objectIsConsumed = false) { data = new TriggerData(anim, audio, objectProps, objectIsConsumed); if (anim != null) { this.SafeGetComponent(ref _playObject); data.Setup(_playObject); } if (audio != null) { this.SafeGetComponent(ref _audioSource); } if (objectProps != null) { this.SafeGetComponent(ref _objectProps); } }
public void SetObjectData(AnimationClip anim, AudioClipProvider audio, ViveObjectProps objectProps, bool objectIsConsumed) { SetData(out _objectData, anim, audio, objectProps, objectIsConsumed); }