using System; using System.Diagnostics; using SUISS.Core; using UnityEngine; using UnityEngine.EventSystems; public class WorldMap : SingletonMonobehaviour { //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event WorldMap.WorldMapVisibilityChanged VisibilityChangedEvent; private void FireVisibilityEvent(bool visible) { if (this.VisibilityChangedEvent != null) { this.VisibilityChangedEvent(visible); } } private void Start() { this.SetDragThreshold(this._eventSystem); SingletonMonobehaviour.Instance.IslandChangedEvent += this.OnIslandChanged; SingletonMonobehaviour.Instance.VisitingStartedEvent += this.OnVisitingStarted; SingletonMonobehaviour.Instance.VisitingStoppedEvent += this.OnVisitingStopped; } private void OnVisitingStarted() { this.ShowInstant(); } private void OnVisitingStopped() { if (this.IsVisible) { this.Refresh(); } else { this.ShowInstant(); } } private void OnIslandChanged(Island island, bool isVisiting) { this.HideInstant(); } protected override void OnDestroy() { if (SingletonMonobehaviour.IsAvailable) { SingletonMonobehaviour.Instance.IslandChangedEvent -= this.OnIslandChanged; SingletonMonobehaviour.Instance.VisitingStartedEvent -= this.OnVisitingStarted; SingletonMonobehaviour.Instance.VisitingStoppedEvent -= this.OnVisitingStopped; } base.OnDestroy(); } public void ShowInstant() { if (!this.IsVisible) { this._root.SetActive(true); this.IsVisible = true; this.Refresh(); this.FireVisibilityEvent(this.IsVisible); } } public void HideInstant() { if (this.IsVisible) { this._root.SetActive(false); this.IsVisible = false; this.FireVisibilityEvent(this.IsVisible); } } public void Refresh() { int num = this._islands.Length; for (int i = 0; i < num; i++) { WorldMapIsland worldMapIsland = this._islands[i]; bool isUnlocked = SingletonMonobehaviour.Instance.IsUnlocked(worldMapIsland.Island); bool isCurrentIsland = SingletonMonobehaviour.Instance.CurrentIsland == worldMapIsland.Island; worldMapIsland.UpdateInfo(isCurrentIsland, isUnlocked, new Action(this.GoToIsland)); } } public bool IsVisible { get; private set; } private void GoToIsland(Island island) { if (this.IsVisible && !SingletonMonobehaviour.Instance.IsLoading) { SingletonMonobehaviour.Instance.LoadIsland(island, true); } } private void SetDragThreshold(EventSystem eventSystem) { float num = 72f; float num2 = 7f; int pixelDragThreshold = Mathf.RoundToInt(num2 / num * Screen.dpi); eventSystem.pixelDragThreshold = pixelDragThreshold; } [SerializeField] private WorldMapIsland[] _islands; [SerializeField] private GameObject _root; [SerializeField] private EventSystem _eventSystem; public delegate void WorldMapVisibilityChanged(bool visible); }