MinMapPos.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Blue;
  2. using UnityEngine;
  3. public class MinMapPos : AbstractController
  4. {
  5. [SerializeField] private GameObject MinMapCanvas;
  6. private bool first = true;
  7. private IMinMapService minMapService;
  8. private int value;
  9. void Start()
  10. {
  11. minMapService = this.GetService<IMinMapService>();
  12. if (MinMapCanvas != null)
  13. {
  14. minMapService.setMinMap.Register(
  15. newValue =>
  16. {
  17. //Debug.LogError("新的值:" + newValue);
  18. value = newValue;
  19. if (newValue == 0)
  20. MinMapCanvas.SetActive(false);
  21. else
  22. MinMapCanvas.SetActive(true);
  23. if (first)
  24. {
  25. first = false;
  26. return;
  27. }
  28. minMapService.Set();
  29. }
  30. ).UnRegisterWhenGameObjectDestroyed(gameObject);
  31. MinMapCanvas.transform.parent = OpenXRCamera.Instance.head;
  32. }
  33. }
  34. private bool patch = true;
  35. private void Update()
  36. {
  37. //其他地方有引用小地图,控制了开关;统一由IMinMapService控制
  38. if (value == 0 && patch)
  39. {
  40. if (MinMapCanvas.activeSelf == true)
  41. {
  42. MinMapCanvas.SetActive(false);
  43. patch = false;
  44. }
  45. }
  46. }
  47. }