|
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using SUISSEngine;
- using UnityEngine;
-
- public class CIGUnlockBuildingVehicleManager : MonoBehaviour
- {
- public void OnDestroy()
- {
- for (int i = 0; i < this._vehicles.Count; i++)
- {
- this._vehicles[i].OnTargetReachedEvent -= this.OnTargetReached;
- }
- }
-
- public void SpawnVehicleAt(CIGUnlockBuilding.SVehicleSpawnInfo spawnInfo)
- {
- if (spawnInfo.vehiclePrefab != null)
- {
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(spawnInfo.vehiclePrefab);
- UnlockBuildingVehicle component = gameObject.GetComponent<UnlockBuildingVehicle>();
- if (component != null)
- {
- component.SpawnAt(this.grid, spawnInfo);
- component.OnTargetReachedEvent += this.OnTargetReached;
- component.IsLeavingMap = true;
- component.TravelDirection = 1;
- this._vehicles.Add(component);
- }
- }
- else
- {
- UnityEngine.Debug.LogWarning("Trying to spawn prefab with value 'null'");
- }
- }
-
- public IEnumerator WaitForVehicleTimer(float time, UnlockBuildingVehicle vehicle)
- {
- yield return new WaitForSeconds(time);
- vehicle.ReverseTravelDirection();
- vehicle.StartTravelling();
- vehicle.SetVisibility(true);
- yield break;
- }
-
- protected void OnTargetReached(UnlockBuildingVehicle vehicle)
- {
- float time;
- if (vehicle.IsLeavingMap)
- {
- vehicle.SetVisibility(false);
- vehicle.IsLeavingMap = false;
- time = vehicle.awayTime;
- }
- else
- {
- vehicle.IsLeavingMap = true;
- time = vehicle.dockedTime;
- }
- vehicle.StopTravelling();
- base.StartCoroutine(this.WaitForVehicleTimer(time, vehicle));
- }
-
- public IsometricGrid grid;
-
- private List<UnlockBuildingVehicle> _vehicles = new List<UnlockBuildingVehicle>();
- }
|