Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Engine;
- using Engine.Attributes;
- using Engine.Components;
- using Game.Games.Planes.Blocks;
- using Game.Games.Planes.Hangars;
- using Game.Games.Planes.Vehicles;
- using UnityEngine;
- namespace Game.Games.Planes
- {
- //! PlaneGameSession \author Serheo \date 2019/01/08 16:19:44
- public class PlaneGameSession : ResettableComponent
- {
- [SerializeField, FieldName("Plane Camera")]
- private PlaneCamera _planeCamera = null;
- [SerializeField]
- private BlockManager _blockManager = null;
- [SerializeField, FieldName("RunwayNew")]
- private RunWayManagerNew _runwayNew = null;
- [SerializeField]
- private HangarManager _hangarManager = null;
- [SerializeField]
- private HangarLinkContainer _hangarLinks = null;
- [SerializeField]
- private float _hangarActivationDelay = 7.5f;
- public Animator[] heroAnimators;
- public static int lastDirection = 1;
- private PlaneBehaviour _plane = null;
- private GameObject _currentHangar = null;
- private Animator _selectedHeroAnimator;
- public GameObject PlaneObject => _plane != null ? _plane.gameObject : null;
- public PlaneBehaviour Plane
- {
- get => _plane;
- set
- {
- if (object.ReferenceEquals(_plane, value))
- {
- return;
- }
- if (_plane != null)
- {
- _plane.FlightStatusChanged.RemoveListener(OnPlaneFlightStatusChanged);
- }
- _plane = value;
- if (_plane != null)
- {
- _plane.FlightStatusChanged.AddListener(OnPlaneFlightStatusChanged);
- }
- }
- }
- //! OnExpose \author Serheo \date 2019/01/10 15:35:29
- protected override void OnExpose()
- {
- base.OnExpose();
- IoC.AddInstance(this);
- }
- //! OnDispose \author Serheo \date 2019/01/10 15:36:12
- protected override void OnDispose()
- {
- base.OnDispose();
- IoC.RemoveInstance(this);
- }
- //! Start \author Serheo \date 2019/01/10 15:52:01
- private void Start()
- {
- if (_planeCamera != null)
- {
- _planeCamera.Target = (_plane != null && _plane.CameraOperator != null)
- ? _plane.CameraOperator.gameObject
- : null;
- }
- if (_hangarManager != null)
- {
- _hangarManager.CreateHangar(0f);
- _currentHangar = _hangarManager._hangarObject;
- }
- foreach (Animator heroAnimator in heroAnimators)
- {
- if (heroAnimator != null)
- heroAnimator.gameObject.SetActive(false);
- }
- }
- public void OnLandingDone()
- {
- _plane.enabled = false;
- _planeCamera.Target = _currentHangar;
- lastDirection = GetPlaneDirection();
- FreePlane();
- }
- public void FreePlane()
- {
- if (_selectedHeroAnimator != null)
- {
- Destroy(_selectedHeroAnimator.gameObject);
- _selectedHeroAnimator = null;
- }
- if (_plane != null)
- {
- Destroy(_plane.gameObject);
- _plane = null;
- }
- }
- //! OnPlaneFilghtStatuChanged \author Serheo \date 2019/04/04 14:46:30
- private void OnPlaneFlightStatusChanged()
- {
- if (_plane == null || _plane.FlightStatus)
- return;
- _hangarManager.CreateHangar(_plane, _hangarActivationDelay);
- _currentHangar = _hangarManager._hangarObject;
- }
- public static Animator GetSelectedHeroAnimator()
- {
- PlaneGameSession planeGameSession;
- IoC.TryResolve(out planeGameSession);
- if (planeGameSession == null) return null;
- // returns animator of the selected hero
- return planeGameSession._selectedHeroAnimator;
- }
- public static PlaneGameSession GetInstance()
- {
- PlaneGameSession planeGameSession;
- IoC.TryResolve(out planeGameSession);
- return planeGameSession;
- }
- public static int GetPlaneDirection()
- {
- PlaneGameSession planeGameSession = GetInstance();
- if (planeGameSession.Plane != null)
- {
- if (planeGameSession.Plane.Orientation == PlaneOrientation.Left)
- return -1; // LEFT
- }
- return 1; // RIGHT
- }
- public PlaneCamera GetPlaneCamera()
- {
- PlaneGameSession planeGameSession = GetInstance();
- if(planeGameSession.Plane != null)
- return _planeCamera;
- return null;
- }
- public GameObject GetCurrentHangar()
- {
- if(_currentHangar != null)
- return _currentHangar;
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement