using System.Collections.Generic; using Photon.VR.Player; using UnityEngine; namespace BlockSpace.Gamemodes { [DisallowMultipleComponent] public sealed class GamemodeZoneManager : MonoBehaviour { private readonly List zones = new List(); public static GamemodeZoneManager Instance { get; private set; } public GamemodeZone CurrentZone { get; private set; } private void Awake() { if (Instance != null && Instance != this) { Object.Destroy(base.gameObject); } else { Instance = this; } } private void OnDestroy() { if (Instance == this) { Instance = null; } } private void Update() { RefreshZonesFromPlayerPositions(); } internal void RegisterZone(GamemodeZone zone) { if (!(zone == null) && !zones.Contains(zone)) { zones.Add(zone); } } internal void UnregisterZone(GamemodeZone zone) { if (!(zone == null)) { zones.Remove(zone); if (CurrentZone == zone) { CurrentZone = null; } } } private void RefreshZonesFromPlayerPositions() { if (zones.Count == 0) { CurrentZone = null; return; } PhotonVRPlayer[] array = Object.FindObjectsByType(FindObjectsInactive.Include); PhotonVRPlayer photonVRPlayer = null; foreach (PhotonVRPlayer photonVRPlayer2 in array) { if (!(photonVRPlayer2 == null) && photonVRPlayer2.photonView != null && photonVRPlayer2.photonView.IsMine) { photonVRPlayer = photonVRPlayer2; } } CurrentZone = null; Vector3 worldPosition = ((photonVRPlayer != null) ? GamemodeZone.GetPlayerZonePosition(photonVRPlayer) : Vector3.zero); for (int j = 0; j < zones.Count; j++) { GamemodeZone gamemodeZone = zones[j]; if (!(gamemodeZone == null)) { gamemodeZone.RefreshPlayersInside(array); if (photonVRPlayer != null && CurrentZone == null && gamemodeZone.ContainsWorldPosition(worldPosition)) { CurrentZone = gamemodeZone; } } } } } }