123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- 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<string> locations;
- [SerializeField]
- private float changeLocationDelay;
- [SerializeField]
- private FlyPreloaderController preloaderPanel;
- private GameObject instantiateLocation;
- private string loadLocation;
- private Location currentLocation;
- private string airportCountry;
- public List<string> 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<Location>();
- 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);
- }
- }
|