using UnityEngine; using WebTools.Currencies.Behaviours; using DataTools; using System.Collections.Generic; public class LocationsManager : MonoBehaviour { public static LocationsManager Instance; [Header("DATAUSER")] [SerializeField] private DataUser dataUser; [SerializeField] private List locations; [SerializeField] private float changeLocationDelay; [SerializeField] private FlyPreloaderController preloaderPanel; private GameObject instantiateLocation; private string loadLocation; private Location currentLocation; private string airportCountry; public List Locations { get { return locations; } } private void Awake() { Instance = this; } private void Start() { loadLocation = GameGlobal.Instance.Location; SetNewLocation(); } private void ClearLocation() { if (instantiateLocation != null) Destroy(instantiateLocation); Resources.UnloadUnusedAssets(); } private void InstantiateLocation(GameObject locationGO) { instantiateLocation = Instantiate(locationGO, Vector3.zero, Quaternion.identity) as GameObject; instantiateLocation.transform.SetParent(transform); instantiateLocation.transform.position = Vector3.zero; instantiateLocation.SetActive(true); currentLocation = instantiateLocation.GetComponent(); Navigation.Instance.SetLimitLocation(currentLocation.LimitL, currentLocation.LimitR, currentLocation.startPostX); PanelCurrenciesBehaviour.Instance.ActiveAnimation(currentLocation.isMap); AnimationPanelMain.Instance.ActiveBottomUIElements(currentLocation.isMap); } private void SetNewLocation() { foreach (string location in locations) { if (location.ToUpper() == loadLocation.ToUpper()) { ClearLocation(); InstantiateLocation(Resources.Load(location) as GameObject); GameGlobal.Instance.SetLocation(currentLocation, currentLocation.isMap); break; } } FadeScreen.Instance.FadeOut(0.5f, null); preloaderPanel.gameObject.SetActive(false); } private void CommonChangeLocationAction(string newLocation, bool isContainMap) { //BlockerManager.Instance.UnblockAllButtons(isFirstGigPassed); loadLocation = newLocation; if (!isContainMap) { dataUser.UserData.ProgressData.Location = loadLocation; dataUser.UpdateUserProgress(); } else airportCountry = currentLocation.AirportLocationName; } public void ChangeLocation(string newLocation) { CommonChangeLocationAction(newLocation, newLocation.ToUpper().Contains("MAP")); FadeScreen.Instance.FadeIn(2f, null); Invoke("SetNewLocation", changeLocationDelay); } public void FlyToLocation(string newLocation, string destinationCountry) { CommonChangeLocationAction(newLocation, false); preloaderPanel.DeparturePoint = airportCountry; preloaderPanel.DestinationPoint = destinationCountry; FadeScreen.Instance.FadeIn(0.5f, null); preloaderPanel.gameObject.SetActive(true); Invoke("SetNewLocation", 3f); } }