12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System.Collections.Generic;
- using Fort23.UTool;
- using UnityEngine;
- using Utility;
- namespace GameLogic.Combat.CombatTool.SceneTool
- {
- public class RandomAllMap
- {
- private Transform root;
- private SceneMonoConfig sceneMonoConfig;
- private Map<int, GameObject> _allGameObjectPools = new Map<int, GameObject>();
- public void Init(Transform root, SceneMonoConfig sceneMonoConfig)
- {
- this.root = root;
- this.sceneMonoConfig = sceneMonoConfig;
- }
- public void Update()
- {
- Vector3 pos = root.position;
- List<int> removeKey = new List<int>();
- for (_allGameObjectPools.Begin(); _allGameObjectPools.Next();)
- {
- Vector3 objetcPos = _allGameObjectPools.Value.transform.position;
- if (Vector3.Distance(pos, objetcPos) > 300)
- {
- removeKey.Add(_allGameObjectPools.Key);
- _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 = -3; i <= 3; i++)
- {
- for (int j = -3; j <= 3; 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;
- }
- GameObject gameObjectPool = GetObejct();
- float y = Random.Range(-2, 0);
- gameObjectPool.transform.position = new Vector3(currX, y, currZ);
- _allGameObjectPools.Add(key, gameObjectPool);
- }
- }
- }
- private GameObject 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 go;
- }
- }
- }
|