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);
            }
        }
        protected virtual void InternalTriggerHapticPulse(VRTK_ControllerReference controllerReference, float strength)
        {
            InternalCancelHapticPulse(controllerReference);
            float hapticPulseStrength = Mathf.Clamp(strength, 0f, 1f);

            VRTK_SDK_Bridge.HapticPulse(controllerReference, hapticPulseStrength);
        }
Пример #3
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;
        }
 protected virtual void InternalTriggerHapticPulse(VRTK_ControllerReference controllerReference, AudioClip clip)
 {
     InternalCancelHapticPulse(controllerReference);
     if (!VRTK_SDK_Bridge.HapticPulse(controllerReference, clip))
     {
         //If the SDK Bridge doesn't support audio clips then defer to a local version
         Coroutine hapticLoop = StartCoroutine(AudioClipHapticsRoutine(controllerReference, clip));
         VRTK_SharedMethods.AddDictionaryValue(hapticLoopCoroutines, controllerReference, hapticLoop);
     }
 }
Пример #5
0
 // Token: 0x06001532 RID: 5426 RVA: 0x00074DEC File Offset: 0x00072FEC
 protected virtual void InternalTriggerHapticPulse(VRTK_ControllerReference controllerReference, AudioClip clip)
 {
     this.InternalCancelHapticPulse(controllerReference);
     if (!VRTK_SDK_Bridge.HapticPulse(controllerReference, clip))
     {
         Coroutine value = base.StartCoroutine(this.AudioClipHapticsRoutine(controllerReference, clip));
         if (!this.hapticLoopCoroutines.ContainsKey(controllerReference))
         {
             this.hapticLoopCoroutines.Add(controllerReference, value);
         }
     }
 }
        protected virtual IEnumerator SimpleHapticPulseRoutine(VRTK_ControllerReference controllerReference, float duration, float hapticPulseStrength, float pulseInterval)
        {
            if (pulseInterval <= 0)
            {
                yield break;
            }

            while (duration > 0)
            {
                VRTK_SDK_Bridge.HapticPulse(controllerReference, hapticPulseStrength);
                yield return(new WaitForSeconds(pulseInterval));

                duration -= pulseInterval;
            }
        }
 protected virtual bool InternalTriggerHapticFrequency(VRTK_ControllerReference controllerReference, float strength, float duration, float frequency)
 {
     InternalCancelHapticPulse(controllerReference);
     return(VRTK_SDK_Bridge.HapticPulse(controllerReference, strength, duration, frequency));
 }
Пример #8
0
 public static void HapticPulseOnIndex(uint index, float strength = 0.5f)
 {
     VRTK_SDK_Bridge.HapticPulse(VRTK_ControllerReference.GetControllerReference(index), strength);
 }