using System; using System.Collections.Generic; using Core.Utility; using Fort23.Core; using Fort23.UTool; using GameLogic.CombatScenesTool; using UnityEngine; using Random = UnityEngine.Random; namespace GameLogic.Combat.CombatTool { public class CombatSenceController : IDisposable { // private AssetHandle scenesHandle; // public GameObject scenes1; public CombatSencePath currBesselPath; public CombatSencePath NextBesselPath; private float moveTime; private Vector3 lasetPos; private float maxD = 100; private Vector3 lasetDir; public float currTime; public Transform moveRoot; private List reclaimSence=new List(); public async CTask InitScenes() { GameObject gameObject = new GameObject("mvoeRoot"); moveRoot = gameObject.transform; CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer(); await GObjectPool.Instance.FetchAsync("shan1", null, null, true, "shan1"); lasetDir = Vector3.forward; lasetPos = new Vector3(0, 5, 0); await cTaskAwaitBuffer.WaitAll(); currBesselPath = InitBesselPath(lasetPos); } private CombatSencePath InitBesselPath(Vector3 satrtPos) { CombatSencePath besselPath = new CombatSencePath(); Vector3 target = satrtPos + lasetDir.normalized * maxD; // if (offx == 0) { besselPath.SetPos(satrtPos, target); } Vector3 p = besselPath.GetValue(0.99f); lasetDir = (target - p).normalized; GameObject gameObject = new GameObject("path"); gameObject.transform.position = satrtPos; CombatPathMono combatPathMono = gameObject.AddComponent(); combatPathMono.BesselPath = besselPath; InitZhuangSHi(besselPath); return besselPath; } private CombatSencePath InitBesselPath(Vector3 satrtPos, float offx) { CombatSencePath besselPath = new CombatSencePath(); Vector3 dir = Quaternion.LookRotation(lasetDir) * new Vector3(offx, 0, 1); Vector3 target = satrtPos + dir.normalized * maxD; Vector3 dir2 = Quaternion.LookRotation(lasetDir) * new Vector3(offx * -1, 0, 1); Vector3 centre = satrtPos + dir2.normalized * maxD; // if (offx == 0) { besselPath.SetPos(satrtPos, centre, target); } Vector3 p = besselPath.GetValue(0.99f); lasetDir = (target - p).normalized; GameObject gameObject = new GameObject("path"); gameObject.transform.position = satrtPos; CombatPathMono combatPathMono = gameObject.AddComponent(); combatPathMono.BesselPath = besselPath; InitZhuangSHi(besselPath); return besselPath; } private async CTask InitZhuangSHi(CombatSencePath besselPath) { int count = Random.Range(30, 40); for (int i = 0; i < count; i++) { float md = Random.Range(0.1f, 0.9f); Vector3 p = besselPath.GetValue(md); Vector3 p2 = besselPath.GetValue(md - 0.01f); Vector3 dir = (p - p2); Vector3 cross = Vector3.Cross(dir, Vector3.up); cross = cross.normalized; int odds = Random.Range(0, 100); p += cross * Random.Range(8, 25) * (odds < 50 ? 1 : -1); GameObjectPool gameObjectPool = await GObjectPool.Instance.FetchAsync("shan1", null, poolName: "shan1"); GameObject g = gameObjectPool.own; g.SetActive(true); besselPath.allPool.Add(gameObjectPool); g.transform.position = new Vector3(p.x,0, p.z) + new Vector3(0, Random.Range(-4, -1), 0); g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360)); } } public Vector3 GetTarget(float time) { if (time > 1) { if (NextBesselPath == null) { NextBesselPath = InitBesselPath(currBesselPath.b, 0); } time = time % 1; return NextBesselPath.GetValue(time); } else { return currBesselPath.GetValue(time); } } public Vector3 Move(float speedTime) { currTime += speedTime; Vector3 targetPos = Vector3.zero; if (currTime > 0.2f) { if (NextBesselPath == null) { int odds = Random.Range(0, 100); if (odds < 50) { NextBesselPath = InitBesselPath(currBesselPath.b, Random.Range(0, 100)<50?-1:1); } else { NextBesselPath = InitBesselPath(currBesselPath.b); } } } if (currTime > 1) { if (NextBesselPath == null) { NextBesselPath = InitBesselPath(currBesselPath.b, Random.Range(0, 100)<50?-1:1); } currTime = currTime % 1; targetPos = NextBesselPath.GetValue(currTime); currBesselPath.reclaimTime = 3; reclaimSence.Add(currBesselPath); currBesselPath = NextBesselPath; NextBesselPath = null; } else { targetPos = currBesselPath.GetValue(currTime); } moveRoot.transform.position = targetPos; return targetPos; } public void Update(float t) { for (int i = 0; i < reclaimSence.Count; i++) { CombatSencePath sencePath= reclaimSence[i]; sencePath.reclaimTime -= t; if (sencePath.reclaimTime < 0) { sencePath.DormancyObj(); reclaimSence.RemoveAt(i); } } } public void Dispose() { // GObjectPool.Instance. } } }