示例#1
0
        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);
        }
示例#2
0
        private static void TryAddImpact(ObjectTrigger objectTrigger, ViveObjectProps prop)
        {
            if (prop.impactAudioProvider == null && prop.impactAnim == null)
            {
                return;
            }

            objectTrigger.SetImpactData(prop.impactAnim, prop.impactAudioProvider);
        }
示例#3
0
        private static void TryAddTouch(ObjectTrigger objectTrigger, ViveObjectProps prop)
        {
            if (prop.touchAudioProvider == null && prop.touchAnimation == null)
            {
                return;
            }

            objectTrigger.SetTouchData(prop.touchAnimation, prop.touchAudioProvider);
        }
示例#4
0
 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));
 }
示例#5
0
 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));
 }
示例#6
0
        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);
        }