Beispiel #1
0
 public void Vibrate(VibrationPreset vibrationPreset, float left, float right, float duration)
 {
     if (canVibrate)
     {
         PresetCurves presetCurves = GetCurves(vibrationPreset, left, right, duration);
         Utils.Coroutine(_Vibrate(presetCurves.leftCurve, presetCurves.rightCurve));
     }
     else
     {
         Utils.VibrationNotAvailableError();
     }
 }
Beispiel #2
0
        private PresetCurves GetCurves(VibrationPreset vibrationPreset, float left, float right, float duration)
        {
            AnimationCurve leftCurve  = new AnimationCurve();
            AnimationCurve rightCurve = new AnimationCurve();

            if (vibrationPreset == VibrationPreset.ButtonPress)
            {
                leftCurve.AddKey(0, 0.5f);
                leftCurve.AddKey(0.1f, 0.5f);

                rightCurve.AddKey(0, 0.5f);
                rightCurve.AddKey(0.1f, 0.5f);
            }

            if (vibrationPreset == VibrationPreset.ImpactLight)
            {
                leftCurve.AddKey(0, 0f);
                leftCurve.AddKey(0.2f, 0f);

                rightCurve.AddKey(0, 0.5f);
                rightCurve.AddKey(0.2f, 0.5f);
            }

            if (vibrationPreset == VibrationPreset.Impact)
            {
                leftCurve.AddKey(0, 0.2f);
                leftCurve.AddKey(0.2f, 0.2f);

                rightCurve.AddKey(0, 0.8f);
                rightCurve.AddKey(0.2f, 0.8f);
            }

            if (vibrationPreset == VibrationPreset.ImpactHeavy)
            {
                leftCurve.AddKey(0, 0.5f);
                leftCurve.AddKey(0.2f, 0.5f);

                rightCurve.AddKey(0, 1);
                rightCurve.AddKey(0.2f, 1);
            }

            if (vibrationPreset == VibrationPreset.ExplosionShort)
            {
                leftCurve.AddKey(0, 0.6f);
                leftCurve.AddKey(0.2f, 0.6f);

                rightCurve.AddKey(0, 0.3f);
                rightCurve.AddKey(0.2f, 0.3f);
            }

            if (vibrationPreset == VibrationPreset.Explosion)
            {
                leftCurve.AddKey(0, 0.8f);
                leftCurve.AddKey(0.5f, 0.8f);

                rightCurve.AddKey(0, 0.4f);
                rightCurve.AddKey(0.5f, 0.4f);
            }

            if (vibrationPreset == VibrationPreset.ExplosionLong)
            {
                leftCurve.AddKey(0, 1f);
                leftCurve.AddKey(1f, 1f);
                leftCurve.AddKey(1.1f, 0f);

                rightCurve.AddKey(0, 0.5f);
                rightCurve.AddKey(1f, 0.5f);
                rightCurve.AddKey(1.1f, 0f);
            }

            if (vibrationPreset == VibrationPreset.AmbientSubtle)
            {
                leftCurve.AddKey(0, 0.1f);
                leftCurve.AddKey(10f, 0.1f);

                rightCurve.AddKey(0, 0);
                rightCurve.AddKey(10f, 0);
            }

            if (vibrationPreset == VibrationPreset.Ambient)
            {
                leftCurve.AddKey(0, 0.3f);
                leftCurve.AddKey(10f, 0.3f);

                rightCurve.AddKey(0, 0.1f);
                rightCurve.AddKey(10f, 0.1f);
            }

            if (vibrationPreset == VibrationPreset.AmbientStrong)
            {
                leftCurve.AddKey(0, 0.6f);
                leftCurve.AddKey(10f, 0.6f);

                rightCurve.AddKey(0, 0.3f);
                rightCurve.AddKey(10f, 0.3f);
            }

            // Multiply the duration and intensity of the curves
            leftCurve.keys = leftCurve.keys
                             .ToList()
                             .Select(key => new Keyframe(key.time * duration, key.value * left))
                             .ToArray();

            rightCurve.keys = rightCurve.keys
                              .ToList()
                              .Select(key => new Keyframe(key.time * duration, key.value * right))
                              .ToArray();

            return(new PresetCurves(leftCurve, rightCurve));
        }
Beispiel #3
0
 public override void Vibrate(VibrationPreset vibrationPreset, float leftIntensity, float rightIntensity,
                              float duration)
 {
     Hinput.gamepad.Take(4).ToList()
     .ForEach(gamepad => gamepad.Vibrate(vibrationPreset, leftIntensity, rightIntensity, duration));
 }
Beispiel #4
0
 public override void Vibrate(VibrationPreset vibrationPreset, float duration)
 {
     Hinput.gamepad.Take(4).ToList()
     .ForEach(gamepad => gamepad.Vibrate(vibrationPreset, duration));
 }
Beispiel #5
0
 /// <summary>
 /// Vibrate a gamepad with an intensity and a duration based on a vibration preset.
 /// The left intensity of the preset is multiplied by leftIntensity, its right intensity is multiplied by
 /// rightIntensity, and its duration is multiplied by duration.<br/> <br/>
 /// Calling this on AnyGamepad vibrates all gamepads.
 /// </summary>
 public virtual void Vibrate(VibrationPreset vibrationPreset, float leftIntensity, float rightIntensity,
                             float duration)
 {
     vibration.Vibrate(vibrationPreset, leftIntensity, rightIntensity, duration);
 }
Beispiel #6
0
 /// <summary>
 /// Vibrate a gamepad with an intensity and a duration based on a vibration preset.
 /// The duration of the preset is multiplied by duration.<br/> <br/>
 /// Calling this on AnyGamepad vibrates all gamepads.
 /// </summary>
 public virtual void Vibrate(VibrationPreset vibrationPreset, float duration)
 {
     vibration.Vibrate(vibrationPreset, 1, 1, duration);
 }
Beispiel #7
0
 /// <summary>
 /// Vibrate a gamepad with an intensity and a duration based on a vibration preset.<br/> <br/>
 /// Calling this on AnyGamepad vibrates all gamepads.
 /// </summary>
 public virtual void Vibrate(VibrationPreset vibrationPreset)
 {
     vibration.Vibrate(vibrationPreset, 1, 1, 1);
 }