Detector.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. namespace Leap.Unity
  5. {
  6. public class Detector : MonoBehaviour
  7. {
  8. public bool IsActive
  9. {
  10. get
  11. {
  12. return this._isActive;
  13. }
  14. }
  15. public virtual void Activate()
  16. {
  17. if (!this.IsActive)
  18. {
  19. this._isActive = true;
  20. this.OnActivate.Invoke();
  21. }
  22. }
  23. public virtual void Deactivate()
  24. {
  25. if (this.IsActive)
  26. {
  27. this._isActive = false;
  28. this.OnDeactivate.Invoke();
  29. }
  30. }
  31. private bool _isActive;
  32. [Tooltip("Draw this detector's Gizmos, if any. (Gizmos must be on in Unity edtor, too.)")]
  33. public bool ShowGizmos = true;
  34. [Tooltip("Dispatched when condition is detected.")]
  35. public UnityEvent OnActivate;
  36. [Tooltip("Dispatched when condition is no longer detected.")]
  37. public UnityEvent OnDeactivate;
  38. protected Color OnColor = Color.green;
  39. protected Color OffColor = Color.red;
  40. protected Color LimitColor = Color.blue;
  41. protected Color DirectionColor = Color.white;
  42. protected Color NormalColor = Color.gray;
  43. }
  44. }