CombatSenceController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. using System;
  2. using System.Collections.Generic;
  3. using Common.Utility.CombatEvent;
  4. using Core.Utility;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Combat.CombatTool.SceneTool;
  8. using GameLogic.CombatScenesTool;
  9. using UnityEngine;
  10. using Random = UnityEngine.Random;
  11. namespace GameLogic.Combat.CombatTool
  12. {
  13. public class CombatSenceController : IDisposable
  14. {
  15. private static readonly int Ran = Shader.PropertyToID("_ran");
  16. private static readonly int Pos = Shader.PropertyToID("_pos");
  17. public CombatSencePath currBesselPath;
  18. public CombatSencePath NextBesselPath;
  19. private float moveTime;
  20. private Vector3 lasetPos;
  21. private float maxD = 100;
  22. private Vector3 lasetDir;
  23. public float currTime;
  24. public Transform moveRoot;
  25. private List<CombatSencePath> reclaimSence = new List<CombatSencePath>();
  26. // protected GameObjectPool ShengShiQiuTi;
  27. private float shengShiStartSize = 3;
  28. private float shengShiEndSize = 300;
  29. // private float _shengShiAddTime;
  30. private bool _isUpdateShengShi;
  31. private SceneMonoConfig SceneMonoConfig;
  32. // private RandomAllMap RandomAllMap;
  33. private float shengShiRan;
  34. // private List
  35. public async CTask InitScenes()
  36. {
  37. GameObject gameObject = new GameObject("mvoeRoot");
  38. moveRoot = gameObject.transform;
  39. CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer();
  40. var task_a = AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>("LevelBattle02.prefab",
  41. delegate(AssetHandle assetHandle)
  42. {
  43. GameObject gameObject = assetHandle.AssetObject<GameObject>();
  44. SceneMonoConfig = gameObject.GetComponent<SceneMonoConfig>();
  45. SceneMonoConfig.shengShiMaterial.SetFloat(Ran,0.1f);
  46. });
  47. cTaskAwaitBuffer.AddTask(task_a);
  48. // ShengShiQiuTi =
  49. // await GObjectPool.Instance.FetchAsync<GameObjectPool>("ShengShiQiuTi", null, null, false,
  50. // "ShengShiQiuTi");
  51. // ShengShiQiuTi.SetActive(false);
  52. lasetDir = Vector3.forward;
  53. lasetPos = new Vector3(0, 20, 0);
  54. await cTaskAwaitBuffer.WaitAll();
  55. currBesselPath = InitBesselPath(lasetPos);
  56. SceneMonoConfig.Init(Camera.main.transform.parent,moveRoot);
  57. // RandomAllMap = new RandomAllMap();
  58. // RandomAllMap.Init(moveRoot, SceneMonoConfig);
  59. // RandomAllMap.Update();
  60. }
  61. private CombatSencePath InitBesselPath(Vector3 satrtPos)
  62. {
  63. CombatSencePath besselPath = new CombatSencePath();
  64. Vector3 target = satrtPos + lasetDir.normalized * maxD;
  65. // if (offx == 0)
  66. {
  67. besselPath.SetPos(satrtPos, target);
  68. }
  69. Vector3 p = besselPath.GetValue(0.99f);
  70. lasetDir = (target - p).normalized;
  71. // GameObject gameObject = new GameObject("path");
  72. // gameObject.transform.position = satrtPos;
  73. // CombatPathMono combatPathMono = gameObject.AddComponent<CombatPathMono>();
  74. // combatPathMono.BesselPath = besselPath;
  75. InitZhuangSHi(besselPath);
  76. return besselPath;
  77. }
  78. private CombatSencePath InitBesselPath(Vector3 satrtPos, float offx)
  79. {
  80. CombatSencePath besselPath = new CombatSencePath();
  81. Vector3 dir = Quaternion.LookRotation(lasetDir) * new Vector3(offx, 0, 1);
  82. Vector3 target = satrtPos + dir.normalized * maxD;
  83. Vector3 dir2 = Quaternion.LookRotation(lasetDir) * new Vector3(offx * -1, 0, 1);
  84. dir2 = dir2.normalized;
  85. Vector3 centre = satrtPos + dir2.normalized * maxD;
  86. // if (offx == 0)
  87. {
  88. besselPath.SetPos(satrtPos, centre, target);
  89. }
  90. Vector3 p = besselPath.GetValue(0.99f);
  91. lasetDir = (target - p).normalized;
  92. // GameObject gameObject = new GameObject("path");
  93. // gameObject.transform.position = satrtPos;
  94. // CombatPathMono combatPathMono = gameObject.AddComponent<CombatPathMono>();
  95. // combatPathMono.BesselPath = besselPath;
  96. InitZhuangSHi(besselPath);
  97. return besselPath;
  98. }
  99. private async CTask InitZhuangSHi(CombatSencePath besselPath)
  100. {
  101. // InitRoadside(besselPath);
  102. // InitRoadside_1(besselPath);
  103. // InitButton(besselPath);
  104. }
  105. // private async CTask InitRoadside(CombatSencePath besselPath)
  106. // {
  107. // SceneConfig sceneConfig = SceneMonoConfig.roadside;
  108. // int count = Random.Range(sceneConfig.minCount, sceneConfig.maxCount);
  109. // for (int i = 0; i < count; i++)
  110. // {
  111. // SceneObjectConfig sceneObjectConfig = sceneConfig.GetSceneObjectConfig();
  112. // if (sceneObjectConfig == null)
  113. // {
  114. // continue;
  115. // }
  116. //
  117. // float md = Random.Range(0.05f, 1f);
  118. // Vector3 p = besselPath.GetValue(md);
  119. // Vector3 p2 = besselPath.GetValue(md - 0.01f);
  120. // Vector3 dir = (p - p2);
  121. // Vector3 cross = Vector3.Cross(dir, Vector3.up);
  122. // cross = cross.normalized;
  123. // int odds = Random.Range(0, 100);
  124. // p += cross * Random.Range(12, 25) * (odds < 50 ? 1 : -1);
  125. // SceneDecoration gameObjectPool = await GetSceneDecoration(sceneObjectConfig);
  126. // GameObject g = gameObjectPool.pool.own;
  127. // besselPath.allPool.Add(gameObjectPool);
  128. // float y = Random.Range(sceneObjectConfig.minY, sceneObjectConfig.maxY);
  129. // g.transform.position = new Vector3(p.x, y, p.z);
  130. // g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360));
  131. // }
  132. // }
  133. // private async CTask InitRoadside_1(CombatSencePath besselPath)
  134. // {
  135. // SceneConfig sceneConfig = SceneMonoConfig.roadside_1;
  136. // int count = Random.Range(sceneConfig.minCount, sceneConfig.maxCount);
  137. // for (int i = 0; i < count; i++)
  138. // {
  139. // SceneObjectConfig sceneObjectConfig = sceneConfig.GetSceneObjectConfig();
  140. // if (sceneObjectConfig == null)
  141. // {
  142. // continue;
  143. // }
  144. //
  145. // float md = Random.Range(0.05f, 1f);
  146. // Vector3 p = besselPath.GetValue(md);
  147. // Vector3 p2 = besselPath.GetValue(md - 0.01f);
  148. // Vector3 dir = (p - p2);
  149. // Vector3 cross = Vector3.Cross(dir, Vector3.up);
  150. // cross = cross.normalized;
  151. // int odds = Random.Range(0, 100);
  152. // p += cross * Random.Range(40, 60) * (odds < 50 ? 1 : -1);
  153. // SceneDecoration gameObjectPool = await GetSceneDecoration(sceneObjectConfig);
  154. // GameObject g = gameObjectPool.pool.own;
  155. // besselPath.allPool.Add(gameObjectPool);
  156. // float y = Random.Range(sceneObjectConfig.minY, sceneObjectConfig.maxY);
  157. // g.transform.position = new Vector3(p.x, y, p.z);
  158. // g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360));
  159. // }
  160. // }
  161. // private async CTask InitButton(CombatSencePath besselPath)
  162. // {
  163. // SceneConfig sceneConfig = SceneMonoConfig.button;
  164. // int count = Random.Range(sceneConfig.minCount, sceneConfig.maxCount);
  165. // for (int i = 0; i < count; i++)
  166. // {
  167. // SceneObjectConfig sceneObjectConfig = sceneConfig.GetSceneObjectConfig();
  168. // if (sceneObjectConfig == null)
  169. // {
  170. // continue;
  171. // }
  172. //
  173. // float md = Random.Range(0.05f, 1f);
  174. // Vector3 p = besselPath.GetValue(md);
  175. // Vector3 p2 = besselPath.GetValue(md - 0.01f);
  176. // Vector3 dir = (p - p2);
  177. // Vector3 cross = Vector3.Cross(dir, Vector3.up);
  178. // cross = cross.normalized;
  179. // // int odds = Random.Range(0, 100);
  180. // p += cross * Random.Range(-20, 20);
  181. // SceneDecoration gameObjectPool = await GetSceneDecoration(sceneObjectConfig);
  182. // GameObject g = gameObjectPool.pool.own;
  183. // besselPath.allPool.Add(gameObjectPool);
  184. // float y = Random.Range(sceneObjectConfig.minY, sceneObjectConfig.maxY);
  185. // g.transform.position = new Vector3(p.x, y, p.z);
  186. // g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360));
  187. // }
  188. // }
  189. private async CTask<SceneDecoration> GetSceneDecoration(SceneObjectConfig sceneObjectConfig)
  190. {
  191. GameObjectPool gameObjectPool = await sceneObjectConfig.GetNewPrefab();
  192. SceneDecoration sceneDecoration = CObjectPool.Instance.Fetch<SceneDecoration>();
  193. sceneDecoration.Init(gameObjectPool);
  194. GameObject g = gameObjectPool.own;
  195. g.SetActive(true);
  196. return sceneDecoration;
  197. }
  198. public Vector3 GetTarget(float time)
  199. {
  200. if (time > 1)
  201. {
  202. if (NextBesselPath == null)
  203. {
  204. NextBesselPath = InitBesselPath(currBesselPath.b, 0);
  205. }
  206. time = time % 1;
  207. return NextBesselPath.GetValue(time);
  208. }
  209. else
  210. {
  211. return currBesselPath.GetValue(time);
  212. }
  213. }
  214. public Vector3 GetNextPoint(float time)
  215. {
  216. if (NextBesselPath == null)
  217. {
  218. NextBesselPath = InitBesselPath(currBesselPath.b, 0);
  219. }
  220. return NextBesselPath.GetValue(time);
  221. }
  222. public Vector3 Move(float dis)
  223. {
  224. float t = dis / currBesselPath.len;
  225. currTime += t;
  226. // Debug.Log("移动速度" + t + "/" + currBesselPath.len);
  227. Vector3 targetPos = Vector3.zero;
  228. if (currTime > 0.01f)
  229. {
  230. if (NextBesselPath == null)
  231. {
  232. // int odds = Random.Range(0, 100);
  233. // if (odds < 50)
  234. // {
  235. // NextBesselPath = InitBesselPath(currBesselPath.b, Random.Range(0, 100) < 50 ? -1 : 1);
  236. // }
  237. // else
  238. {
  239. NextBesselPath = InitBesselPath(currBesselPath.b);
  240. }
  241. }
  242. }
  243. if (currTime > 1)
  244. {
  245. if (NextBesselPath == null)
  246. {
  247. NextBesselPath = InitBesselPath(currBesselPath.b);
  248. }
  249. currTime = currTime % 1;
  250. // targetPos = NextBesselPath.GetValue(currTime);
  251. currBesselPath.reclaimTime = 3;
  252. reclaimSence.Add(currBesselPath);
  253. currBesselPath = NextBesselPath;
  254. NextBesselPath = null;
  255. CombatEventManager.Instance.Dispatch(CombatEventType.SencenBesselPathAlter, null);
  256. }
  257. else
  258. {
  259. }
  260. targetPos = currBesselPath.GetValue(currTime);
  261. moveRoot.transform.position = targetPos;
  262. return targetPos;
  263. }
  264. public void StartPayShengShi(Transform root)
  265. {
  266. shengShiRan = 1;
  267. SceneMonoConfig.shengShiMaterial.SetFloat(Ran,shengShiRan);
  268. Vector3 pos= CombatController.currActiveCombat.playerHeroEntity.dotPos - CombatController.currActiveCombat
  269. .CombatCameraControllder.Camera.transform.position;
  270. pos.z = -30;
  271. SceneMonoConfig.shengShiMaterial.SetVector(Pos,pos);
  272. _isUpdateShengShi = true;
  273. // _shengShiAddTime = 0;
  274. }
  275. public void Update(float t)
  276. {
  277. SceneMonoConfig?.UpdateScene();
  278. if (currBesselPath != null)
  279. {
  280. currBesselPath.Update(t);
  281. }
  282. if (NextBesselPath != null)
  283. {
  284. NextBesselPath.Update(t);
  285. }
  286. if (_isUpdateShengShi)
  287. {
  288. // _shengShiAddTime += t * 1f;
  289. shengShiRan += t * 150;
  290. SceneMonoConfig.shengShiMaterial.SetFloat(Ran,shengShiRan);
  291. // float v = Mathf.Lerp(shengShiStartSize, shengShiEndSize, _shengShiAddTime);
  292. // ShengShiQiuTi.own.transform.localScale = Vector3.one * v;
  293. if (shengShiRan >= 200)
  294. {
  295. SceneMonoConfig.shengShiMaterial.SetFloat(Ran,0.1f);
  296. _isUpdateShengShi = false;
  297. }
  298. }
  299. for (int i = 0; i < reclaimSence.Count; i++)
  300. {
  301. CombatSencePath sencePath = reclaimSence[i];
  302. sencePath.reclaimTime -= t;
  303. if (sencePath.reclaimTime < 0)
  304. {
  305. sencePath.DormancyObj();
  306. reclaimSence.RemoveAt(i);
  307. }
  308. }
  309. }
  310. public void Dispose()
  311. {
  312. // GObjectPool.Instance.
  313. }
  314. }
  315. }