AbstractRadar.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // MIT License
  2. // https://gitlab.com/ilnprj
  3. // Copyright (c) 2020 ilnprj
  4. using UnityEngine;
  5. namespace RadarComponents
  6. {
  7. /// <summary>
  8. /// Abstract radar class. Works when updating a player’s locator
  9. /// </summary>
  10. [RequireComponent(typeof(ContainerTargetsView))]
  11. public abstract class AbstractRadar : MonoBehaviour
  12. {
  13. public bool TargetsFadeOut
  14. {
  15. get
  16. {
  17. return targetsFadeOut;
  18. }
  19. }
  20. protected PlayerLocator locator = null;
  21. protected ContainerTargetsView containerViews;
  22. [SerializeField]
  23. private bool targetsFadeOut = default;
  24. private ContainerTargetManager containerTargets;
  25. protected virtual void Awake()
  26. {
  27. CheckLocator();
  28. containerViews = GetComponent<ContainerTargetsView>();
  29. containerTargets = FindObjectOfType<ContainerTargetManager>();
  30. }
  31. protected virtual void Start()
  32. {
  33. containerViews.SetTargetManager(containerTargets.TargetManager);
  34. }
  35. private void CheckLocator()
  36. {
  37. if (PlayerLocator.IsInited)
  38. {
  39. locator = FindObjectOfType<PlayerLocator>();
  40. }
  41. else
  42. {
  43. PlayerLocator.onInit += SetLocator;
  44. }
  45. PlayerLocator.onUpdateLocator += OnUpdateRadar;
  46. }
  47. protected virtual void OnDestroy()
  48. {
  49. PlayerLocator.onInit -= SetLocator;
  50. PlayerLocator.onUpdateLocator -= OnUpdateRadar;
  51. }
  52. private void SetLocator()
  53. {
  54. locator = FindObjectOfType<PlayerLocator>();
  55. }
  56. /// <summary>
  57. /// Update information on radar
  58. /// </summary>
  59. public abstract void OnUpdateRadar();
  60. }
  61. }