16 [Tooltip(
"Add EventHapticSources for vibrations on button press or event calls")]
19 [Tooltip(
"Add AudioHapticSources for vibrations on button press or event calls")]
22 [Tooltip(
"Add SpatialHapticSources for vibrations on button press or collision/trigger calls")]
25 [Tooltip(
"Add EventHapticSources for vibrations on index (GameInput exclusive feature)")]
28 private TextMesh buttonPressed;
30 private TextMesh vibrationMaterialName;
32 private TextMesh vibrationType;
34 private int m_StickId = 1;
37 private int indexStiffness;
40 private int indexVibration;
43 private bool canModifyVibrationType =
true;
44 private AudioSource[] allAudioSources;
49 VibrationHapticSourceGUI();
60 Debug.Log(debugMessage);
64 private void ResetHapticSources()
66 Core.HAR.StopAllEvents();
73 hapticSource.playingCoroutine =
null;
75 hapticSource.isPlaying =
false;
77 allAudioSources = FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
78 foreach (AudioSource audioSource
in allAudioSources)
80 if (audioSource.isPlaying)
83 Debug.Log(
"Audio Source stopped: " + audioSource);
92 spatialHapticSource.GetComponent<
ObjectTransform>().buttonPressed =
false;
99 private void OnApplicationFocus(
bool hasFocus)
101 if ((!hasFocus) && (HapticManager.StopHapticsOnFocusLoss))
103 ResetHapticSources();
107 private void OnApplicationPause(
bool pauseStatus)
109 if (pauseStatus && HapticManager.StopHapticsOnFocusLoss)
111 ResetHapticSources();
115 private void Update()
122 private void GameInputTriggers()
124 KeyCode[] joystickButtonCodes = {
125 (KeyCode)Enum.Parse(typeof(KeyCode),
"Joystick" + m_StickId +
"Button4",
true),
126 (KeyCode)Enum.Parse(typeof(KeyCode),
"Joystick" + m_StickId +
"Button5",
true)
128 for (
int i = 0; i < joystickButtonCodes.Length; i++)
130 if (Input.GetKeyDown(joystickButtonCodes[i]))
132 Debug.Log(
"Trigger " + i +
" pressed");
134 vibrationMaterialName.text = triggerEventHapticSources[i].name;
139 private void VibrationButtons()
141 float dpadVertical = Input.GetAxis(
"dpad" + m_StickId +
"_vertical");
142 if (dpadVertical == 0)
144 canModifyVibrationType =
true;
150 KeyCode[] joystickButtonCodes = {
151 (KeyCode)Enum.Parse(typeof(KeyCode),
"Joystick" + m_StickId +
"Button0",
true),
152 (KeyCode)Enum.Parse(typeof(KeyCode),
"Joystick" + m_StickId +
"Button1",
true),
153 (KeyCode)Enum.Parse(typeof(KeyCode),
"Joystick" + m_StickId +
"Button2",
true),
154 (KeyCode)Enum.Parse(typeof(KeyCode),
"Joystick" + m_StickId +
"Button3",
true)
156 for (
int i = 0; i < joystickButtonCodes.Length; i++)
158 if (Input.GetKeyDown(joystickButtonCodes[i]))
160 HapticVibrationController(indexVibration, i);
165 private void HapticVibrationController(
int indexVibration,
int indexButton)
167 switch (indexVibration)
179 Debug.LogWarning(
"Invalid input for indexVibration.");
186 ResetHapticSources();
188 vibrationMaterialName.text = audioHapticSources[indexButton].name;
193 ResetHapticSources();
194 eventHapticSources[indexButton].PlayEventVibration();
195 vibrationMaterialName.text = eventHapticSources[indexButton].name;
200 ResetHapticSources();
201 spatialHapticSources[indexButton].GetComponent<
ObjectTransform>().enabled =
true;
202 spatialHapticSources[indexButton].GetComponent<
ObjectTransform>().buttonPressed =
true;
203 vibrationMaterialName.text = spatialHapticSources[indexButton].name;
208 if (canModifyVibrationType)
210 indexVibration = isIncrementing ? (indexVibration + 1) % 3 : (indexVibration + 2) % 3;
211 canModifyVibrationType =
false;
213 VibrationHapticSourceGUI();
216 private void VibrationHapticSourceGUI()
218 switch (indexVibration)
221 vibrationType.text =
"Audio Haptic Source";
224 vibrationType.text =
"Event Haptic Source";
227 vibrationType.text =
"Spatial Haptic Source";
230 Debug.LogWarning(
"Invalid input for Haptic Source.");
235 private void ButtonsUI()
237 string[] buttonNames = {
"A | Cross",
"B | Circle",
"X | Square",
"Y | Triangle",
"Shoulder Left",
"Shoulder Right" };
238 string[] dpadNames = {
"DPad left",
"DPad right",
"DPad down",
"DPad up" };
239 for (
int i = 0; i < buttonNames.Length; i++)
241 if (Input.GetKey((KeyCode)Enum.Parse(typeof(KeyCode),
"Joystick" + m_StickId +
"Button" + i,
true)))
243 buttonPressed.text = buttonNames[i];
247 for (
int i = 0; i < dpadNames.Length; i++)
249 if (i < 2 && Input.GetAxis(
"dpad" + m_StickId +
"_horizontal") == (i == 0 ? -1 : 1))
251 buttonPressed.text = dpadNames[i] +
" " + Input.GetAxis(
"dpad" + m_StickId +
"_horizontal");
254 else if (i >= 2 && Input.GetAxis(
"dpad" + m_StickId +
"_vertical") == (i == 2 ? -1 : 1))
256 buttonPressed.text = dpadNames[i] +
" " + Input.GetAxis(
"dpad" + m_StickId +
"_vertical");