CombatSenceController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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);
  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. float md = Random.Range(0.05f, 1f);
  117. Vector3 p = besselPath.GetValue(md);
  118. Vector3 p2 = besselPath.GetValue(md - 0.01f);
  119. Vector3 dir = (p - p2);
  120. Vector3 cross = Vector3.Cross(dir, Vector3.up);
  121. cross = cross.normalized;
  122. int odds = Random.Range(0, 100);
  123. p += cross * Random.Range(12, 25) * (odds < 50 ? 1 : -1);
  124. SceneDecoration gameObjectPool = await GetSceneDecoration(sceneObjectConfig);
  125. GameObject g = gameObjectPool.pool.own;
  126. besselPath.allPool.Add(gameObjectPool);
  127. float y = Random.Range(sceneObjectConfig.minY, sceneObjectConfig.maxY);
  128. g.transform.position = new Vector3(p.x, y, p.z);
  129. g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360));
  130. }
  131. }
  132. private async CTask InitRoadside_1(CombatSencePath besselPath)
  133. {
  134. SceneConfig sceneConfig = SceneMonoConfig.roadside_1;
  135. int count = Random.Range(sceneConfig.minCount, sceneConfig.maxCount);
  136. for (int i = 0; i < count; i++)
  137. {
  138. SceneObjectConfig sceneObjectConfig = sceneConfig.GetSceneObjectConfig();
  139. if (sceneObjectConfig == null)
  140. {
  141. continue;
  142. }
  143. float md = Random.Range(0.05f, 1f);
  144. Vector3 p = besselPath.GetValue(md);
  145. Vector3 p2 = besselPath.GetValue(md - 0.01f);
  146. Vector3 dir = (p - p2);
  147. Vector3 cross = Vector3.Cross(dir, Vector3.up);
  148. cross = cross.normalized;
  149. int odds = Random.Range(0, 100);
  150. p += cross * Random.Range(40, 60) * (odds < 50 ? 1 : -1);
  151. SceneDecoration gameObjectPool = await GetSceneDecoration(sceneObjectConfig);
  152. GameObject g = gameObjectPool.pool.own;
  153. besselPath.allPool.Add(gameObjectPool);
  154. float y = Random.Range(sceneObjectConfig.minY, sceneObjectConfig.maxY);
  155. g.transform.position = new Vector3(p.x, y, p.z);
  156. g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360));
  157. }
  158. }
  159. private async CTask InitButton(CombatSencePath besselPath)
  160. {
  161. SceneConfig sceneConfig = SceneMonoConfig.button;
  162. int count = Random.Range(sceneConfig.minCount, sceneConfig.maxCount);
  163. for (int i = 0; i < count; i++)
  164. {
  165. SceneObjectConfig sceneObjectConfig = sceneConfig.GetSceneObjectConfig();
  166. if (sceneObjectConfig == null)
  167. {
  168. continue;
  169. }
  170. float md = Random.Range(0.05f, 1f);
  171. Vector3 p = besselPath.GetValue(md);
  172. Vector3 p2 = besselPath.GetValue(md - 0.01f);
  173. Vector3 dir = (p - p2);
  174. Vector3 cross = Vector3.Cross(dir, Vector3.up);
  175. cross = cross.normalized;
  176. // int odds = Random.Range(0, 100);
  177. p += cross * Random.Range(-20, 20);
  178. SceneDecoration gameObjectPool = await GetSceneDecoration(sceneObjectConfig);
  179. GameObject g = gameObjectPool.pool.own;
  180. besselPath.allPool.Add(gameObjectPool);
  181. float y = Random.Range(sceneObjectConfig.minY, sceneObjectConfig.maxY);
  182. g.transform.position = new Vector3(p.x, y, p.z);
  183. g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360));
  184. }
  185. }
  186. private async CTask<SceneDecoration> GetSceneDecoration(SceneObjectConfig sceneObjectConfig)
  187. {
  188. GameObjectPool gameObjectPool = await sceneObjectConfig.GetNewPrefab();
  189. SceneDecoration sceneDecoration = CObjectPool.Instance.Fetch<SceneDecoration>();
  190. sceneDecoration.Init(gameObjectPool);
  191. GameObject g = gameObjectPool.own;
  192. g.SetActive(true);
  193. return sceneDecoration;
  194. }
  195. public Vector3 GetTarget(float time)
  196. {
  197. if (time > 1)
  198. {
  199. if (NextBesselPath == null)
  200. {
  201. NextBesselPath = InitBesselPath(currBesselPath.b, 0);
  202. }
  203. time = time % 1;
  204. return NextBesselPath.GetValue(time);
  205. }
  206. else
  207. {
  208. return currBesselPath.GetValue(time);
  209. }
  210. }
  211. public Vector3 GetNextPoint(float time)
  212. {
  213. if (NextBesselPath == null)
  214. {
  215. NextBesselPath = InitBesselPath(currBesselPath.b, 0);
  216. }
  217. return NextBesselPath.GetValue(time);
  218. }
  219. public Vector3 Move(float dis)
  220. {
  221. float t = dis / currBesselPath.len;
  222. currTime += t;
  223. // Debug.Log("移动速度" + t + "/" + currBesselPath.len);
  224. Vector3 targetPos = Vector3.zero;
  225. if (currTime > 0.01f)
  226. {
  227. if (NextBesselPath == null)
  228. {
  229. // int odds = Random.Range(0, 100);
  230. // if (odds < 50)
  231. // {
  232. // NextBesselPath = InitBesselPath(currBesselPath.b, Random.Range(0, 100) < 50 ? -1 : 1);
  233. // }
  234. // else
  235. {
  236. NextBesselPath = InitBesselPath(currBesselPath.b);
  237. }
  238. }
  239. }
  240. if (currTime > 1)
  241. {
  242. if (NextBesselPath == null)
  243. {
  244. NextBesselPath = InitBesselPath(currBesselPath.b);
  245. }
  246. currTime = currTime % 1;
  247. // targetPos = NextBesselPath.GetValue(currTime);
  248. currBesselPath.reclaimTime = 3;
  249. reclaimSence.Add(currBesselPath);
  250. currBesselPath = NextBesselPath;
  251. NextBesselPath = null;
  252. CombatEventManager.Instance.Dispatch(CombatEventType.SencenBesselPathAlter, null);
  253. }
  254. else
  255. {
  256. }
  257. targetPos = currBesselPath.GetValue(currTime);
  258. moveRoot.transform.position = targetPos;
  259. return targetPos;
  260. }
  261. public void StartPayShengShi(Transform root)
  262. {
  263. shengShiRan = 1;
  264. SceneMonoConfig.shengShiMaterial.SetFloat(Ran,shengShiRan);
  265. Vector3 pos= CombatController.currActiveCombat.playerHeroEntity.dotPos - CombatController.currActiveCombat
  266. .CombatCameraControllder.Camera.transform.position;
  267. pos.z = -30;
  268. SceneMonoConfig.shengShiMaterial.SetVector(Pos,pos);
  269. _isUpdateShengShi = true;
  270. // _shengShiAddTime = 0;
  271. }
  272. public void Update(float t)
  273. {
  274. SceneMonoConfig?.Update();
  275. if (currBesselPath != null)
  276. {
  277. currBesselPath.Update(t);
  278. }
  279. if (NextBesselPath != null)
  280. {
  281. NextBesselPath.Update(t);
  282. }
  283. if (RandomAllMap != null)
  284. {
  285. RandomAllMap.Update();
  286. }
  287. if (_isUpdateShengShi)
  288. {
  289. // _shengShiAddTime += t * 1f;
  290. shengShiRan += t * 150;
  291. SceneMonoConfig.shengShiMaterial.SetFloat(Ran,shengShiRan);
  292. // float v = Mathf.Lerp(shengShiStartSize, shengShiEndSize, _shengShiAddTime);
  293. // ShengShiQiuTi.own.transform.localScale = Vector3.one * v;
  294. if (shengShiRan >= 200)
  295. {
  296. SceneMonoConfig.shengShiMaterial.SetFloat(Ran,0.1f);
  297. _isUpdateShengShi = false;
  298. }
  299. }
  300. for (int i = 0; i < reclaimSence.Count; i++)
  301. {
  302. CombatSencePath sencePath = reclaimSence[i];
  303. sencePath.reclaimTime -= t;
  304. if (sencePath.reclaimTime < 0)
  305. {
  306. sencePath.DormancyObj();
  307. reclaimSence.RemoveAt(i);
  308. }
  309. }
  310. }
  311. public void Dispose()
  312. {
  313. // GObjectPool.Instance.
  314. }
  315. }
  316. }