CombatSenceController.cs 13 KB

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