Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

123 linhas
3.1 KiB

  1. using System;
  2. using System.Diagnostics;
  3. using SUISS.Core;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. public class WorldMap : SingletonMonobehaviour<WorldMap>
  7. {
  8. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  9. public event WorldMap.WorldMapVisibilityChanged VisibilityChangedEvent;
  10. private void FireVisibilityEvent(bool visible)
  11. {
  12. if (this.VisibilityChangedEvent != null)
  13. {
  14. this.VisibilityChangedEvent(visible);
  15. }
  16. }
  17. private void Start()
  18. {
  19. this.SetDragThreshold(this._eventSystem);
  20. SingletonMonobehaviour<CIGIslandsManager>.Instance.IslandChangedEvent += this.OnIslandChanged;
  21. SingletonMonobehaviour<CIGIslandsManager>.Instance.VisitingStartedEvent += this.OnVisitingStarted;
  22. SingletonMonobehaviour<CIGIslandsManager>.Instance.VisitingStoppedEvent += this.OnVisitingStopped;
  23. }
  24. private void OnVisitingStarted()
  25. {
  26. this.ShowInstant();
  27. }
  28. private void OnVisitingStopped()
  29. {
  30. if (this.IsVisible)
  31. {
  32. this.Refresh();
  33. }
  34. else
  35. {
  36. this.ShowInstant();
  37. }
  38. }
  39. private void OnIslandChanged(Island island, bool isVisiting)
  40. {
  41. this.HideInstant();
  42. }
  43. protected override void OnDestroy()
  44. {
  45. if (SingletonMonobehaviour<CIGIslandsManager>.IsAvailable)
  46. {
  47. SingletonMonobehaviour<CIGIslandsManager>.Instance.IslandChangedEvent -= this.OnIslandChanged;
  48. SingletonMonobehaviour<CIGIslandsManager>.Instance.VisitingStartedEvent -= this.OnVisitingStarted;
  49. SingletonMonobehaviour<CIGIslandsManager>.Instance.VisitingStoppedEvent -= this.OnVisitingStopped;
  50. }
  51. base.OnDestroy();
  52. }
  53. public void ShowInstant()
  54. {
  55. if (!this.IsVisible)
  56. {
  57. this._root.SetActive(true);
  58. this.IsVisible = true;
  59. this.Refresh();
  60. this.FireVisibilityEvent(this.IsVisible);
  61. }
  62. }
  63. public void HideInstant()
  64. {
  65. if (this.IsVisible)
  66. {
  67. this._root.SetActive(false);
  68. this.IsVisible = false;
  69. this.FireVisibilityEvent(this.IsVisible);
  70. }
  71. }
  72. public void Refresh()
  73. {
  74. int num = this._islands.Length;
  75. for (int i = 0; i < num; i++)
  76. {
  77. WorldMapIsland worldMapIsland = this._islands[i];
  78. bool isUnlocked = SingletonMonobehaviour<CIGIslandsManager>.Instance.IsUnlocked(worldMapIsland.Island);
  79. bool isCurrentIsland = SingletonMonobehaviour<CIGIslandsManager>.Instance.CurrentIsland == worldMapIsland.Island;
  80. worldMapIsland.UpdateInfo(isCurrentIsland, isUnlocked, new Action<Island>(this.GoToIsland));
  81. }
  82. }
  83. public bool IsVisible { get; private set; }
  84. private void GoToIsland(Island island)
  85. {
  86. if (this.IsVisible && !SingletonMonobehaviour<CIGIslandsManager>.Instance.IsLoading)
  87. {
  88. SingletonMonobehaviour<CIGIslandsManager>.Instance.LoadIsland(island, true);
  89. }
  90. }
  91. private void SetDragThreshold(EventSystem eventSystem)
  92. {
  93. float num = 72f;
  94. float num2 = 7f;
  95. int pixelDragThreshold = Mathf.RoundToInt(num2 / num * Screen.dpi);
  96. eventSystem.pixelDragThreshold = pixelDragThreshold;
  97. }
  98. [SerializeField]
  99. private WorldMapIsland[] _islands;
  100. [SerializeField]
  101. private GameObject _root;
  102. [SerializeField]
  103. private EventSystem _eventSystem;
  104. public delegate void WorldMapVisibilityChanged(bool visible);
  105. }