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.

50 lines
1.7 KiB

  1. namespace VRTK.Examples.Utilities
  2. {
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. public class SceneLoader : MonoBehaviour
  6. {
  7. public Object sceneConstructor;
  8. public bool sdkSwitcher = true;
  9. public GameObject leftScriptAlias;
  10. public GameObject rightScriptAlias;
  11. protected VRTK_SDKSetupSwitcher setupSwitcher;
  12. protected virtual void Awake()
  13. {
  14. ToggleScriptAlias(false);
  15. SceneManager.sceneLoaded += OnSceneLoaded;
  16. SceneManager.LoadScene(sceneConstructor.name, LoadSceneMode.Additive);
  17. }
  18. protected virtual void LateUpdate()
  19. {
  20. if (setupSwitcher != null)
  21. {
  22. setupSwitcher.gameObject.SetActive(sdkSwitcher);
  23. }
  24. }
  25. protected virtual void OnSceneLoaded(Scene loadedScene, LoadSceneMode loadMode)
  26. {
  27. if (loadedScene.name == sceneConstructor.name)
  28. {
  29. VRTK_SDKManager sdkManager = FindObjectOfType<VRTK_SDKManager>();
  30. sdkManager.gameObject.SetActive(false);
  31. sdkManager.scriptAliasLeftController = leftScriptAlias;
  32. sdkManager.scriptAliasRightController = rightScriptAlias;
  33. sdkManager.gameObject.SetActive(true);
  34. ToggleScriptAlias(true);
  35. VRTK_SDKManager.ProcessDelayedToggleBehaviours();
  36. setupSwitcher = sdkManager.GetComponentInChildren<VRTK_SDKSetupSwitcher>();
  37. }
  38. }
  39. protected virtual void ToggleScriptAlias(bool state)
  40. {
  41. leftScriptAlias.SetActive(state);
  42. rightScriptAlias.SetActive(state);
  43. }
  44. }
  45. }