PlayerManager.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using System;
  2. using System.Linq;
  3. using SaveDataModel;
  4. using UnityEngine;
  5. namespace GameWorld
  6. {
  7. public class PlayerManager
  8. {
  9. public GameObject GameObject
  10. {
  11. get
  12. {
  13. GameObject result;
  14. if ((result = this._gameObject) == null)
  15. {
  16. result = (this._gameObject = GameObject.FindGameObjectsWithTag("Player").FirstOrDefault((GameObject p) => p.GetComponent<PlayerAction>() != null));
  17. }
  18. return result;
  19. }
  20. private set
  21. {
  22. this._gameObject = value;
  23. }
  24. }
  25. public Transform Transform
  26. {
  27. get
  28. {
  29. Transform result;
  30. if ((result = this._transform) == null)
  31. {
  32. result = ((!(this.GameObject != null)) ? null : (this._transform = this.GameObject.transform));
  33. }
  34. return result;
  35. }
  36. }
  37. public string UserName
  38. {
  39. get
  40. {
  41. return R.GameData.UserName;
  42. }
  43. }
  44. public string RoleName
  45. {
  46. get
  47. {
  48. return R.GameData.RoleName;
  49. }
  50. set
  51. {
  52. R.GameData.RoleName = value;
  53. }
  54. }
  55. public PlayerAction Action
  56. {
  57. get
  58. {
  59. PlayerAction result;
  60. if ((result = this._action) == null)
  61. {
  62. result = (this._action = this.GetComponent<PlayerAction>());
  63. }
  64. return result;
  65. }
  66. }
  67. public PlayerAbilities Abilities
  68. {
  69. get
  70. {
  71. PlayerAbilities result;
  72. if ((result = this._abilities) == null)
  73. {
  74. result = (this._abilities = this.GetComponent<PlayerAbilities>());
  75. }
  76. return result;
  77. }
  78. }
  79. public PlayerTimeController TimeController
  80. {
  81. get
  82. {
  83. PlayerTimeController result;
  84. if ((result = this._timeController) == null)
  85. {
  86. result = (this._timeController = this.GetComponent<PlayerTimeController>());
  87. }
  88. return result;
  89. }
  90. }
  91. public StateMachine StateMachine
  92. {
  93. get
  94. {
  95. StateMachine result;
  96. if ((result = this._stateMachine) == null)
  97. {
  98. result = (this._stateMachine = this.GetComponent<StateMachine>());
  99. }
  100. return result;
  101. }
  102. }
  103. public Rigidbody2D Rigidbody2D
  104. {
  105. get
  106. {
  107. Rigidbody2D result;
  108. if ((result = this._rigidbody2D) == null)
  109. {
  110. result = (this._rigidbody2D = this.GetComponent<Rigidbody2D>());
  111. }
  112. return result;
  113. }
  114. }
  115. public Enhancement Enhancement
  116. {
  117. get
  118. {
  119. return R.GameData.Enhancement;
  120. }
  121. }
  122. public PlayerActionController ActionController
  123. {
  124. get
  125. {
  126. PlayerActionController result;
  127. if ((result = this._actionController) == null)
  128. {
  129. result = (this._actionController = this.GetComponent<PlayerActionController>());
  130. }
  131. return result;
  132. }
  133. }
  134. public T GetComponent<T>()
  135. {
  136. return this.GameObject.GetComponent<T>();
  137. }
  138. public void SetPosition(Vector2 position)
  139. {
  140. this.Transform.position = new Vector3(position.x, position.y, this.Transform.position.z);
  141. }
  142. public void Kill()
  143. {
  144. this.Attribute.currentHP = 0;
  145. }
  146. public bool IsNearSceneGate()
  147. {
  148. for (int i = 0; i < R.SceneGate.GatesInCurrentScene.Count; i++)
  149. {
  150. SceneGate sceneGate = R.SceneGate.GatesInCurrentScene[i];
  151. if (MathfX.isInMiddleRange(this.Transform.position.x, sceneGate.transform.position.x, sceneGate.data.TriggerSize.x))
  152. {
  153. return true;
  154. }
  155. }
  156. return false;
  157. }
  158. public bool CanExecute()
  159. {
  160. return this.Action.pab.execute.CanExecute;
  161. }
  162. private GameObject _gameObject;
  163. private Transform _transform;
  164. private PlayerAction _action;
  165. private PlayerAbilities _abilities;
  166. private PlayerTimeController _timeController;
  167. private StateMachine _stateMachine;
  168. private Rigidbody2D _rigidbody2D;
  169. public readonly PlayerAttribute Attribute = new PlayerAttribute();
  170. private PlayerActionController _actionController;
  171. }
  172. }