CombatSenceController.cs 14 KB

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