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

using UnityEngine;
public class EnableSwitch : MonoBehaviour
{
public GameObject[] SwitchTargets;
/// <summary>
/// Sets the active GameObject
/// </summary>
/// <returns><c>true</c>, if active was set, <c>false</c> otherwise.</returns>
/// <param name="target">Target.</param>
public bool SetActive<T>(int target) where T : MonoBehaviour
{
if((target < 0) || (target >= SwitchTargets.Length))
return false;
for (int i = 0; i < SwitchTargets.Length; i++)
{
SwitchTargets[i].SetActive(false);
// Disable texture flip or morph target
OVRLipSyncContextMorphTarget lipsyncContextMorph =
SwitchTargets[i].GetComponent<OVRLipSyncContextMorphTarget>();
if (lipsyncContextMorph)
lipsyncContextMorph.enabled = false;
OVRLipSyncContextTextureFlip lipsyncContextTexture =
SwitchTargets[i].GetComponent<OVRLipSyncContextTextureFlip>();
if (lipsyncContextTexture)
lipsyncContextTexture.enabled = false;
}
SwitchTargets[target].SetActive(true);
MonoBehaviour lipsyncContext = SwitchTargets[target].GetComponent<T>();
if (lipsyncContext != null)
{
lipsyncContext.enabled = true;
}
return true;
}
}