protected virtual IEnumerator AudioClipHapticsRoutine(VRTK_ControllerReference controllerReference, AudioClip clip)
        {
            SDK_ControllerHapticModifiers hapticModifiers = VRTK_SDK_Bridge.GetHapticModifiers();
            float hapticScalar = hapticModifiers.maxHapticVibration;

            float[] audioData    = new float[hapticModifiers.hapticsBufferSize];
            int     sampleOffset = -hapticModifiers.hapticsBufferSize;
            float   startTime    = Time.time;
            float   length       = clip.length / 1;
            float   endTime      = startTime + length;
            float   sampleRate   = clip.samples;

            while (Time.time <= endTime)
            {
                float lerpVal     = (Time.time - startTime) / length;
                int   sampleIndex = (int)(sampleRate * lerpVal);
                if (sampleIndex >= sampleOffset + hapticModifiers.hapticsBufferSize)
                {
                    clip.GetData(audioData, sampleIndex);
                    sampleOffset = sampleIndex;
                }
                float  currentSample  = Mathf.Abs(audioData[sampleIndex - sampleOffset]);
                ushort hapticStrength = (ushort)(hapticScalar * currentSample);
                VRTK_SDK_Bridge.HapticPulse(controllerReference, hapticStrength);
                yield return(null);
            }
        }
Beispiel #2
0
        // Token: 0x06001535 RID: 5429 RVA: 0x00074E95 File Offset: 0x00073095
        protected virtual IEnumerator AudioClipHapticsRoutine(VRTK_ControllerReference controllerReference, AudioClip clip)
        {
            SDK_ControllerHapticModifiers hapticModifiers = VRTK_SDK_Bridge.GetHapticModifiers();
            float hapticScalar = (float)hapticModifiers.maxHapticVibration;

            float[] audioData    = new float[hapticModifiers.hapticsBufferSize];
            int     sampleOffset = -hapticModifiers.hapticsBufferSize;
            float   startTime    = Time.time;
            float   length       = clip.length / 1f;
            float   endTime      = startTime + length;
            float   sampleRate   = (float)clip.samples;

            while (Time.time <= endTime)
            {
                float num  = (Time.time - startTime) / length;
                int   num2 = (int)(sampleRate * num);
                if (num2 >= sampleOffset + hapticModifiers.hapticsBufferSize)
                {
                    clip.GetData(audioData, num2);
                    sampleOffset = num2;
                }
                float  num3 = Mathf.Abs(audioData[num2 - sampleOffset]);
                ushort num4 = (ushort)(hapticScalar * num3);
                VRTK_SDK_Bridge.HapticPulse(controllerReference, (float)num4);
                yield return(null);
            }
            yield break;
        }
Beispiel #3
0
        /// <summary>
        /// The GetHapticModifiers method is used to return modifiers for the duration and interval if the SDK handles it slightly differently.
        /// </summary>
        /// <returns>An SDK_ControllerHapticModifiers object with a given `durationModifier` and an `intervalModifier`.</returns>
        public override SDK_ControllerHapticModifiers GetHapticModifiers()
        {
            var modifiers = new SDK_ControllerHapticModifiers();

            modifiers.durationModifier = 0.8f;
            modifiers.intervalModifier = 1f;
            return(modifiers);
        }
        protected virtual void InternalTriggerHapticPulse(VRTK_ControllerReference controllerReference, float strength, float duration, float pulseInterval)
        {
            InternalCancelHapticPulse(controllerReference);
            float hapticPulseStrength = Mathf.Clamp(strength, 0f, 1f);
            SDK_ControllerHapticModifiers hapticModifiers = VRTK_SDK_Bridge.GetHapticModifiers();
            Coroutine hapticLoop = StartCoroutine(SimpleHapticPulseRoutine(controllerReference, duration * hapticModifiers.durationModifier, hapticPulseStrength, pulseInterval * hapticModifiers.intervalModifier));

            VRTK_SharedMethods.AddDictionaryValue(hapticLoopCoroutines, controllerReference, hapticLoop);
        }
Beispiel #5
0
        // Token: 0x06001531 RID: 5425 RVA: 0x00074D84 File Offset: 0x00072F84
        protected virtual void InternalTriggerHapticPulse(VRTK_ControllerReference controllerReference, float strength, float duration, float pulseInterval)
        {
            this.InternalCancelHapticPulse(controllerReference);
            float hapticPulseStrength = Mathf.Clamp(strength, 0f, 1f);
            SDK_ControllerHapticModifiers hapticModifiers = VRTK_SDK_Bridge.GetHapticModifiers();
            Coroutine value = base.StartCoroutine(this.SimpleHapticPulseRoutine(controllerReference, duration * hapticModifiers.durationModifier, hapticPulseStrength, pulseInterval * hapticModifiers.intervalModifier));

            if (!this.hapticLoopCoroutines.ContainsKey(controllerReference))
            {
                this.hapticLoopCoroutines.Add(controllerReference, value);
            }
        }
Beispiel #6
0
        protected virtual void InternalTriggerHapticPulse(VRTK_ControllerReference controllerReference, float strength, float duration, float pulseInterval)
        {
            InternalCancelHapticPulse(controllerReference);
            float hapticPulseStrength = Mathf.Clamp(strength, 0f, 1f);
            SDK_ControllerHapticModifiers hapticModifiers = VRTK_SDK_Bridge.GetHapticModifiers();

            //TM: added after the SteamVR 2.2 update
            SDK_SteamVRInputSource   inputSource  = controllerReference.actual.GetComponent <SDK_SteamVRInputSource>();
            SteamVR_Action_Vibration hapticAction = inputSource.HapticAction;

            Coroutine hapticLoop = StartCoroutine(SimpleHapticPulseRoutine(inputSource, duration * hapticModifiers.durationModifier, hapticPulseStrength, pulseInterval * hapticModifiers.intervalModifier));

            VRTK_SharedMethods.AddDictionaryValue(hapticLoopCoroutines, controllerReference, hapticLoop);
        }