LocationsManager.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using UnityEngine;
  2. using WebTools.Currencies.Behaviours;
  3. using DataTools;
  4. using System.Collections.Generic;
  5. public class LocationsManager : MonoBehaviour
  6. {
  7. public static LocationsManager Instance;
  8. [Header("DATAUSER")]
  9. [SerializeField]
  10. private DataUser dataUser;
  11. [SerializeField]
  12. private List<string> locations;
  13. [SerializeField]
  14. private float changeLocationDelay;
  15. [SerializeField]
  16. private FlyPreloaderController preloaderPanel;
  17. private GameObject instantiateLocation;
  18. private string loadLocation;
  19. private Location currentLocation;
  20. private string airportCountry;
  21. public List<string> Locations { get { return locations; } }
  22. private void Awake()
  23. {
  24. Instance = this;
  25. }
  26. private void Start()
  27. {
  28. loadLocation = GameGlobal.Instance.Location;
  29. SetNewLocation();
  30. }
  31. private void ClearLocation()
  32. {
  33. if (instantiateLocation != null)
  34. Destroy(instantiateLocation);
  35. Resources.UnloadUnusedAssets();
  36. }
  37. private void InstantiateLocation(GameObject locationGO)
  38. {
  39. instantiateLocation = Instantiate(locationGO, Vector3.zero, Quaternion.identity) as GameObject;
  40. instantiateLocation.transform.SetParent(transform);
  41. instantiateLocation.transform.position = Vector3.zero;
  42. instantiateLocation.SetActive(true);
  43. currentLocation = instantiateLocation.GetComponent<Location>();
  44. Navigation.Instance.SetLimitLocation(currentLocation.LimitL, currentLocation.LimitR, currentLocation.startPostX);
  45. PanelCurrenciesBehaviour.Instance.ActiveAnimation(currentLocation.isMap);
  46. AnimationPanelMain.Instance.ActiveBottomUIElements(currentLocation.isMap);
  47. }
  48. private void SetNewLocation()
  49. {
  50. foreach (string location in locations)
  51. {
  52. if (location.ToUpper() == loadLocation.ToUpper())
  53. {
  54. ClearLocation();
  55. InstantiateLocation(Resources.Load(location) as GameObject);
  56. GameGlobal.Instance.SetLocation(currentLocation, currentLocation.isMap);
  57. break;
  58. }
  59. }
  60. FadeScreen.Instance.FadeOut(0.5f, null);
  61. preloaderPanel.gameObject.SetActive(false);
  62. }
  63. private void CommonChangeLocationAction(string newLocation, bool isContainMap)
  64. {
  65. //BlockerManager.Instance.UnblockAllButtons(isFirstGigPassed);
  66. loadLocation = newLocation;
  67. if (!isContainMap)
  68. {
  69. dataUser.UserData.ProgressData.Location = loadLocation;
  70. dataUser.UpdateUserProgress();
  71. }
  72. else
  73. airportCountry = currentLocation.AirportLocationName;
  74. }
  75. public void ChangeLocation(string newLocation)
  76. {
  77. CommonChangeLocationAction(newLocation, newLocation.ToUpper().Contains("MAP"));
  78. FadeScreen.Instance.FadeIn(2f, null);
  79. Invoke("SetNewLocation", changeLocationDelay);
  80. }
  81. public void FlyToLocation(string newLocation, string destinationCountry)
  82. {
  83. CommonChangeLocationAction(newLocation, false);
  84. preloaderPanel.DeparturePoint = airportCountry;
  85. preloaderPanel.DestinationPoint = destinationCountry;
  86. FadeScreen.Instance.FadeIn(0.5f, null);
  87. preloaderPanel.gameObject.SetActive(true);
  88. Invoke("SetNewLocation", 3f);
  89. }
  90. }