1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System.Collections.Generic;
- using Fort23.UTool;
- using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
- using UnityEngine;
- using Utility;
- namespace GameLogic.Combat.CombatTool.SceneTool
- {
- public class SceneMonoConfig : SceneMonoConfigBasic
- {
- public Color fogColor;
- public float fogStartDistance;
- public float fogEndDistance;
- public GameObject[] allObject;
- public float radius;
- public string dec;
- // private Transform root;
- private SceneMonoConfig sceneMonoConfig;
- private Map<int, GameObjectPool> _allGameObjectPools = new Map<int, GameObjectPool>();
- protected override void ProInit()
- {
- RenderSettings.fogColor= fogColor;
- RenderSettings.fogStartDistance = fogStartDistance;
- RenderSettings.fogEndDistance = fogEndDistance;
- this.sceneMonoConfig = this;
- }
- protected override void ProUpdate()
- {
- Vector3 pos = moveRoot.position;
- List<int> removeKey = new List<int>();
- for (_allGameObjectPools.Begin(); _allGameObjectPools.Next();)
- {
- 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]);
- }
- float radius = sceneMonoConfig.radius;
- int x = (int)(pos.x / radius);
- int z = (int)(pos.z / radius);
- float xStartInit = x;
- float zStartInit = z;
- for (int i = -15; i <= 15; i++)
- {
- for (int j = -15; j <= 15; j++)
- {
- // if (i == 0 && j == 0)
- // {
- // continue;
- // }
- float currX = (xStartInit + i) * radius;
- float currZ = (zStartInit + j) * radius;
- int key = (int)(currX * 1000 + currZ);
- if (_allGameObjectPools.ContainsKey(key))
- {
- continue;
- }
- GameObjectPool gameObjectPool = GetObejct();
- float y = Random.Range(-2, 0);
- float xoff = Random.Range(-3.0f, 3.0f);
- float zoff = Random.Range(-2.0f, 2.0f);
- gameObjectPool.own.transform.position = new Vector3(currX+xoff, y, currZ+zoff);
- float ry = Random.Range(0, 360);
- Vector3 eulerAngles = gameObjectPool.own.transform.eulerAngles;
- gameObjectPool.own.transform.eulerAngles = new Vector3(eulerAngles.x, ry, eulerAngles.z);
- _allGameObjectPools.Add(key, gameObjectPool);
- }
- }
- }
- private GameObjectPool GetObejct()
- {
- int index = Random.Range(0, sceneMonoConfig.allObject.Length);
- GameObject gameObject = sceneMonoConfig.allObject[index];
- // GameObject go = GameObject.Instantiate(gameObject);
- GameObjectPool gameObjectPool =
- GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(gameObject, gameObject.name);
- return gameObjectPool;
- }
- }
- }
|