SceneManagement.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SceneManagement.cs
  2. * author: Yannic Seidler
  3. */
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using Valve.VR.InteractionSystem;
  8. using UnityEngine.SceneManagement;
  9. using RosSharp.RosBridgeClient;
  10. // Class that handels transition between scenes.
  11. // Attached to GameObject SceneManagement (Scene: SelectRobot).
  12. public class SceneManagement : MonoBehaviour
  13. {
  14. public robotType robotToLoad { get; set; }
  15. public GameObject simRobot { get; set; }
  16. public GameObject[] robots;
  17. public string topic {get; set;}
  18. public void Awake()
  19. {
  20. DontDestroyOnLoad(gameObject);
  21. }
  22. // Loads the simulation scene asynchronously.
  23. public void loadSceneAsync(robotType robot)
  24. {
  25. try
  26. {
  27. simRobot = getRobot(robot);
  28. }
  29. catch (RobotNotFoundInListException e)
  30. {
  31. Debug.Log(e.Message);
  32. }
  33. Destroy(Player.instance.gameObject);
  34. SceneManager.LoadSceneAsync(1);
  35. }
  36. private GameObject getRobot(robotType robot)
  37. {
  38. for (int i = 0; i < robots.Length; i++)
  39. {
  40. if (robots[i] != null)
  41. {
  42. if (robots[i].GetComponent<RobotInformation>().robotType == robot)
  43. {
  44. return robots[i];
  45. }
  46. }
  47. }
  48. throw new RobotNotFoundInListException("Robot could not be found in robot list");
  49. }
  50. private class RobotNotFoundInListException : System.Exception
  51. {
  52. public RobotNotFoundInListException(string message) : base(message) { }
  53. }
  54. }