using System; using System.Collections.Generic; using Common.Utility.CombatEvent; using Core.Utility; using Fort23.Core; using Fort23.UTool; using GameLogic.Combat.CombatTool.SceneTool; using GameLogic.CombatScenesTool; using UnityEngine; using Random = UnityEngine.Random; namespace GameLogic.Combat.CombatTool { public class CombatSenceController : IDisposable { 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(); protected GameObjectPool ShengShiQiuTi; private float shengShiStartSize = 3; private float shengShiEndSize = 300; private float _shengShiAddTime; private bool _isUpdateShengShi; private SceneMonoConfig SceneMonoConfig; public async CTask InitScenes() { GameObject gameObject = new GameObject("mvoeRoot"); moveRoot = gameObject.transform; CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer(); var task_a = AssetBundleLoadManager.Instance.LoadAssetAsyncTask("LevelBattle01.prefab", delegate(AssetHandle assetHandle) { GameObject gameObject = assetHandle.AssetObject(); SceneMonoConfig = gameObject.GetComponent(); }); cTaskAwaitBuffer.AddTask(task_a); ShengShiQiuTi = await GObjectPool.Instance.FetchAsync("ShengShiQiuTi", null, null, false, "ShengShiQiuTi"); ShengShiQiuTi.SetActive(false); lasetDir = Vector3.forward; lasetPos = new Vector3(0, 20, 0); await cTaskAwaitBuffer.WaitAll(); currBesselPath = InitBesselPath(lasetPos); SceneMonoConfig.Init(Camera.main.transform.parent); } 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) { InitRoadside(besselPath); InitRoadside_1(besselPath); InitButton(besselPath); } private async CTask InitRoadside(CombatSencePath besselPath) { SceneConfig sceneConfig = SceneMonoConfig.roadside; int count = Random.Range(sceneConfig.minCount, sceneConfig.maxCount); for (int i = 0; i < count; i++) { SceneObjectConfig sceneObjectConfig = sceneConfig.GetSceneObjectConfig(); if (sceneObjectConfig == null) { continue; } float md = Random.Range(0.05f, 1f); 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(12, 25) * (odds < 50 ? 1 : -1); SceneDecoration gameObjectPool = await GetSceneDecoration(sceneObjectConfig); GameObject g = gameObjectPool.pool.own; besselPath.allPool.Add(gameObjectPool); float y = Random.Range(sceneObjectConfig.minY, sceneObjectConfig.maxY); g.transform.position = new Vector3(p.x, y, p.z); g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360)); } } private async CTask InitRoadside_1(CombatSencePath besselPath) { SceneConfig sceneConfig = SceneMonoConfig.roadside_1; int count = Random.Range(sceneConfig.minCount, sceneConfig.maxCount); for (int i = 0; i < count; i++) { SceneObjectConfig sceneObjectConfig = sceneConfig.GetSceneObjectConfig(); if (sceneObjectConfig == null) { continue; } float md = Random.Range(0.05f, 1f); 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(40, 60) * (odds < 50 ? 1 : -1); SceneDecoration gameObjectPool = await GetSceneDecoration(sceneObjectConfig); GameObject g = gameObjectPool.pool.own; besselPath.allPool.Add(gameObjectPool); float y = Random.Range(sceneObjectConfig.minY, sceneObjectConfig.maxY); g.transform.position = new Vector3(p.x, y, p.z); g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360)); } } private async CTask InitButton(CombatSencePath besselPath) { SceneConfig sceneConfig = SceneMonoConfig.button; int count = Random.Range(sceneConfig.minCount, sceneConfig.maxCount); for (int i = 0; i < count; i++) { SceneObjectConfig sceneObjectConfig = sceneConfig.GetSceneObjectConfig(); if (sceneObjectConfig == null) { continue; } float md = Random.Range(0.05f, 1f); 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(-20, 20); SceneDecoration gameObjectPool = await GetSceneDecoration(sceneObjectConfig); GameObject g = gameObjectPool.pool.own; besselPath.allPool.Add(gameObjectPool); float y = Random.Range(sceneObjectConfig.minY, sceneObjectConfig.maxY); g.transform.position = new Vector3(p.x, y, p.z); g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360)); } } private async CTask GetSceneDecoration(SceneObjectConfig sceneObjectConfig) { GameObjectPool gameObjectPool = await sceneObjectConfig.GetNewPrefab(); SceneDecoration sceneDecoration = CObjectPool.Instance.Fetch(); sceneDecoration.Init(gameObjectPool); GameObject g = gameObjectPool.own; g.SetActive(true); return sceneDecoration; } 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 GetNextPoint(float time) { if (NextBesselPath == null) { NextBesselPath = InitBesselPath(currBesselPath.b, 0); } return NextBesselPath.GetValue(time); } public Vector3 Move(float dis) { float t = dis / currBesselPath.len; currTime += t; // Debug.Log("移动速度" + t + "/" + currBesselPath.len); Vector3 targetPos = Vector3.zero; if (currTime > 0.01f) { 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; CombatEventManager.Instance.Dispatch(CombatEventType.SencenBesselPathAlter, null); } else { } targetPos = currBesselPath.GetValue(currTime); moveRoot.transform.position = targetPos; return targetPos; } public void StartPayShengShi(Transform root) { ShengShiQiuTi.own.transform.SetParent(root); ShengShiQiuTi.own.transform.localPosition = Vector3.zero; ShengShiQiuTi.SetActive(true); _isUpdateShengShi = true; ShengShiQiuTi.own.transform.localScale = Vector3.one * shengShiStartSize; _shengShiAddTime = 0; } public void Update(float t) { SceneMonoConfig?.Update(); if (currBesselPath != null) { currBesselPath.Update(t); } if (NextBesselPath != null) { NextBesselPath.Update(t); } if (_isUpdateShengShi) { _shengShiAddTime += t * 1f; float v = Mathf.Lerp(shengShiStartSize, shengShiEndSize, _shengShiAddTime); ShengShiQiuTi.own.transform.localScale = Vector3.one * v; if (_shengShiAddTime >= 1) { ShengShiQiuTi.SetActive(false); _isUpdateShengShi = false; } } 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. } } }