using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace MoreMountains.NiceVibrations { public class NiceVibrationsDemoManager : MonoBehaviour { /// a text object in the demo scene in which debug information will be displayed public Text DebugTextBox; protected string _debugString; protected string _platformString; protected const string _CURRENTVERSION = "1.7"; /// /// On Awake, we initialize our iOS haptics. /// Of course, this only needs to be done when on iOS, or targeting iOS. /// A test will be done and this method will do nothing if running on anything else /// protected virtual void Awake() { MMNViOS.iOSInitializeHaptics(); } /// /// On Start, we display our debug information /// protected virtual void Start() { DisplayInformation(); } /// /// Displays the debug information (API version on Android, iOS sdk version, and error message otherwise) /// protected virtual void DisplayInformation() { if (MMVibrationManager.Android()) { _platformString = "API version " + MMNVAndroid.AndroidSDKVersion().ToString(); } else if (MMVibrationManager.iOS()) { _platformString = "iOS " + MMNViOS.iOSSDKVersion(); } else { _platformString = Application.platform + ", not supported by Nice Vibrations for now."; } DebugTextBox.text = "Platform : " + _platformString + "\n Nice Vibrations v" + _CURRENTVERSION; } /// /// On Disable, we release our iOS haptics (to save memory and avoid garbage). /// Of course, this only needs to be done when on iOS, or targeting iOS. /// A test will be done and this method will do nothing if running on anything else /// protected virtual void OnDisable() { MMNViOS.iOSReleaseHaptics(); } /// /// The following methods are bound (via the inspector) to buttons in the demo scene, and will call the corresponding vibration methods /// /// /// Triggers the default Unity vibration, without any control over duration, pattern or amplitude /// public virtual void TriggerDefault() { #if UNITY_IOS || UNITY_ANDROID Handheld.Vibrate (); #endif } /// /// Triggers the default Vibrate method, which will result in a medium vibration on Android and a medium impact on iOS /// public virtual void TriggerVibrate() { MMVibrationManager.Vibrate(); } /// /// Triggers the selection haptic feedback, a light vibration on Android, and a light impact on iOS /// public virtual void TriggerSelection() { MMVibrationManager.Haptic(HapticTypes.Selection); } /// /// Triggers the success haptic feedback, a light then heavy vibration on Android, and a success impact on iOS /// public virtual void TriggerSuccess() { MMVibrationManager.Haptic(HapticTypes.Success); } /// /// Triggers the warning haptic feedback, a heavy then medium vibration on Android, and a warning impact on iOS /// public virtual void TriggerWarning() { MMVibrationManager.Haptic(HapticTypes.Warning); } /// /// Triggers the failure haptic feedback, a medium / heavy / heavy / light vibration pattern on Android, and a failure impact on iOS /// public virtual void TriggerFailure() { MMVibrationManager.Haptic(HapticTypes.Failure); } /// /// Triggers a light impact on iOS and a short and light vibration on Android. /// public virtual void TriggerLightImpact() { MMVibrationManager.Haptic(HapticTypes.LightImpact); } /// /// Triggers a medium impact on iOS and a medium and regular vibration on Android. /// public virtual void TriggerMediumImpact() { MMVibrationManager.Haptic(HapticTypes.MediumImpact); } /// /// Triggers a heavy impact on iOS and a long and heavy vibration on Android. /// public virtual void TriggerHeavyImpact() { MMVibrationManager.Haptic(HapticTypes.HeavyImpact); } } }