Example #1
0
    public static void Haptic(HapticTypes type)
    {
        switch (type)
        {
        case HapticTypes.Selection:
            AndroidVibrate(LightDuration, LightAmplitude);
            break;

        case HapticTypes.Success:
            AndroidVibrate(_successPattern, _successPatternAmplitude, -1);
            break;

        case HapticTypes.Warning:
            AndroidVibrate(_warningPattern, _warningPatternAmplitude, -1);
            break;

        case HapticTypes.Failure:
            AndroidVibrate(_failurePattern, _failurePatternAmplitude, -1);
            break;

        case HapticTypes.LightImpact:
            AndroidVibrate(LightDuration, LightAmplitude);
            break;

        case HapticTypes.MediumImpact:
            AndroidVibrate(MediumDuration, MediumAmplitude);
            break;

        case HapticTypes.HeavyImpact:
            AndroidVibrate(HeavyDuration, HeavyAmplitude);
            break;
        }
    }
Example #2
0
 void LogVibration(HapticTypes type)
 {
     if (logOnAnyVibration)
     {
         print("[VIBRATION] " + type);
     }
 }
Example #3
0
 public static void Haptic(HapticTypes type)
 {
     if (Application.platform == RuntimePlatform.IPhonePlayer && false)
     {
         MMVibrationManager.Haptic(type);
     }
 }
        /// <summary>
        /// Triggers a haptic feedback of the specified type
        /// </summary>
        /// <param name="type">Type.</param>
        public static void Haptic(HapticTypes type, bool defaultToRegularVibrate = false)
        {
            if (!_vibrationsActive)
            {
                return;
            }

            DebugLog("[MMVibrationManager] Regular Haptic");

            if (Android())
            {
                switch (type)
                {
                case HapticTypes.None:
                    // do nothing
                    break;

                case HapticTypes.Selection:
                    MMNVAndroid.AndroidVibrate(LightDuration, LightAmplitude);
                    break;

                case HapticTypes.Success:
                    MMNVAndroid.AndroidVibrate(_successPattern, _successPatternAmplitude, -1);
                    break;

                case HapticTypes.Warning:
                    MMNVAndroid.AndroidVibrate(_warningPattern, _warningPatternAmplitude, -1);
                    break;

                case HapticTypes.Failure:
                    MMNVAndroid.AndroidVibrate(_failurePattern, _failurePatternAmplitude, -1);
                    break;

                case HapticTypes.LightImpact:
                    MMNVAndroid.AndroidVibrate(_lightImpactPattern, _lightImpactPatternAmplitude, -1);
                    break;

                case HapticTypes.MediumImpact:
                    MMNVAndroid.AndroidVibrate(_mediumImpactPattern, _mediumImpactPatternAmplitude, -1);
                    break;

                case HapticTypes.HeavyImpact:
                    MMNVAndroid.AndroidVibrate(_HeavyImpactPattern, _HeavyImpactPatternAmplitude, -1);
                    break;

                case HapticTypes.RigidImpact:
                    MMNVAndroid.AndroidVibrate(_rigidImpactPattern, _rigidImpactPatternAmplitude, -1);
                    break;

                case HapticTypes.SoftImpact:
                    MMNVAndroid.AndroidVibrate(_softImpactPattern, _softImpactPatternAmplitude, -1);
                    break;
                }
            }
            else if (iOS())
            {
                MMNViOS.iOSTriggerHaptics(type, defaultToRegularVibrate);
            }
        }
 /// <summary>
 /// Plays a haptic pattern, the most complex type of haptic, defined by a JSON string on iOS, and a pattern on Android
 /// </summary>
 /// <param name="iOSJSONString"></param>
 /// <param name="androidPattern"></param>
 /// <param name="androidAmplitudes"></param>
 /// <param name="androidRepeat"></param>
 /// <param name="fallbackOldiOS"></param>
 public static void AdvancedHapticPattern(string iOSJSONString,
                                          long[] androidPattern, int[] androidAmplitudes, int androidRepeat,
                                          long[] rumblePattern, int[] rumbleLowFreqAmplitudes, int[] rumbleHighFreqAmplitudes, int rumbleRepeat,
                                          HapticTypes fallbackOldiOS     = HapticTypes.None,
                                          MonoBehaviour coroutineSupport = null, int controllerID = -1, bool threaded = false)
 {
     AdvancedHapticPattern(true, iOSJSONString, true, androidPattern, androidAmplitudes, androidRepeat, false, true, rumblePattern,
                           rumbleLowFreqAmplitudes, rumbleHighFreqAmplitudes, rumbleRepeat, fallbackOldiOS, coroutineSupport, controllerID, threaded);
 }
 /// <summary>
 /// 在Update中调用,获得一个连续固定间隔的振动效果
 /// </summary>
 /// <param name="level">振动等级,详见Tigger方法注释</param>
 /// <param name="interval">振动间隔</param>
 public static void UpdateTrigger(HapticTypes level = HapticTypes.Selection, float interval = 0.05f)
 {
     if (Time.time - _lastTriggerTime < interval)
     {
         return;
     }
     Trigger(level);
     _lastTriggerTime = Time.time;
 }
            private void _Vibration(HapticTypes type, float delta, string key)
            {
                this._vibrations[key] = Time.time + delta;
                MMVibrationManager.Haptic(type);
#if UNITY_EDITOR
                if (this.ycManager.ycConfig.VibrationDebugLog)
                {
                    Debug.Log("[VIBRATION] " + type + " " + key);
                }
#endif
            }
Example #8
0
        /// <summary>
        /// iOS only : triggers a haptic feedback of the specified type
        /// </summary>
        /// <param name="type">Type.</param>
        public static void iOSTriggerHaptics(HapticTypes type, bool defaultToRegularVibrate = false)
        {
            if (!iOS())
            {
                return;
            }

            if (!iOSHapticsInitialized)
            {
                iOSInitializeHaptics();
            }

            // this will trigger a standard vibration on all the iOS devices that don't support haptic feedback

            if (HapticsSupported())
            {
                switch (type)
                {
                case HapticTypes.Selection:
                    SelectionHaptic();
                    break;

                case HapticTypes.Success:
                    SuccessHaptic();
                    break;

                case HapticTypes.Warning:
                    WarningHaptic();
                    break;

                case HapticTypes.Failure:
                    FailureHaptic();
                    break;

                case HapticTypes.LightImpact:
                    LightImpactHaptic();
                    break;

                case HapticTypes.MediumImpact:
                    MediumImpactHaptic();
                    break;

                case HapticTypes.HeavyImpact:
                    HeavyImpactHaptic();
                    break;
                }
            }
            else if (defaultToRegularVibrate)
            {
                                #if UNITY_IOS
                Handheld.Vibrate();
                                #endif
            }
        }
Example #9
0
 public static void StartVibration(HapticTypes vibrationType)
 {
     if (IsVibroOn)
     {
         try
         {
             MMVibrationManager.Haptic(vibrationType, false, true);
         }
         catch (Exception e)
         {
             //TODO: :ODOT\\
         }
     }
 }
 private void _VibrationCheck(HapticTypes type, float delta, string key)
 {
     if (this.ycManager.ycConfig.Vibration && this.ycManager.dataManager.GetVibration() == true)
     {
         if (this._vibrations.ContainsKey(key))
         {
             if (Time.time >= this._vibrations[key])
             {
                 this._Vibration(type, delta, key);
             }
         }
         else
         {
             this._Vibration(type, delta, key);
         }
     }
 }
Example #11
0
    public static void iOSTriggerHaptics(HapticTypes type)
    {
        if (!iOS())
        {
            return;
        }
        if (!iOSHapticsInitialized)
        {
            iOSInitializeHaptics();
        }
        if (HapticsSupported())
        {
            switch (type)
            {
            case HapticTypes.Selection:
                SelectionHaptic();
                break;

            case HapticTypes.Success:
                SuccessHaptic();
                break;

            case HapticTypes.Warning:
                WarningHaptic();
                break;

            case HapticTypes.Failure:
                FailureHaptic();
                break;

            case HapticTypes.LightImpact:
                LightImpactHaptic();
                break;

            case HapticTypes.MediumImpact:
                MediumImpactHaptic();
                break;

            case HapticTypes.HeavyImpact:
                HeavyImpactHaptic();
                break;
            }
        }
    }
Example #12
0
        /// <summary>
        /// Triggers a haptic feedback of the specified type
        /// </summary>
        /// <param name="type">Type.</param>
        public static void Haptic(HapticTypes type, bool defaultToRegularVibrate = false)
        {
            if (Android())
            {
                switch (type)
                {
                case HapticTypes.None:
                    // do nothing
                    break;

                case HapticTypes.Selection:
                    AndroidVibrate(LightDuration, LightAmplitude);
                    break;

                case HapticTypes.Success:
                    AndroidVibrate(_successPattern, _successPatternAmplitude, -1);
                    break;

                case HapticTypes.Warning:
                    AndroidVibrate(_warningPattern, _warningPatternAmplitude, -1);
                    break;

                case HapticTypes.Failure:
                    AndroidVibrate(_failurePattern, _failurePatternAmplitude, -1);
                    break;

                case HapticTypes.LightImpact:
                    AndroidVibrate(_lightimpactPattern, _lightimpactPatternAmplitude, -1);
                    break;

                case HapticTypes.MediumImpact:
                    AndroidVibrate(_mediumimpactPattern, _mediumimpactPatternAmplitude, -1);
                    break;

                case HapticTypes.HeavyImpact:
                    AndroidVibrate(_HeavyimpactPattern, _HeavyimpactPatternAmplitude, -1);
                    break;
                }
            }
            else if (iOS())
            {
                iOSTriggerHaptics(type, defaultToRegularVibrate);
            }
        }
Example #13
0
 public static void Vibrate(HapticTypes hapticType, float cooldown = 0.0f)
 {
     if (AllowHaptics)
     {
         // If no cooldown is set
         if (cooldown == 0.0f)
         {
             MMVibrationManager.Haptic(hapticType);
         }
         else
         {
             if (Time.time >= _nextVibrationTime)
             {
                 MMVibrationManager.Haptic(hapticType);
                 _nextVibrationTime = Time.time + cooldown;
             }
         }
     }
 }
        /// <summary>
        /// Plays a advanced haptic pattern,
        /// </summary>
        /// <param name="ios"></param>
        /// <param name="iOSJSONString"></param>
        /// <param name="android"></param>
        /// <param name="androidPattern"></param>
        /// <param name="androidAmplitudes"></param>
        /// <param name="androidRepeat"></param>
        /// <param name="vibrateAndroidIfNoSupport"></param>
        /// <param name="rumble"></param>
        /// <param name="rumblePattern"></param>
        /// <param name="rumbleLowFreqAmplitudes"></param>
        /// <param name="rumbleHighFreqAmplitudes"></param>
        /// <param name="rumbleRepeat"></param>
        /// <param name="fallbackOldiOS"></param>
        /// <param name="coroutineSupport"></param>
        /// <param name="controllerID"></param>
        public static void AdvancedHapticPattern(bool ios, string iOSJSONString,
                                                 bool android, long[] androidPattern, int[] androidAmplitudes, int androidRepeat,
                                                 bool vibrateAndroidIfNoSupport,
                                                 bool rumble,
                                                 long[] rumblePattern, int[] rumbleLowFreqAmplitudes, int[] rumbleHighFreqAmplitudes, int rumbleRepeat,
                                                 HapticTypes fallbackOldiOS     = HapticTypes.None,
                                                 MonoBehaviour coroutineSupport = null, int controllerID = -1, bool threaded = false)
        {
            if (!_vibrationsActive)
            {
                return;
            }

            DebugLog("[MMVibrationManager] Advanced Haptic Pattern");

            if (Android())
            {
                if (!MMNVAndroid.AndroidHasAmplitudeControl() && !vibrateAndroidIfNoSupport)
                {
                    return;
                }
                MMNVAndroid.AndroidVibrate(androidPattern, androidAmplitudes, androidRepeat, threaded);
            }
            else if (iOS())
            {
                if ((iOSVersion >= 13) && HapticsSupported())
                {
                    MMNViOSCoreHaptics.PlayCoreHapticsFromJSON(iOSJSONString, threaded);
                    _hapticsPlayedOnce = true;
                }
                else
                {
                    MMNViOS.iOSTriggerHaptics(fallbackOldiOS);
                }
            }
#if MOREMOUNTAINS_NICEVIBRATIONS_RUMBLE
            if (coroutineSupport != null)
            {
                MMNVRumble.Rumble(rumblePattern, rumbleLowFreqAmplitudes, rumbleHighFreqAmplitudes, rumbleRepeat, coroutineSupport, controllerID);
            }
#endif
        }
Example #15
0
    public static void Haptic(HapticTypes type)
    {
        try {
            switch (type)
            {
            case HapticTypes.Selection:
                AndroidVibrate(LightDuration, LightAmplitude);
                break;

            case HapticTypes.Success:
                AndroidVibrate(_successPattern, _successPatternAmplitude, -1);
                break;

            case HapticTypes.Warning:
                AndroidVibrate(_warningPattern, _warningPatternAmplitude, -1);
                break;

            case HapticTypes.Failure:
                AndroidVibrate(_failurePattern, _failurePatternAmplitude, -1);
                break;

            case HapticTypes.LightImpact:
                AndroidVibrate(LightDuration, LightAmplitude);
                break;

            case HapticTypes.MediumImpact:
                AndroidVibrate(MediumDuration, MediumAmplitude);
                break;

            case HapticTypes.HeavyImpact:
                AndroidVibrate(HeavyDuration, HeavyAmplitude);
                break;
            }
        } catch (System.NullReferenceException e) {
            Debug.Log(e.StackTrace);
        }
    }
    /// <summary>
    /// 调用震动
    /// </summary>
    /// <param name="level"></param>
    public static void Trigger(HapticTypes level)
    {
        try
        {
            if (VibratorEnable)
            {
                MMVibrationManager.Haptic(level);

#if PUFFER_DEBUG
                Debug.Log("[VibratorManager]:Trigger" + level);
#endif
            }
            else
            {
#if PUFFER_DEBUG
                Debug.Log("[VibratorManager]:VibratorEnable==False");
#endif
            }
        }
        catch (Exception e)
        {
            Debug.Log("Error:" + e.Message);
        }
    }
Example #17
0
    /// 震动反馈
    public static void Haptic(HapticTypes type, bool defaultToRegularVibrate = false, bool alsoRumble = false,
                              MonoBehaviour coroutineSupport = null, int controllerID = -1)
    {
        if (!_vibrationsActive)
        {
            Debug.LogError("vibrationsActive不震动时的值: " + _vibrationsActive);
            //   ------------------------------ [ 不震动测试 ] ------------------------------
            switch (type)
            {
            case HapticTypes.None:         Debug.LogError("------ 00 -----");  break;

            case HapticTypes.Selection:    Debug.LogError("------ 11 -----");  break;

            case HapticTypes.Success:      Debug.LogError("------ 22 -----");  break;

            case HapticTypes.Warning:      Debug.LogError("------ 33 -----");  break;

            case HapticTypes.Failure:      Debug.LogError("------ 44 -----");  break;

            case HapticTypes.LightImpact:  Debug.LogError("------ 55 -----");  break;

            case HapticTypes.MediumImpact: Debug.LogError("------ 66 -----");  break;

            case HapticTypes.HeavyImpact:  Debug.LogError("------ 77 -----");  break;

            case HapticTypes.RigidImpact:  Debug.LogError("------ 88 -----");  break;

            case HapticTypes.SoftImpact:   Debug.LogError("------ 99 -----");  break;
            }
            return;
        }

        //   ------------------------------ [ 震动测试 ] ------------------------------
        Debug.LogError("进入实现微信震动接口: ");
        Debug.LogError("vibrationsActive的值: " + _vibrationsActive);
#if WXGAME && !UNITY_EDITOR
        switch (type)
        {
        case HapticTypes.None:         Debug.LogError("------ 0 -----"); break;

        case HapticTypes.Selection:    Debug.LogError("------ 1 -----"); WX.VibrateLong(); break;

        case HapticTypes.Success:      Debug.LogError("------ 2 -----"); WX.VibrateLong(); break;

        case HapticTypes.Warning:      Debug.LogError("------ 3 -----"); WX.VibrateLong(); break;

        case HapticTypes.Failure:      Debug.LogError("------ 4 -----"); WX.VibrateLong(); break;

        case HapticTypes.LightImpact:  Debug.LogError("------ 5 -----"); WX.VibrateLong(); break;

        case HapticTypes.MediumImpact: Debug.LogError("------ 6 -----"); WX.VibrateLong(); break;

        case HapticTypes.HeavyImpact:  Debug.LogError("------ 7 -----"); WX.VibrateLong(); break;

        case HapticTypes.RigidImpact:  Debug.LogError("------ 8 -----"); WX.VibrateLong(); break;

        case HapticTypes.SoftImpact:   Debug.LogError("------ 9 -----"); WX.VibrateLong(); break;
        }
#endif
        switch (type)
        {
        case HapticTypes.None:         Debug.LogError("------ 0 -----");  break;

        case HapticTypes.Selection:    Debug.LogError("------ 1 -----");  break;

        case HapticTypes.Success:      Debug.LogError("------ 2 -----");  break;

        case HapticTypes.Warning:      Debug.LogError("------ 3 -----");  break;

        case HapticTypes.Failure:      Debug.LogError("------ 4 -----");  break;

        case HapticTypes.LightImpact:  Debug.LogError("------ 5 -----");  break;

        case HapticTypes.MediumImpact: Debug.LogError("------ 6 -----");  break;

        case HapticTypes.HeavyImpact:  Debug.LogError("------ 7 -----");  break;

        case HapticTypes.RigidImpact:  Debug.LogError("------ 8 -----");  break;

        case HapticTypes.SoftImpact:   Debug.LogError("------ 9 -----");  break;
        }
    }
        /// <summary>
        /// Plays a continuous haptic, full options signature
        /// </summary>
        /// <param name="vibrateiOS"></param>
        /// <param name="iOSIntensity"></param>
        /// <param name="iOSSharpness"></param>
        /// <param name="fallbackOldiOS"></param>
        /// <param name="vibrateAndroid"></param>
        /// <param name="androidIntensity"></param>
        /// <param name="androidSharpness"></param>
        /// <param name="vibrateAndroidIfNoSupport"></param>
        /// <param name="rumble"></param>
        /// <param name="rumbleLowFrequency"></param>
        /// <param name="rumbleHighFrequency"></param>
        /// <param name="controllerID"></param>
        /// <param name="duration">the duration in seconds</param>
        /// <param name="mono">a monobehaviour to use to sustain this haptic</param>
        /// <param name="threaded">whether to call this on the main thread (false) or a secondary one (true)</param>
        /// <param name="fullIntensity">whether to allow for full intensity control for subsequent updates</param>
        public static void ContinuousHaptic(bool vibrateiOS, float iOSIntensity, float iOSSharpness, HapticTypes fallbackOldiOS,
                                            bool vibrateAndroid, float androidIntensity, float androidSharpness,
                                            bool vibrateAndroidIfNoSupport,
                                            bool rumble, float rumbleLowFrequency, float rumbleHighFrequency, int controllerID,
                                            float duration,
                                            MonoBehaviour mono = null, bool threaded = false, bool fullIntensity = true)
        {
            if (!_vibrationsActive)
            {
                return;
            }

            DebugLog("[MMVibrationManager] Continuous Haptic");

            if (Android() && vibrateAndroid)
            {
                if (!MMNVAndroid.AndroidHasAmplitudeControl() && !vibrateAndroidIfNoSupport)
                {
                    return;
                }
                androidIntensity = Remap(androidIntensity, 0f, 1f, 0, 255);
                MMNVAndroid.AndroidVibrate((long)(duration * 1000), (int)(androidIntensity));
            }
            else if (iOS() && vibrateiOS)
            {
                if ((iOSVersion >= 13) && HapticsSupported())
                {
                    MMNViOSCoreHaptics.PlayContinuousHapticPattern(iOSIntensity, iOSSharpness, duration, mono, threaded, fullIntensity);
                    _hapticsPlayedOnce = true;
                }
                else
                {
                    MMNViOS.iOSTriggerHaptics(fallbackOldiOS);
                }
            }
            if (rumble && (mono != null))
            {
#if MOREMOUNTAINS_NICEVIBRATIONS_RUMBLE
                MMNVRumble.RumbleContinuous(rumbleLowFrequency, rumbleHighFrequency, controllerID);
#endif
            }
        }
 /// <summary>
 /// Plays a continuous haptic of the specified intensity, sharpness and duration
 /// </summary>
 /// <param name="intensity">the intensity of the haptic, between 0 and 1</param>
 /// <param name="sharpness">the sharpness of the haptic, between 0 and 1</param>
 /// <param name="duration">the duration in seconds</param>
 /// <param name="fallbackOldiOS">the fallback to use on old iOS versions that don't support Core Haptics</param>
 /// <param name="mono">a monobehaviour to use to sustain this haptic</param>
 /// <param name="alsoRumble">whether to also rumble or not</param>
 /// <param name="controllerID">the ID of the controller</param>
 /// <param name="threaded">whether to call this on the main thread (false) or a secondary one (true)</param>
 /// <param name="fullIntensity">whether to allow for full intensity control for subsequent updates</param>
 public static void ContinuousHaptic(float intensity, float sharpness, float duration,
                                     HapticTypes fallbackOldiOS = HapticTypes.None, MonoBehaviour mono = null, bool alsoRumble = false, int controllerID = -1, bool threaded = false, bool fullIntensity = true)
 {
     ContinuousHaptic(true, intensity, sharpness, fallbackOldiOS, true, intensity, sharpness, false, alsoRumble, intensity, sharpness, controllerID, duration, mono, threaded, fullIntensity);
 }
        /// <summary>
        /// Triggers a haptic feedback of the specified type
        /// </summary>
        /// <param name="type">Type.</param>
        public static void Haptic(HapticTypes type, bool defaultToRegularVibrate = false, bool alsoRumble = false, MonoBehaviour coroutineSupport = null, int controllerID = -1)
        {
            if (!_vibrationsActive)
            {
                return;
            }

            DebugLog("[MMVibrationManager] Regular Haptic");

            if (Android())
            {
                switch (type)
                {
                case HapticTypes.None:
                    // do nothing
                    break;

                case HapticTypes.Selection:
                    MMNVAndroid.AndroidVibrate(LightDuration, LightAmplitude);
                    break;

                case HapticTypes.Success:
                    MMNVAndroid.AndroidVibrate(_successPattern, _successPatternAmplitude, -1);
                    break;

                case HapticTypes.Warning:
                    MMNVAndroid.AndroidVibrate(_warningPattern, _warningPatternAmplitude, -1);
                    break;

                case HapticTypes.Failure:
                    MMNVAndroid.AndroidVibrate(_failurePattern, _failurePatternAmplitude, -1);
                    break;

                case HapticTypes.LightImpact:
                    MMNVAndroid.AndroidVibrate(_lightImpactPattern, _lightImpactPatternAmplitude, -1);
                    break;

                case HapticTypes.MediumImpact:
                    MMNVAndroid.AndroidVibrate(_mediumImpactPattern, _mediumImpactPatternAmplitude, -1);
                    break;

                case HapticTypes.HeavyImpact:
                    MMNVAndroid.AndroidVibrate(_HeavyImpactPattern, _HeavyImpactPatternAmplitude, -1);
                    break;

                case HapticTypes.RigidImpact:
                    MMNVAndroid.AndroidVibrate(_rigidImpactPattern, _rigidImpactPatternAmplitude, -1);
                    break;

                case HapticTypes.SoftImpact:
                    MMNVAndroid.AndroidVibrate(_softImpactPattern, _softImpactPatternAmplitude, -1);
                    break;
                }
            }
            else if (iOS())
            {
                MMNViOS.iOSTriggerHaptics(type, defaultToRegularVibrate);
            }

            if (alsoRumble && (coroutineSupport != null))
            {
                #if MOREMOUNTAINS_NICEVIBRATIONS_RUMBLE
                switch (type)
                {
                case HapticTypes.None:
                    // do nothing
                    break;

                case HapticTypes.Selection:
                    MMNVRumble.Rumble(_rumbleLight.x, _rumbleMedium.y, _rumbleLight.z, coroutineSupport, controllerID);
                    break;

                case HapticTypes.Success:
                    MMNVRumble.Rumble(_successPattern, _successPatternAmplitude, -1, coroutineSupport, controllerID);
                    break;

                case HapticTypes.Warning:
                    MMNVRumble.Rumble(_warningPattern, _warningPatternAmplitude, -1, coroutineSupport, controllerID);
                    break;

                case HapticTypes.Failure:
                    MMNVRumble.Rumble(_failurePattern, _failurePatternAmplitude, -1, coroutineSupport, controllerID);
                    break;

                case HapticTypes.LightImpact:
                    MMNVRumble.Rumble(_rumbleLight.x, _rumbleLight.y, _rumbleLight.z, coroutineSupport, controllerID);
                    break;

                case HapticTypes.MediumImpact:
                    MMNVRumble.Rumble(_rumbleMedium.x, _rumbleMedium.y, _rumbleMedium.z, coroutineSupport, controllerID);
                    break;

                case HapticTypes.HeavyImpact:
                    MMNVRumble.Rumble(_rumbleHeavy.x, _rumbleHeavy.y, _rumbleHeavy.z, coroutineSupport, controllerID);
                    break;

                case HapticTypes.RigidImpact:
                    MMNVRumble.Rumble(_rumbleRigid.x, _rumbleRigid.y, _rumbleRigid.z, coroutineSupport, controllerID);
                    break;

                case HapticTypes.SoftImpact:
                    MMNVRumble.Rumble(_rumbleSoft.x, _rumbleSoft.y, _rumbleSoft.z, coroutineSupport, controllerID);
                    break;
                }
                #endif
            }
        }
        /// <summary>
        /// Plays a continuous haptic of the specified intensity, sharpness and duration
        /// </summary>
        /// <param name="intensity"></param>
        /// <param name="sharpness"></param>
        /// <param name="duration"></param>
        public static void ContinuousHaptic(float intensity, float sharpness, float duration, HapticTypes fallbackOldiOS = HapticTypes.None, MonoBehaviour mono = null)
        {
            if (!_vibrationsActive)
            {
                return;
            }

            DebugLog("[MMVibrationManager] Continuous Haptic");

            if (Android())
            {
                intensity = NiceVibrationsDemoHelpers.Remap(intensity, 0f, 1f, 0, 255);

                MMNVAndroid.AndroidVibrate((long)(duration * 1000), (int)(intensity));
            }
            else if (iOS())
            {
                if (iOSVersion >= 13)
                {
                    MMNViOSCoreHaptics.PlayContinuousHapticPattern(intensity, sharpness, duration, mono);
                }
                else
                {
                    MMNViOS.iOSTriggerHaptics(fallbackOldiOS);
                }
            }
        }
        /// <summary>
        /// Plays a haptic pattern, the most complex type of haptic, defined by a JSON string on iOS, and a pattern on Android
        /// </summary>
        /// <param name="iOSJSONString"></param>
        /// <param name="androidPattern"></param>
        /// <param name="androidAmplitudes"></param>
        /// <param name="androidRepeat"></param>
        /// <param name="fallbackOldiOS"></param>
        public static void AdvancedHapticPattern(string iOSJSONString, long[] androidPattern, int[] androidAmplitudes, int androidRepeat, HapticTypes fallbackOldiOS = HapticTypes.None)
        {
            if (!_vibrationsActive)
            {
                return;
            }

            DebugLog("[MMVibrationManager] Advanced Haptic Pattern");

            if (Android())
            {
                MMNVAndroid.AndroidVibrate(androidPattern, androidAmplitudes, androidRepeat);
            }
            else if (iOS())
            {
                if (iOSVersion >= 13)
                {
                    MMNViOSCoreHaptics.PlayCoreHapticsFromJSON(iOSJSONString);
                }
                else
                {
                    MMNViOS.iOSTriggerHaptics(fallbackOldiOS);
                }
            }
        }
Example #23
0
 public static void Haptic(HapticTypes hapticType)
 {
     MMVibrationManager.Haptic(hapticType);
     OnHaptic.Invoke();
 }
Example #24
0
 private void PlayHaptic(HapticTypes type)
 {
                 #if !UNITY_EDITOR
     MMVibrationManager.Haptic(type);
                 #endif
 }
 /// <summary>
 /// 开启一个持续的震动
 /// </summary>
 /// <param name="intensity">震动的强度</param>
 /// <param name="sharpness">震动的锐度</param>
 /// <param name="duration">震动的持续时间</param>
 /// <param name="fallbackOldiOS"></param>
 /// <param name="mono"></param>
 /// <param name="alsoRumble"></param>
 /// <param name="controllerID"></param>
 /// <param name="threaded"></param>
 /// <param name="fullIntensity"></param>
 public static void StartContinuousVibration(float intensity, float sharpness, float duration, HapticTypes fallbackOldiOS = HapticTypes.None, MonoBehaviour mono = null)
 {
     MMVibrationManager.ContinuousHaptic(intensity, sharpness, duration, fallbackOldiOS, mono);
 }