Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

69 строки
1.7 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using SUISSEngine;
  5. using UnityEngine;
  6. public class CIGUnlockBuildingVehicleManager : MonoBehaviour
  7. {
  8. public void OnDestroy()
  9. {
  10. for (int i = 0; i < this._vehicles.Count; i++)
  11. {
  12. this._vehicles[i].OnTargetReachedEvent -= this.OnTargetReached;
  13. }
  14. }
  15. public void SpawnVehicleAt(CIGUnlockBuilding.SVehicleSpawnInfo spawnInfo)
  16. {
  17. if (spawnInfo.vehiclePrefab != null)
  18. {
  19. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(spawnInfo.vehiclePrefab);
  20. UnlockBuildingVehicle component = gameObject.GetComponent<UnlockBuildingVehicle>();
  21. if (component != null)
  22. {
  23. component.SpawnAt(this.grid, spawnInfo);
  24. component.OnTargetReachedEvent += this.OnTargetReached;
  25. component.IsLeavingMap = true;
  26. component.TravelDirection = 1;
  27. this._vehicles.Add(component);
  28. }
  29. }
  30. else
  31. {
  32. UnityEngine.Debug.LogWarning("Trying to spawn prefab with value 'null'");
  33. }
  34. }
  35. public IEnumerator WaitForVehicleTimer(float time, UnlockBuildingVehicle vehicle)
  36. {
  37. yield return new WaitForSeconds(time);
  38. vehicle.ReverseTravelDirection();
  39. vehicle.StartTravelling();
  40. vehicle.SetVisibility(true);
  41. yield break;
  42. }
  43. protected void OnTargetReached(UnlockBuildingVehicle vehicle)
  44. {
  45. float time;
  46. if (vehicle.IsLeavingMap)
  47. {
  48. vehicle.SetVisibility(false);
  49. vehicle.IsLeavingMap = false;
  50. time = vehicle.awayTime;
  51. }
  52. else
  53. {
  54. vehicle.IsLeavingMap = true;
  55. time = vehicle.dockedTime;
  56. }
  57. vehicle.StopTravelling();
  58. base.StartCoroutine(this.WaitForVehicleTimer(time, vehicle));
  59. }
  60. public IsometricGrid grid;
  61. private List<UnlockBuildingVehicle> _vehicles = new List<UnlockBuildingVehicle>();
  62. }