| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 | 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<CombatSencePath> reclaimSence = new List<CombatSencePath>();        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<GameObject>("LevelBattle01.prefab",                delegate(AssetHandle assetHandle)                {                    GameObject gameObject = assetHandle.AssetObject<GameObject>();                    SceneMonoConfig = gameObject.GetComponent<SceneMonoConfig>();                });            cTaskAwaitBuffer.AddTask(task_a);            ShengShiQiuTi =                await GObjectPool.Instance.FetchAsync<GameObjectPool>("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>();            // 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);            dir2 = dir2.normalized;            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>();            // 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<SceneDecoration> GetSceneDecoration(SceneObjectConfig sceneObjectConfig)        {            GameObjectPool gameObjectPool = await sceneObjectConfig.GetNewPrefab();            SceneDecoration sceneDecoration = CObjectPool.Instance.Fetch<SceneDecoration>();            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);                }                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.        }    }}
 |