12 [RequireComponent(typeof(CompoundButton))]
15 const float MinTimeBetweenSameClip = 0.1f;
18 private AudioSource audioSource;
19 private static string lastClipName;
20 private static float lastClipTime;
25 Button button = GetComponent<Button>();
32 audioSource = GetComponent<AudioSource>();
38 if (lastState == newState)
44 if (!gameObject.activeSelf || !gameObject.activeInHierarchy)
49 Debug.LogError(
"Sound profile was null in button " + name);
56 PlayClip(Profile.ButtonObservation, Profile.ButtonObservationVolume);
60 PlayClip(Profile.ButtonObservationTargeted, Profile.ButtonObservationTargetedVolume);
64 PlayClip(Profile.ButtonTargeted, Profile.ButtonTargetedVolume);
72 private void OnButtonCanceled(GameObject go)
74 PlayClip(Profile.ButtonCanceled, Profile.ButtonCanceledVolume);
77 private void OnButtonHeld(GameObject go)
79 PlayClip(Profile.ButtonHeld, Profile.ButtonHeldVolume);
82 private void OnButtonPressed(GameObject go)
84 PlayClip(Profile.ButtonPressed, Profile.ButtonPressedVolume);
87 private void OnButtonReleased (GameObject go)
89 PlayClip(Profile.ButtonReleased, Profile.ButtonReleasedVolume);
92 private void PlayClip (AudioClip clip,
float volume)
97 if (clip.name == lastClipName && (Time.realtimeSinceStartup - lastClipTime) < MinTimeBetweenSameClip)
102 lastClipName = clip.name;
103 lastClipTime = Time.realtimeSinceStartup;
104 if (audioSource != null)
106 audioSource.PlayOneShot(clip, volume);
110 AudioSource.PlayClipAtPoint(clip, transform.position, volume);
117 public class CustomEditor : MRTKEditor { }