Beispiel #1
0
        protected virtual void UpdateUI()
        {
            if (Knob.Active)
            {
                // start dent
                if (Time.time - _lastStartClickAt < StartClickDuration)
                {
                    float elapsedTime = StartClickCurve.Evaluate((Time.time - _lastStartClickAt) * (1 / StartClickDuration));
                    Knob._rectTransform.localScale = Vector3.one + Vector3.one * elapsedTime * 0.05f;
                    Knob._image.color = Color.Lerp(ActiveColor, Color.white, elapsedTime);
                }

                // other dents
                foreach (float f in Dents)
                {
                    if (((_knobValue >= f) && (_knobValueLastFrame < f)) || ((_knobValue <= f) && (_knobValueLastFrame > f)))
                    {
                        _lastDentAt = Time.time;
                        break;
                    }
                }
                if (Time.time - _lastDentAt < DentDuration)
                {
                    float elapsedTime = StartClickCurve.Evaluate((Time.time - _lastDentAt) * (1 / DentDuration));
                    Knob._rectTransform.localScale = Vector3.one + Vector3.one * elapsedTime * 0.02f;
                    Knob._image.color = Color.Lerp(ActiveColor, Color.white, elapsedTime * 0.05f);
                    if (MMVibrationManager.iOS())
                    {
                        MMVibrationManager.TransientHaptic(0.4f, 1f);
                    }
                }
            }

            // gas bar
            PowerBar.UpdateBar(Power, 0f, MaximumPowerDuration);

            // power bars
            if (CarSpeed <= 0.1f)
            {
                for (int i = 0; i < SpeedBars.Count; i++)
                {
                    SpeedBars[i].SetActive(false);
                }
            }
            else
            {
                int barsAmount = (int)(CarSpeed * 5f);
                for (int i = 0; i < SpeedBars.Count; i++)
                {
                    if (i <= barsAmount)
                    {
                        SpeedBars[i].SetActive(true);
                    }
                    else
                    {
                        SpeedBars[i].SetActive(false);
                    }
                }
            }
        }
 /// <summary>
 /// Releases the feedback generators, usually you'll want to call this at OnDisable(); or anytime you know you won't need
 /// vibrations anymore.
 /// </summary>
 public static void iOSReleaseHaptics()
 {
     if (!MMVibrationManager.iOS())
     {
         return;
     }
     MMNViOS_ReleaseFeedbackGenerators();
 }
 /// <summary>
 /// Call this method to initialize the haptics. If you forget to do it, Nice Vibrations will do it for you the first time you
 /// call iOSTriggerHaptics. It's better if you do it though.
 /// </summary>
 public static void iOSInitializeHaptics()
 {
     if (!MMVibrationManager.iOS())
     {
         return;
     }
     MMNViOS_InstantiateFeedbackGenerators();
     iOSHapticsInitialized = true;
 }
Beispiel #4
0
        protected virtual void Start()
        {
            _text.text = Version;

            if (MMVibrationManager.iOS())
            {
                _text.text += " iOS " + MMVibrationManager.iOSVersion.ToString();
            }

            if (MMVibrationManager.Android())
            {
                _text.text += " Android " + MMNVAndroid.AndroidSDKVersion().ToString();
            }
        }
 protected virtual void DisplayInformation()
 {
     if (MMVibrationManager.Android())
     {
         _platformString = "API version " + MMVibrationManager.AndroidSDKVersion().ToString();
     }
     else if (MMVibrationManager.iOS())
     {
         _platformString = "iOS " + MMVibrationManager.iOSSDKVersion();
     }
     else
     {
         _platformString = Application.platform + ", not supported by Nice Vibrations for now.";
     }
     DebugTextBox.text = "Platform : " + _platformString + "\n Nice Vibrations v1.2";
 }
        /// <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 (!MMVibrationManager.iOS())
            {
                return;
            }

            if (!iOSHapticsInitialized)
            {
                iOSInitializeHaptics();
            }

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

            if (iOSHapticsSupported())
            {
                switch (type)
                {
                case HapticTypes.Selection:
                    MMNViOS_SelectionHaptic();
                    break;

                case HapticTypes.Success:
                    MMNViOS_SuccessHaptic();
                    break;

                case HapticTypes.Warning:
                    MMNViOS_WarningHaptic();
                    break;

                case HapticTypes.Failure:
                    MMNViOS_FailureHaptic();
                    break;

                case HapticTypes.LightImpact:
                    MMNViOS_LightImpactHaptic();
                    break;

                case HapticTypes.MediumImpact:
                    MMNViOS_MediumImpactHaptic();
                    break;

                case HapticTypes.HeavyImpact:
                    MMNViOS_HeavyImpactHaptic();
                    break;

                case HapticTypes.RigidImpact:
                    MMNViOS_RigidImpactHaptic();
                    break;

                case HapticTypes.SoftImpact:
                    MMNViOS_SoftImpactHaptic();
                    break;
                }
            }
            else if (defaultToRegularVibrate)
            {
                #if UNITY_IOS
                Handheld.Vibrate();
                #endif
            }
        }