BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / VoiceMod / Scenes / Scripts / VoiceModEnableSwitch.cs

VoiceModEnableSwitch.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
VoiceModEnableSwitch.cs 1.8 KiB Download Raw
1using UnityEngine;
2
3public class VoiceModEnableSwitch : MonoBehaviour
4{
5 public GameObject[] SwitchTargets;
6
7 /// <summary>
8 /// Sets the active GameObject
9 /// </summary>
10 /// <returns><c>true</c>, if active was set, <c>false</c> otherwise.</returns>
11 /// <param name="target">Target.</param>
12 public bool SetActive<T>(int target) where T : MonoBehaviour
13 {
14 if((target < 0) || (target >= SwitchTargets.Length))
15 return false;
16
17 for (int i = 0; i < SwitchTargets.Length; i++)
18 {
19 SwitchTargets[i].SetActive(false);
20
21 // Disable texture flip or morph target
22 OVRLipSyncContextMorphTarget lipsyncContextMorph =
23 SwitchTargets[i].GetComponent<OVRLipSyncContextMorphTarget>();
24 if (lipsyncContextMorph)
25 lipsyncContextMorph.enabled = false;
26 OVRLipSyncContextTextureFlip lipsyncContextTexture =
27 SwitchTargets[i].GetComponent<OVRLipSyncContextTextureFlip>();
28 if (lipsyncContextTexture)
29 lipsyncContextTexture.enabled = false;
30 }
31
32 SwitchTargets[target].SetActive(true);
33 MonoBehaviour lipsyncContext = SwitchTargets[target].GetComponent<T>();
34 if (lipsyncContext != null)
35 {
36 lipsyncContext.enabled = true;
37 }
38
39 return true;
40 }
41
42 /// <summary>
43 /// Sets the active GameObject
44 /// </summary>
45 /// <returns><c>true</c>, if active was set, <c>false</c> otherwise.</returns>
46 /// <param name="target">Target.</param>
47 public bool SetActive(int target)
48 {
49 if((target < 0) || (target >= SwitchTargets.Length))
50 return false;
51
52 for (int i = 0; i < SwitchTargets.Length; i++)
53 SwitchTargets[i].SetActive(false);
54
55 SwitchTargets[target].SetActive(true);
56
57 return true;
58 }
59}
60