CombatSenceController.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System;
  2. using System.Collections.Generic;
  3. using Core.Utility;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using GameLogic.CombatScenesTool;
  7. using UnityEngine;
  8. using Random = UnityEngine.Random;
  9. namespace GameLogic.Combat.CombatTool
  10. {
  11. public class CombatSenceController : IDisposable
  12. {
  13. // private AssetHandle scenesHandle;
  14. // public GameObject scenes1;
  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. public async CTask InitScenes()
  25. {
  26. GameObject gameObject = new GameObject("mvoeRoot");
  27. moveRoot = gameObject.transform;
  28. CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer();
  29. await GObjectPool.Instance.FetchAsync<GameObjectPool>("shan1", null, null, true, "shan1");
  30. lasetDir = Vector3.forward;
  31. lasetPos = new Vector3(0, 5, 0);
  32. await cTaskAwaitBuffer.WaitAll();
  33. currBesselPath = InitBesselPath(lasetPos);
  34. }
  35. private CombatSencePath InitBesselPath(Vector3 satrtPos)
  36. {
  37. CombatSencePath besselPath = new CombatSencePath();
  38. Vector3 target = satrtPos + lasetDir.normalized * maxD;
  39. // if (offx == 0)
  40. {
  41. besselPath.SetPos(satrtPos, target);
  42. }
  43. Vector3 p = besselPath.GetValue(0.99f);
  44. lasetDir = (target - p).normalized;
  45. GameObject gameObject = new GameObject("path");
  46. gameObject.transform.position = satrtPos;
  47. CombatPathMono combatPathMono = gameObject.AddComponent<CombatPathMono>();
  48. combatPathMono.BesselPath = besselPath;
  49. InitZhuangSHi(besselPath);
  50. return besselPath;
  51. }
  52. private CombatSencePath InitBesselPath(Vector3 satrtPos, float offx)
  53. {
  54. CombatSencePath besselPath = new CombatSencePath();
  55. Vector3 dir = Quaternion.LookRotation(lasetDir) * new Vector3(offx, 0, 1);
  56. Vector3 target = satrtPos + dir.normalized * maxD;
  57. Vector3 dir2 = Quaternion.LookRotation(lasetDir) * new Vector3(offx * -1, 0, 1);
  58. Vector3 centre = satrtPos + dir2.normalized * maxD;
  59. // if (offx == 0)
  60. {
  61. besselPath.SetPos(satrtPos, centre, target);
  62. }
  63. Vector3 p = besselPath.GetValue(0.99f);
  64. lasetDir = (target - p).normalized;
  65. GameObject gameObject = new GameObject("path");
  66. gameObject.transform.position = satrtPos;
  67. CombatPathMono combatPathMono = gameObject.AddComponent<CombatPathMono>();
  68. combatPathMono.BesselPath = besselPath;
  69. InitZhuangSHi(besselPath);
  70. return besselPath;
  71. }
  72. private async CTask InitZhuangSHi(CombatSencePath besselPath)
  73. {
  74. int count = Random.Range(30, 40);
  75. for (int i = 0; i < count; i++)
  76. {
  77. float md = Random.Range(0.1f, 0.9f);
  78. Vector3 p = besselPath.GetValue(md);
  79. Vector3 p2 = besselPath.GetValue(md - 0.01f);
  80. Vector3 dir = (p - p2);
  81. Vector3 cross = Vector3.Cross(dir, Vector3.up);
  82. cross = cross.normalized;
  83. int odds = Random.Range(0, 100);
  84. p += cross * Random.Range(8, 25) * (odds < 50 ? 1 : -1);
  85. GameObjectPool gameObjectPool =
  86. await GObjectPool.Instance.FetchAsync<GameObjectPool>("shan1", null, poolName: "shan1");
  87. GameObject g = gameObjectPool.own;
  88. g.SetActive(true);
  89. besselPath.allPool.Add(gameObjectPool);
  90. g.transform.position = new Vector3(p.x,0, p.z) + new Vector3(0, Random.Range(-4, -1), 0);
  91. g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360));
  92. }
  93. }
  94. public Vector3 GetTarget(float time)
  95. {
  96. if (time > 1)
  97. {
  98. if (NextBesselPath == null)
  99. {
  100. NextBesselPath = InitBesselPath(currBesselPath.b, 0);
  101. }
  102. time = time % 1;
  103. return NextBesselPath.GetValue(time);
  104. }
  105. else
  106. {
  107. return currBesselPath.GetValue(time);
  108. }
  109. }
  110. public Vector3 Move(float speedTime)
  111. {
  112. currTime += speedTime;
  113. Vector3 targetPos = Vector3.zero;
  114. if (currTime > 0.2f)
  115. {
  116. if (NextBesselPath == null)
  117. {
  118. int odds = Random.Range(0, 100);
  119. if (odds < 50)
  120. {
  121. NextBesselPath = InitBesselPath(currBesselPath.b, Random.Range(0, 100)<50?-1:1);
  122. }
  123. else
  124. {
  125. NextBesselPath = InitBesselPath(currBesselPath.b);
  126. }
  127. }
  128. }
  129. if (currTime > 1)
  130. {
  131. if (NextBesselPath == null)
  132. {
  133. NextBesselPath = InitBesselPath(currBesselPath.b, Random.Range(0, 100)<50?-1:1);
  134. }
  135. currTime = currTime % 1;
  136. targetPos = NextBesselPath.GetValue(currTime);
  137. currBesselPath.reclaimTime = 3;
  138. reclaimSence.Add(currBesselPath);
  139. currBesselPath = NextBesselPath;
  140. NextBesselPath = null;
  141. }
  142. else
  143. {
  144. targetPos = currBesselPath.GetValue(currTime);
  145. }
  146. moveRoot.transform.position = targetPos;
  147. return targetPos;
  148. }
  149. public void Update(float t)
  150. {
  151. for (int i = 0; i < reclaimSence.Count; i++)
  152. {
  153. CombatSencePath sencePath= reclaimSence[i];
  154. sencePath.reclaimTime -= t;
  155. if (sencePath.reclaimTime < 0)
  156. {
  157. sencePath.DormancyObj();
  158. reclaimSence.RemoveAt(i);
  159. }
  160. }
  161. }
  162. public void Dispose()
  163. {
  164. // GObjectPool.Instance.
  165. }
  166. }
  167. }