CombatSenceController.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 Random = UnityEngine.Random;
  12. namespace GameLogic.Combat.CombatTool
  13. {
  14. public class CombatSenceController : IDisposable
  15. {
  16. private static readonly int Ran = Shader.PropertyToID("_ran");
  17. private static readonly int Pos = Shader.PropertyToID("_pos");
  18. // public CombatSencePath currBesselPath;
  19. //
  20. // public CombatSencePath NextBesselPath;
  21. private float moveTime;
  22. private Vector3 lasetPos;
  23. private float maxD = 100;
  24. private Vector3 lasetDir;
  25. public float currTime;
  26. public Transform moveRoot;
  27. private List<CombatSencePath> reclaimSence = new List<CombatSencePath>();
  28. // protected GameObjectPool ShengShiQiuTi;
  29. private float shengShiStartSize = 3;
  30. private float shengShiEndSize = 300;
  31. // private float _shengShiAddTime;
  32. private bool _isUpdateShengShi;
  33. private SceneMonoConfigBasic SceneMonoConfig;
  34. // private RandomAllMap RandomAllMap;
  35. private float shengShiRan;
  36. // private List
  37. public async CTask InitScenes(int levelBattleId)
  38. {
  39. GameObject gameObject = new GameObject("mvoeRoot");
  40. string sceneName = "LevelBattle03";
  41. LevelbattleConfig levelbattleConfig = ConfigComponent.Instance.Get<LevelbattleConfig>(levelBattleId);
  42. if (levelbattleConfig.ID > 0)
  43. {
  44. //sceneName= levelbattleConfig.sceneName;
  45. }
  46. #if UNITY_EDITOR
  47. TestCombatHeroConfig testCombatHeroConfig = GameObject.FindObjectOfType<TestCombatHeroConfig>();
  48. if (testCombatHeroConfig != null)
  49. {
  50. if (!string.IsNullOrEmpty(testCombatHeroConfig.testSenceName))
  51. {
  52. sceneName = testCombatHeroConfig.testSenceName;
  53. }
  54. }
  55. #endif
  56. moveRoot = gameObject.transform;
  57. CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer();
  58. var task_a = AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>(sceneName + ".prefab",
  59. delegate(AssetHandle assetHandle)
  60. {
  61. GameObject gameObject = assetHandle.AssetObject<GameObject>();
  62. SceneMonoConfig = gameObject.GetComponent<SceneMonoConfigBasic>();
  63. SceneMonoConfig.shengShiMaterial.SetFloat(Ran, 0.1f);
  64. });
  65. cTaskAwaitBuffer.AddTask(task_a);
  66. lasetDir = Vector3.forward;
  67. lasetPos = new Vector3(0, 20, 0);
  68. await cTaskAwaitBuffer.WaitAll();
  69. // currBesselPath = InitBesselPath(lasetPos);
  70. SceneMonoConfig.Init(Camera.main.transform.parent, moveRoot);
  71. }
  72. private async CTask<SceneDecoration> GetSceneDecoration(SceneObjectConfig sceneObjectConfig)
  73. {
  74. GameObjectPool gameObjectPool = await sceneObjectConfig.GetNewPrefab();
  75. SceneDecoration sceneDecoration = CObjectPool.Instance.Fetch<SceneDecoration>();
  76. sceneDecoration.Init(gameObjectPool);
  77. GameObject g = gameObjectPool.own;
  78. g.SetActive(true);
  79. return sceneDecoration;
  80. }
  81. // public Vector3 GetTarget(float time)
  82. // {
  83. // if (time > 1)
  84. // {
  85. // if (NextBesselPath == null)
  86. // {
  87. // NextBesselPath = InitBesselPath(currBesselPath.b, 0);
  88. // }
  89. //
  90. // time = time % 1;
  91. // return NextBesselPath.GetValue(time);
  92. // }
  93. // else
  94. // {
  95. // return currBesselPath.GetValue(time);
  96. // }
  97. // }
  98. // public Vector3 Move(float dis)
  99. // {
  100. // float t = dis / currBesselPath.len;
  101. // currTime += t;
  102. // // Debug.Log("移动速度" + t + "/" + currBesselPath.len);
  103. //
  104. // Vector3 targetPos = Vector3.zero;
  105. // if (currTime > 0.01f)
  106. // {
  107. // if (NextBesselPath == null)
  108. // {
  109. // // int odds = Random.Range(0, 100);
  110. // // if (odds < 50)
  111. // // {
  112. // // NextBesselPath = InitBesselPath(currBesselPath.b, Random.Range(0, 100) < 50 ? -1 : 1);
  113. // // }
  114. // // else
  115. // {
  116. // NextBesselPath = InitBesselPath(currBesselPath.b);
  117. // }
  118. // }
  119. // }
  120. //
  121. // if (currTime > 1)
  122. // {
  123. // if (NextBesselPath == null)
  124. // {
  125. // NextBesselPath = InitBesselPath(currBesselPath.b);
  126. // }
  127. //
  128. // currTime = currTime % 1;
  129. // // targetPos = NextBesselPath.GetValue(currTime);
  130. // currBesselPath.reclaimTime = 3;
  131. // reclaimSence.Add(currBesselPath);
  132. // currBesselPath = NextBesselPath;
  133. // NextBesselPath = null;
  134. // CombatEventManager.Instance.Dispatch(CombatEventType.SencenBesselPathAlter, null);
  135. // }
  136. // else
  137. // {
  138. // }
  139. //
  140. // targetPos = currBesselPath.GetValue(currTime);
  141. // moveRoot.transform.position = targetPos;
  142. // return targetPos;
  143. // }
  144. public void StartPayShengShi(Transform root)
  145. {
  146. shengShiRan = 1;
  147. SceneMonoConfig.shengShiMaterial.SetFloat(Ran, shengShiRan);
  148. Vector3 pos = CombatController.currActiveCombat.playerHeroEntity.dotPos - CombatController.currActiveCombat
  149. .CombatCameraControllder.Camera.transform.position;
  150. pos.z = -30;
  151. SceneMonoConfig.shengShiMaterial.SetVector(Pos, pos);
  152. _isUpdateShengShi = true;
  153. // _shengShiAddTime = 0;
  154. }
  155. public void Update(float t)
  156. {
  157. moveRoot.transform.position = CombatController.currActiveCombat.CombatHeroController.GetTarget(0);
  158. SceneMonoConfig?.UpdateScene();
  159. // if (currBesselPath != null)
  160. // {
  161. // currBesselPath.Update(t);
  162. // }
  163. //
  164. // if (NextBesselPath != null)
  165. // {
  166. // NextBesselPath.Update(t);
  167. // }
  168. if (_isUpdateShengShi)
  169. {
  170. // _shengShiAddTime += t * 1f;
  171. shengShiRan += t * 150;
  172. SceneMonoConfig.shengShiMaterial.SetFloat(Ran, shengShiRan);
  173. // float v = Mathf.Lerp(shengShiStartSize, shengShiEndSize, _shengShiAddTime);
  174. // ShengShiQiuTi.own.transform.localScale = Vector3.one * v;
  175. if (shengShiRan >= 200)
  176. {
  177. SceneMonoConfig.shengShiMaterial.SetFloat(Ran, 0.1f);
  178. _isUpdateShengShi = false;
  179. }
  180. }
  181. for (int i = 0; i < reclaimSence.Count; i++)
  182. {
  183. CombatSencePath sencePath = reclaimSence[i];
  184. sencePath.reclaimTime -= t;
  185. if (sencePath.reclaimTime < 0)
  186. {
  187. sencePath.DormancyObj();
  188. reclaimSence.RemoveAt(i);
  189. }
  190. }
  191. }
  192. public void Dispose()
  193. {
  194. // GObjectPool.Instance.
  195. }
  196. }
  197. }