Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB

  1. using UnityEngine;
  2. public class EnableSwitch : MonoBehaviour
  3. {
  4. public GameObject[] SwitchTargets;
  5. /// <summary>
  6. /// Sets the active GameObject
  7. /// </summary>
  8. /// <returns><c>true</c>, if active was set, <c>false</c> otherwise.</returns>
  9. /// <param name="target">Target.</param>
  10. public bool SetActive<T>(int target) where T : MonoBehaviour
  11. {
  12. if((target < 0) || (target >= SwitchTargets.Length))
  13. return false;
  14. for (int i = 0; i < SwitchTargets.Length; i++)
  15. {
  16. SwitchTargets[i].SetActive(false);
  17. // Disable texture flip or morph target
  18. OVRLipSyncContextMorphTarget lipsyncContextMorph =
  19. SwitchTargets[i].GetComponent<OVRLipSyncContextMorphTarget>();
  20. if (lipsyncContextMorph)
  21. lipsyncContextMorph.enabled = false;
  22. OVRLipSyncContextTextureFlip lipsyncContextTexture =
  23. SwitchTargets[i].GetComponent<OVRLipSyncContextTextureFlip>();
  24. if (lipsyncContextTexture)
  25. lipsyncContextTexture.enabled = false;
  26. }
  27. SwitchTargets[target].SetActive(true);
  28. MonoBehaviour lipsyncContext = SwitchTargets[target].GetComponent<T>();
  29. if (lipsyncContext != null)
  30. {
  31. lipsyncContext.enabled = true;
  32. }
  33. return true;
  34. }
  35. }