| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 | using System.Collections.Generic;using Fort23.UTool;using UnityEngine;using Utility;namespace GameLogic.Combat.CombatTool.SceneTool{    public class SceneCJ2MonoConfig : SceneMonoConfigBasic    {        public Color fogColor;        public float fogStartDistance;        public float fogEndDistance;        public GameObject[] allObject;        public float radius;        private Map<int, GameObjectPool> _allGameObjectPools = new Map<int, GameObjectPool>();        private Map<int, GameObjectPool> _downAllGameObjectPools = new Map<int, GameObjectPool>();        protected override void ProInit()        {            RenderSettings.fogColor = fogColor;            RenderSettings.fogStartDistance = fogStartDistance;            RenderSettings.fogEndDistance = fogEndDistance;        }        protected override void ProUpdate()        {            Vector3 pos = moveRoot.position;            List<int> removeKey = new List<int>();            for (_allGameObjectPools.Begin(); _allGameObjectPools.Next();)            {                if (_allGameObjectPools.Value == null)                {                    continue;                }                Vector3 objetcPos = _allGameObjectPools.Value.own.transform.position;                if (Vector3.Distance(pos, objetcPos) > 1600)                {                    removeKey.Add(_allGameObjectPools.Key);                    GObjectPool.Instance.Recycle(_allGameObjectPools.Value);                    // _allGameObjectPools.Value.SetActive(false);                }            }            for (int i = 0; i < removeKey.Count; i++)            {                _allGameObjectPools.Remove(removeKey[i]);            }            removeKey.Clear();            for (_downAllGameObjectPools.Begin(); _downAllGameObjectPools.Next();)            {                if (_downAllGameObjectPools.Value == null)                {                    continue;                }                Vector3 objetcPos = _downAllGameObjectPools.Value.own.transform.position;                if (Vector3.Distance(pos, objetcPos) > 1600)                {                    removeKey.Add(_downAllGameObjectPools.Key);                    GObjectPool.Instance.Recycle(_downAllGameObjectPools.Value);                    // _allGameObjectPools.Value.SetActive(false);                }            }            for (int i = 0; i < removeKey.Count; i++)            {                _downAllGameObjectPools.Remove(removeKey[i]);            }            // float radius = radius;            int x = (int)(pos.x / radius);            int z = (int)(pos.z / radius);            float xStartInit = x;            float zStartInit = z;            for (int i = -4; i <= 10; i++)            {                for (int j = -4; j <= 20; j++)                {                    float currX = (xStartInit + i) * radius;                    float currZ = (zStartInit + j) * radius;                    int key = (int)(currX * 1000 + currZ);                    InitUp(key, currX, currZ);                    InitDown(key, currX, currZ, i, j);                }            }        }        private void InitUp(int key, float currX, float currZ)        {            if (_allGameObjectPools.ContainsKey(key))            {                return;            }            GameObjectPool gameObjectPool = GetObejct(80);            if (gameObjectPool != null)            {                float y = Random.Range(45.0f, 65.0f);                float x = Random.Range(-3.0f, 3.0f);                float z = Random.Range(-2.0f, 2.0f);                gameObjectPool.own.transform.position = new Vector3(currX + x, y, currZ + z);                float ry = Random.Range(0, 360);                Vector3 eulerAngles = gameObjectPool.own.transform.eulerAngles;                gameObjectPool.own.transform.eulerAngles = new Vector3(eulerAngles.x, ry, eulerAngles.z);                gameObjectPool.own.transform.localScale = Vector3.one * 1.5f;            }            _allGameObjectPools.Add(key, gameObjectPool);        }        private void InitDown(int key, float currX, float currZ, int xintdex, int yindex)        {            if (_downAllGameObjectPools.ContainsKey(key))            {                return;            }            int odds = 50;            GameObjectPool gameObjectPool = GetObejct(odds);            if (gameObjectPool != null)            {                float y = Random.Range(-10.0f, -1f);                int d = Mathf.Abs(Mathf.Abs(xintdex) - 1);                if (d <= 1)                {                    y = Random.Range(-10.0f - d * 10, -6.0f - d * 10);                }                float x = Random.Range(-3.0f, 3.0f);                float z = Random.Range(-3.0f, 3.0f);                gameObjectPool.own.transform.position = new Vector3(currX + x, y, currZ + z);                float ry = Random.Range(0, 360);                Vector3 eulerAngles = gameObjectPool.own.transform.eulerAngles;                gameObjectPool.own.transform.eulerAngles = new Vector3(eulerAngles.x, ry, eulerAngles.z);                gameObjectPool.own.transform.localScale = Vector3.one;            }            _downAllGameObjectPools.Add(key, gameObjectPool);        }        private GameObjectPool GetObejct(int currOdds)        {            int odds = Random.Range(0, 100);            if (odds < currOdds)            {                return null;            }            int index = Random.Range(0, allObject.Length);            GameObject gameObject = allObject[index];            // GameObject go = GameObject.Instantiate(gameObject);            GameObjectPool gameObjectPool =                GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(gameObject, gameObject.name);            return gameObjectPool;        }        protected override void ProDispose()        {            for (_downAllGameObjectPools.Begin(); _downAllGameObjectPools.Next();)            {                GObjectPool.Instance.Recycle(_downAllGameObjectPools.Value);            }               _downAllGameObjectPools.Clear();            for (_allGameObjectPools.Begin(); _allGameObjectPools.Next();)            {                GObjectPool.Instance.Recycle(_allGameObjectPools.Value);            }        }    }}
 |