| 1 | using UnityEngine; |
| 2 | |
| 3 | public class EnableSwitch : 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 | |