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.

35 lines
1020 B

  1. namespace VRTK.UnityEventHelper
  2. {
  3. using UnityEngine;
  4. public abstract class VRTK_UnityEvents<T> : MonoBehaviour where T : Component
  5. {
  6. private T component;
  7. protected abstract void AddListeners(T component);
  8. protected abstract void RemoveListeners(T component);
  9. protected virtual void OnEnable()
  10. {
  11. component = GetComponent<T>();
  12. if (component != null)
  13. {
  14. AddListeners(component);
  15. }
  16. else
  17. {
  18. string eventsScriptName = GetType().Name;
  19. string scriptName = component.GetType().Name;
  20. VRTK_Logger.Error(string.Format("The {0} script requires to be attached to a GameObject that contains a {1} script.", eventsScriptName, scriptName));
  21. }
  22. }
  23. protected virtual void OnDisable()
  24. {
  25. if (component != null)
  26. {
  27. RemoveListeners(component);
  28. }
  29. }
  30. }
  31. }