wangguan
2020-12-29 452c75675679c44cc39b04bdb7d330d7c5c14d5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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";
 
        /// <summary>
        /// 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
        /// </summary>
        protected virtual void Awake()
        {
            MMNViOS.iOSInitializeHaptics();
        }
 
        /// <summary>
        /// On Start, we display our debug information
        /// </summary>
        protected virtual void Start()
        {
            DisplayInformation();
        }
 
        /// <summary>
        /// Displays the debug information (API version on Android, iOS sdk version, and error message otherwise)
        /// </summary>
        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;
        }
 
        /// <summary>
        /// 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
        /// </summary>
        protected virtual void OnDisable()
        {
            MMNViOS.iOSReleaseHaptics();
        }
 
        /// <summary>
        /// The following methods are bound (via the inspector) to buttons in the demo scene, and will call the corresponding vibration methods
        /// </summary>
 
        /// <summary>
        /// Triggers the default Unity vibration, without any control over duration, pattern or amplitude
        /// </summary>
        public virtual void TriggerDefault()
        {
#if UNITY_IOS || UNITY_ANDROID
                Handheld.Vibrate ();    
#endif
        }
 
        /// <summary>
        /// Triggers the default Vibrate method, which will result in a medium vibration on Android and a medium impact on iOS
        /// </summary>
        public virtual void TriggerVibrate()
        {
            MMVibrationManager.Vibrate();
        }
 
        /// <summary>
        /// Triggers the selection haptic feedback, a light vibration on Android, and a light impact on iOS
        /// </summary>
        public virtual void TriggerSelection()
        {
            MMVibrationManager.Haptic(HapticTypes.Selection);
        }
 
        /// <summary>
        /// Triggers the success haptic feedback, a light then heavy vibration on Android, and a success impact on iOS
        /// </summary>
        public virtual void TriggerSuccess()
        {
            MMVibrationManager.Haptic(HapticTypes.Success);
        }
 
        /// <summary>
        /// Triggers the warning haptic feedback, a heavy then medium vibration on Android, and a warning impact on iOS
        /// </summary>
        public virtual void TriggerWarning()
        {
            MMVibrationManager.Haptic(HapticTypes.Warning);
        }
 
        /// <summary>
        /// Triggers the failure haptic feedback, a medium / heavy / heavy / light vibration pattern on Android, and a failure impact on iOS
        /// </summary>
        public virtual void TriggerFailure()
        {
            MMVibrationManager.Haptic(HapticTypes.Failure);
        }
 
        /// <summary>
        /// Triggers a light impact on iOS and a short and light vibration on Android.
        /// </summary>
        public virtual void TriggerLightImpact()
        {
            MMVibrationManager.Haptic(HapticTypes.LightImpact);
        }
 
        /// <summary>
        /// Triggers a medium impact on iOS and a medium and regular vibration on Android.
        /// </summary>
        public virtual void TriggerMediumImpact()
        {
            MMVibrationManager.Haptic(HapticTypes.MediumImpact);
        }
 
        /// <summary>
        /// Triggers a heavy impact on iOS and a long and heavy vibration on Android.
        /// </summary>
        public virtual void TriggerHeavyImpact()
        {
            MMVibrationManager.Haptic(HapticTypes.HeavyImpact);
        }
    }
}