CalibModeSwitcher.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. /// <summary>
  6. /// Switches between manual and automatic calibration mode, enabling and disabling objects as specified.
  7. /// </summary>
  8. public class CalibModeSwitcher : MonoBehaviour
  9. {
  10. /// <summary>
  11. /// Objects that will only be enabled when in manual mode, and disabled otherwise.
  12. /// </summary>
  13. [Tooltip("Objects that will only be enabled when in manual mode, and disabled otherwise. ")]
  14. public List<GameObject> enabledInManualMode = new List<GameObject>();
  15. /// <summary>
  16. /// Objects that will only be enabled when in automatic mode, and disabled otherwise.
  17. /// </summary>
  18. [Tooltip("Objects that will only be enabled when in automatic mode, and disabled otherwise. ")]
  19. public List<GameObject> enabledInAutomaticMode = new List<GameObject>();
  20. /// <summary>
  21. /// Methods called when switching to manual mode.
  22. /// </summary>
  23. [Space(5)]
  24. [Tooltip("Methods called when switching to manual mode. ")]
  25. public UnityEvent OnManualModeEntered;
  26. /// <summary>
  27. /// Methods called when switching to automatic mode.
  28. /// </summary>
  29. [Tooltip("Methods called when switching to automatic mode. ")]
  30. public UnityEvent OnAutomaticModeEntered;
  31. /// <summary>
  32. /// The mode options, set by SetCalibrationMode.
  33. /// </summary>
  34. public enum MRCalibrationMode
  35. {
  36. Manual = 0,
  37. Automatic = 1
  38. }
  39. /// <summary>
  40. /// Changes the calibration mode to the one provided by enabling/disabling objecs as needed
  41. /// and calling relevant events.
  42. /// Override that takes an int, so that it can be set via Unity's Inspector. 0 = Manual, 1 = Automatic.
  43. /// </summary>
  44. public void SetCalibrationMode(int newmode)
  45. {
  46. SetCalibrationMode((MRCalibrationMode)newmode);
  47. }
  48. /// <summary>
  49. /// Changes the calibration mode to the one provided by enabling/disabling objecs as needed
  50. /// and calling relevant events.
  51. /// </summary>
  52. public void SetCalibrationMode(MRCalibrationMode newmode)
  53. {
  54. foreach(GameObject mobj in enabledInManualMode)
  55. {
  56. mobj.SetActive(newmode == MRCalibrationMode.Manual);
  57. }
  58. foreach(GameObject aobj in enabledInAutomaticMode)
  59. {
  60. aobj.SetActive(newmode == MRCalibrationMode.Automatic);
  61. }
  62. if (newmode == MRCalibrationMode.Manual) OnManualModeEntered.Invoke();
  63. else if (newmode == MRCalibrationMode.Automatic) OnAutomaticModeEntered.Invoke();
  64. }
  65. }