using System; using System.Collections.Generic; using Core.Utility; using Fort23.Core; 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; public async CTask InitScenes() { GameObject gameObject = new GameObject("mvoeRoot"); moveRoot = gameObject.transform; CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer(); cTaskAwaitBuffer.AddTask(AssetBundleLoadManager.Instance.LoadAssetAsyncTask( "shan1.prefab", delegate(AssetHandle handle) { scenesHandle = handle; scenes1 = scenesHandle.AssetObject(); scenes1.SetActive(false); })); lasetDir = Vector3.forward; 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 void 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); GameObject g = GameObject.Instantiate(scenes1); g.SetActive(true); g.transform.position = p + new Vector3(0, Random.Range(-7, -4), 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, -1); } else { NextBesselPath = InitBesselPath(currBesselPath.b); } } } if (currTime > 1) { if (NextBesselPath == null) { NextBesselPath = InitBesselPath(currBesselPath.b, -1); } currTime = currTime % 1; targetPos = NextBesselPath.GetValue(currTime); currBesselPath = NextBesselPath; NextBesselPath = null; } else { targetPos = currBesselPath.GetValue(currTime); } moveRoot.transform.position = targetPos; return targetPos; } public void Update(float t) { } public void Dispose() { if (scenesHandle != null) { scenesHandle.Release(); } } } }