Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. using Engine;
  2. using Engine.Attributes;
  3. using Engine.Components;
  4. using Game.Games.Planes.Blocks;
  5. using Game.Games.Planes.Hangars;
  6. using Game.Games.Planes.Vehicles;
  7. using UnityEngine;
  8.  
  9. namespace Game.Games.Planes
  10. {
  11. //! PlaneGameSession \author Serheo \date 2019/01/08 16:19:44
  12. public class PlaneGameSession : ResettableComponent
  13. {
  14. [SerializeField, FieldName("Plane Camera")]
  15. private PlaneCamera _planeCamera = null;
  16.  
  17. [SerializeField]
  18. private BlockManager _blockManager = null;
  19.  
  20. [SerializeField, FieldName("RunwayNew")]
  21. private RunWayManagerNew _runwayNew = null;
  22.  
  23. [SerializeField]
  24. private HangarManager _hangarManager = null;
  25.  
  26. [SerializeField]
  27. private HangarLinkContainer _hangarLinks = null;
  28.  
  29. [SerializeField]
  30. private float _hangarActivationDelay = 7.5f;
  31.  
  32. public Animator[] heroAnimators;
  33.  
  34. public static int lastDirection = 1;
  35.  
  36. private PlaneBehaviour _plane = null;
  37. private GameObject _currentHangar = null;
  38.  
  39. private Animator _selectedHeroAnimator;
  40.  
  41. public GameObject PlaneObject => _plane != null ? _plane.gameObject : null;
  42.  
  43. public PlaneBehaviour Plane
  44. {
  45. get => _plane;
  46. set
  47. {
  48. if (object.ReferenceEquals(_plane, value))
  49. {
  50. return;
  51. }
  52. if (_plane != null)
  53. {
  54. _plane.FlightStatusChanged.RemoveListener(OnPlaneFlightStatusChanged);
  55. }
  56. _plane = value;
  57. if (_plane != null)
  58. {
  59. _plane.FlightStatusChanged.AddListener(OnPlaneFlightStatusChanged);
  60. }
  61. }
  62. }
  63.  
  64. //! OnExpose \author Serheo \date 2019/01/10 15:35:29
  65. protected override void OnExpose()
  66. {
  67. base.OnExpose();
  68. IoC.AddInstance(this);
  69. }
  70.  
  71. //! OnDispose \author Serheo \date 2019/01/10 15:36:12
  72. protected override void OnDispose()
  73. {
  74. base.OnDispose();
  75. IoC.RemoveInstance(this);
  76. }
  77.  
  78. //! Start \author Serheo \date 2019/01/10 15:52:01
  79. private void Start()
  80. {
  81. if (_planeCamera != null)
  82. {
  83. _planeCamera.Target = (_plane != null && _plane.CameraOperator != null)
  84. ? _plane.CameraOperator.gameObject
  85. : null;
  86. }
  87.  
  88. if (_hangarManager != null)
  89. {
  90. _hangarManager.CreateHangar(0f);
  91. _currentHangar = _hangarManager._hangarObject;
  92. }
  93.  
  94. foreach (Animator heroAnimator in heroAnimators)
  95. {
  96. if (heroAnimator != null)
  97. heroAnimator.gameObject.SetActive(false);
  98. }
  99. }
  100.  
  101. public void OnLandingDone()
  102. {
  103. _plane.enabled = false;
  104.  
  105. _planeCamera.Target = _currentHangar;
  106.  
  107. lastDirection = GetPlaneDirection();
  108. FreePlane();
  109. }
  110.  
  111. public void FreePlane()
  112. {
  113. if (_selectedHeroAnimator != null)
  114. {
  115. Destroy(_selectedHeroAnimator.gameObject);
  116. _selectedHeroAnimator = null;
  117. }
  118.  
  119. if (_plane != null)
  120. {
  121. Destroy(_plane.gameObject);
  122. _plane = null;
  123. }
  124. }
  125.  
  126. //! OnPlaneFilghtStatuChanged \author Serheo \date 2019/04/04 14:46:30
  127. private void OnPlaneFlightStatusChanged()
  128. {
  129. if (_plane == null || _plane.FlightStatus)
  130. return;
  131.  
  132. _hangarManager.CreateHangar(_plane, _hangarActivationDelay);
  133. _currentHangar = _hangarManager._hangarObject;
  134. }
  135.  
  136. public static Animator GetSelectedHeroAnimator()
  137. {
  138. PlaneGameSession planeGameSession;
  139. IoC.TryResolve(out planeGameSession);
  140. if (planeGameSession == null) return null;
  141.  
  142. // returns animator of the selected hero
  143. return planeGameSession._selectedHeroAnimator;
  144. }
  145.  
  146. public static PlaneGameSession GetInstance()
  147. {
  148. PlaneGameSession planeGameSession;
  149. IoC.TryResolve(out planeGameSession);
  150. return planeGameSession;
  151. }
  152.  
  153. public static int GetPlaneDirection()
  154. {
  155. PlaneGameSession planeGameSession = GetInstance();
  156.  
  157. if (planeGameSession.Plane != null)
  158. {
  159. if (planeGameSession.Plane.Orientation == PlaneOrientation.Left)
  160. return -1; // LEFT
  161. }
  162.  
  163. return 1; // RIGHT
  164. }
  165.  
  166. public PlaneCamera GetPlaneCamera()
  167. {
  168. PlaneGameSession planeGameSession = GetInstance();
  169.  
  170. if(planeGameSession.Plane != null)
  171. return _planeCamera;
  172.  
  173. return null;
  174. }
  175.  
  176. public GameObject GetCurrentHangar()
  177. {
  178. if(_currentHangar != null)
  179. return _currentHangar;
  180.  
  181. return null;
  182. }
  183. }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement