CombatSenceController.cs 5.9 KB

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