CombatSenceController.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System;
  2. using System.Collections.Generic;
  3. using Common.Utility.CombatEvent;
  4. using Core.Utility;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.UTool;
  8. using GameLogic.Combat.CombatTool.SceneTool;
  9. using GameLogic.CombatScenesTool;
  10. using UnityEngine;
  11. using Utility.UITool;
  12. using Random = UnityEngine.Random;
  13. namespace GameLogic.Combat.CombatTool
  14. {
  15. public class CombatSenceController : IDisposable
  16. {
  17. private static readonly int Ran = Shader.PropertyToID("_ran");
  18. private static readonly int Pos = Shader.PropertyToID("_pos");
  19. // public CombatSencePath currBesselPath;
  20. //
  21. // public CombatSencePath NextBesselPath;
  22. private float moveTime;
  23. private Vector3 lasetPos;
  24. private float maxD = 100;
  25. private Vector3 lasetDir;
  26. public float currTime;
  27. public Transform moveRoot;
  28. // private List<CombatSencePath> reclaimSence = new List<CombatSencePath>();
  29. // protected GameObjectPool ShengShiQiuTi;
  30. private float shengShiStartSize = 3;
  31. private float shengShiEndSize = 300;
  32. // private float _shengShiAddTime;
  33. private bool _isUpdateShengShi;
  34. private SceneMonoConfigBasic SceneMonoConfig;
  35. // private RandomAllMap RandomAllMap;
  36. private float shengShiRan;
  37. public float moveSpeed = 2f;
  38. public bool isFlight;
  39. private bool _isFlightCameraFinish;
  40. private float _flightTime;
  41. private float _flightAddTime;
  42. private float _flightCurrTime;
  43. private Vector3 _flightDir;
  44. private Vector3 _flightStartDir;
  45. private float _flightStartSpeed;
  46. private float _flightSpeed;
  47. private ParticleSystemPool _flightFx1;
  48. private ParticleSystemPool _flightFx2;
  49. public Vector3 moveDir = Vector3.forward;
  50. // private List
  51. public async CTask InitScenes(string sceneName)
  52. {
  53. if (SceneMonoConfig != null)
  54. {
  55. SceneMonoConfig.Dispose();
  56. GameObject.Destroy(moveRoot.gameObject);
  57. GameObject.Destroy(SceneMonoConfig.gameObject);
  58. SceneMonoConfig = null;
  59. }
  60. shengShiRan = 0;
  61. _isUpdateShengShi = false;
  62. GameObject gameObject = new GameObject("mvoeRoot");
  63. if (string.IsNullOrEmpty(sceneName))
  64. {
  65. sceneName= "LevelBattle03";
  66. }
  67. // string sceneName = "LevelBattle03";
  68. // LevelbattleConfig levelbattleConfig = ConfigComponent.Instance.Get<LevelbattleConfig>(levelBattleId);
  69. // if (levelbattleConfig.ID > 0)
  70. // {
  71. // //sceneName= levelbattleConfig.sceneName;
  72. // }
  73. #if UNITY_EDITOR
  74. TestCombatHeroConfig testCombatHeroConfig = GameObject.FindObjectOfType<TestCombatHeroConfig>();
  75. if (testCombatHeroConfig != null)
  76. {
  77. if (!string.IsNullOrEmpty(testCombatHeroConfig.testSenceName))
  78. {
  79. sceneName = testCombatHeroConfig.testSenceName;
  80. }
  81. }
  82. #endif
  83. moveRoot = gameObject.transform;
  84. CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer();
  85. var task_a = AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>(sceneName + ".prefab",
  86. delegate(AssetHandle assetHandle)
  87. {
  88. GameObject gameObject = assetHandle.AssetObject<GameObject>();
  89. SceneMonoConfig = gameObject.GetComponent<SceneMonoConfigBasic>();
  90. SceneMonoConfig.shengShiMaterial.SetFloat(Ran, 0.1f);
  91. });
  92. cTaskAwaitBuffer.AddTask(task_a);
  93. lasetDir = Vector3.forward;
  94. lasetPos = new Vector3(0, 20, 0);
  95. await cTaskAwaitBuffer.WaitAll();
  96. // currBesselPath = InitBesselPath(lasetPos);
  97. SceneMonoConfig.Init(Camera.main.transform.parent, moveRoot);
  98. SceneMonoConfig.UpdateScene();
  99. }
  100. public Vector3 GetTarget(float d)
  101. {
  102. if (CombatController.currActiveCombat.playerHeroEntity == null)
  103. {
  104. return new Vector3(0, 20, 0);
  105. }
  106. return CombatController.currActiveCombat.playerHeroEntity.dotPos + moveDir * d;
  107. }
  108. public async CTask Flight(float time, float jiaoDu, float speed)
  109. {
  110. _flightCurrTime = 0;
  111. _flightTime = time;
  112. _flightAddTime = 1.0f / time;
  113. isFlight = true;
  114. _isFlightCameraFinish = false;
  115. Quaternion quaternion = Quaternion.Euler(0, jiaoDu, 0);
  116. _flightDir = quaternion * moveDir;
  117. _flightStartDir = moveDir;
  118. _flightStartSpeed = moveSpeed;
  119. _flightSpeed = speed;
  120. CombatController.currActiveCombat.playerHeroEntity.PlayAnim("idle2", true, 0, false, 1);
  121. CombatController.currActiveCombat.CombatCameraControllder.SetFieldOfView(90, 0.5f);
  122. GObjectPool.Instance.Recycle(_flightFx1);
  123. GObjectPool.Instance.Recycle(_flightFx2);
  124. GObjectPool.Instance.FetchAsync<ParticleSystemPool>("fx fly qi", delegate(ParticleSystemPool pool)
  125. {
  126. _flightFx1 = pool;
  127. SpecialDotInfo specialDotInfo =
  128. CombatController.currActiveCombat.playerHeroEntity.GetSpecialDotInfo("hitpos");
  129. pool.own.transform.SetParent(specialDotInfo.targetTran);
  130. pool.own.transform.localPosition = Vector3.zero;
  131. });
  132. GObjectPool.Instance.FetchAsync<ParticleSystemPool>("fx zq jian loop", delegate(ParticleSystemPool pool)
  133. {
  134. _flightFx2 = pool;
  135. pool.own.transform.SetParent(CombatController.currActiveCombat.playerHeroEntity.GameObject.transform);
  136. pool.own.transform.localPosition = Vector3.zero;
  137. });
  138. }
  139. private async CTask<SceneDecoration> GetSceneDecoration(SceneObjectConfig sceneObjectConfig)
  140. {
  141. GameObjectPool gameObjectPool = await sceneObjectConfig.GetNewPrefab();
  142. SceneDecoration sceneDecoration = CObjectPool.Instance.Fetch<SceneDecoration>();
  143. sceneDecoration.Init(gameObjectPool);
  144. GameObject g = gameObjectPool.own;
  145. g.SetActive(true);
  146. return sceneDecoration;
  147. }
  148. public void StartPayShengShi(Transform root)
  149. {
  150. shengShiRan = 1;
  151. SceneMonoConfig.shengShiMaterial.SetFloat(Ran, shengShiRan);
  152. Vector3 pos = CombatController.currActiveCombat.playerHeroEntity.dotPos - CombatController.currActiveCombat
  153. .CombatCameraControllder.Camera.transform.position;
  154. pos.z = -30;
  155. SceneMonoConfig.shengShiMaterial.SetVector(Pos, pos);
  156. _isUpdateShengShi = true;
  157. // _shengShiAddTime = 0;
  158. }
  159. public void Update(float t)
  160. {
  161. moveRoot.transform.position = GetTarget(0);
  162. SceneMonoConfig?.UpdateScene();
  163. if (_isUpdateShengShi)
  164. {
  165. // _shengShiAddTime += t * 1f;
  166. shengShiRan += t * 150;
  167. SceneMonoConfig.shengShiMaterial.SetFloat(Ran, shengShiRan);
  168. // float v = Mathf.Lerp(shengShiStartSize, shengShiEndSize, _shengShiAddTime);
  169. // ShengShiQiuTi.own.transform.localScale = Vector3.one * v;
  170. if (shengShiRan >= 200)
  171. {
  172. SceneMonoConfig.shengShiMaterial.SetFloat(Ran, 0.1f);
  173. _isUpdateShengShi = false;
  174. }
  175. }
  176. if (isFlight)
  177. {
  178. _flightCurrTime += t * _flightAddTime;
  179. moveDir = Vector3.Lerp(_flightStartDir, _flightDir, _flightCurrTime);
  180. float flightSpeedCur =
  181. AnimationCurveManager.Instance.AnimationCurveLibrary.flightSpeedCurve.Evaluate(_flightCurrTime);
  182. moveSpeed = Mathf.Lerp(_flightStartSpeed, _flightSpeed, flightSpeedCur);
  183. if (_flightCurrTime > 0.95f&&!_isFlightCameraFinish)
  184. {
  185. _isFlightCameraFinish= true;
  186. CombatController.currActiveCombat.CombatCameraControllder.SetFieldOfView(70, 1);
  187. }
  188. if (_flightCurrTime >= 1)
  189. {
  190. moveDir = _flightDir;
  191. isFlight = false;
  192. moveSpeed = 2;
  193. GObjectPool.Instance.Recycle(_flightFx1);
  194. GObjectPool.Instance.Recycle(_flightFx2);
  195. CombatController.currActiveCombat.playerHeroEntity.PlayAnim("idle", true, 0, false, 1);
  196. }
  197. }
  198. }
  199. public void Dispose()
  200. {
  201. // GObjectPool.Instance.
  202. }
  203. }
  204. }