|
- using System;
- using System.Diagnostics;
- using SUISS.Core;
- using UnityEngine;
- using UnityEngine.EventSystems;
-
- public class WorldMap : SingletonMonobehaviour<WorldMap>
- {
- //[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<CIGIslandsManager>.Instance.IslandChangedEvent += this.OnIslandChanged;
- SingletonMonobehaviour<CIGIslandsManager>.Instance.VisitingStartedEvent += this.OnVisitingStarted;
- SingletonMonobehaviour<CIGIslandsManager>.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<CIGIslandsManager>.IsAvailable)
- {
- SingletonMonobehaviour<CIGIslandsManager>.Instance.IslandChangedEvent -= this.OnIslandChanged;
- SingletonMonobehaviour<CIGIslandsManager>.Instance.VisitingStartedEvent -= this.OnVisitingStarted;
- SingletonMonobehaviour<CIGIslandsManager>.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<CIGIslandsManager>.Instance.IsUnlocked(worldMapIsland.Island);
- bool isCurrentIsland = SingletonMonobehaviour<CIGIslandsManager>.Instance.CurrentIsland == worldMapIsland.Island;
- worldMapIsland.UpdateInfo(isCurrentIsland, isUnlocked, new Action<Island>(this.GoToIsland));
- }
- }
-
- public bool IsVisible { get; private set; }
-
- private void GoToIsland(Island island)
- {
- if (this.IsVisible && !SingletonMonobehaviour<CIGIslandsManager>.Instance.IsLoading)
- {
- SingletonMonobehaviour<CIGIslandsManager>.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);
- }
|