using System; using System.Collections; using Photon.Pun; using UnityEngine; public class Map : MonoBehaviour { public bool wasSpawned; public float size = 15f; public bool hasEntered; internal int levelID; internal int missingObjects; private float counter; private int readyForFrames; private bool hasCalledReady; public Rigidbody2D[] allRigs; private SpawnPoint[] spawnPoints; public Action mapIsReadyAction; public Action mapIsReadyEarlyAction; public Action mapMovingOutAction; internal bool hasRope; internal bool LoadedForAll() { return MapManager.instance.otherPlayersMostRecentlyLoadedLevel == levelID; } private void Awake() { if (!GameManager.instance || !GameManager.instance.isPlaying) { GM_Test componentInChildren = GameManager.instance.transform.root.GetComponentInChildren(includeInactive: true); componentInChildren.gameObject.SetActive(value: true); componentInChildren.testMap = true; MapManager.instance.isTestingMap = true; componentInChildren.transform.root.Find("UI/UI_MainMenu").gameObject.SetActive(value: false); hasEntered = true; } } private void Update() { counter += Time.deltaTime; if (!hasCalledReady && ((PhotonNetwork.OfflineMode && counter > 1f && hasEntered) || (hasEntered && LoadedForAll()))) { if (missingObjects <= 0) { readyForFrames++; } if (readyForFrames > 2) { StartCoroutine(StartMatch()); } } } public void MapMoveOut() { mapMovingOutAction?.Invoke(); } internal Vector3 GetRandomSpawnPos() { if (spawnPoints == null) { spawnPoints = GetComponentsInChildren(); } return spawnPoints[UnityEngine.Random.Range(0, spawnPoints.Length)].transform.position; } private IEnumerator StartMatch() { hasCalledReady = true; mapIsReadyEarlyAction?.Invoke(); yield return new WaitForSecondsRealtime(0f); allRigs = GetComponentsInChildren(); mapIsReadyAction?.Invoke(); } private void Start() { if (!PhotonNetwork.OfflineMode) { MapManager.instance.ReportMapLoaded(levelID); } if (MapManager.instance.isTestingMap) { wasSpawned = true; } if (!wasSpawned) { MapManager.instance.UnloadScene(base.gameObject.scene); } SpriteRenderer[] componentsInChildren = GetComponentsInChildren(includeInactive: true); for (int i = 0; i < componentsInChildren.Length; i++) { if ((double)componentsInChildren[i].color.a < 0.5) { continue; } componentsInChildren[i].transform.position = new Vector3(componentsInChildren[i].transform.position.x, componentsInChildren[i].transform.position.y, -3f); if (!(componentsInChildren[i].gameObject.tag == "NoMask")) { componentsInChildren[i].color = new Color(11f / 51f, 11f / 51f, 11f / 51f); if (!componentsInChildren[i].GetComponent()) { componentsInChildren[i].gameObject.AddComponent().sprite = componentsInChildren[i].sprite; } } } SpriteMask[] componentsInChildren2 = GetComponentsInChildren(); for (int j = 0; j < componentsInChildren2.Length; j++) { if (!(componentsInChildren2[j].gameObject.tag == "NoMask")) { componentsInChildren2[j].isCustomRangeActive = true; componentsInChildren2[j].frontSortingLayerID = SortingLayer.NameToID("MapParticle"); componentsInChildren2[j].frontSortingOrder = 1; componentsInChildren2[j].backSortingLayerID = SortingLayer.NameToID("MapParticle"); componentsInChildren2[j].backSortingOrder = 0; } } } }