SceneMonoConfig.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections.Generic;
  2. using Fort23.UTool;
  3. using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
  4. using UnityEngine;
  5. using Utility;
  6. namespace GameLogic.Combat.CombatTool.SceneTool
  7. {
  8. public class SceneMonoConfig : SceneMonoConfigBasic
  9. {
  10. public Color fogColor;
  11. public float fogStartDistance;
  12. public float fogEndDistance;
  13. public GameObject[] allObject;
  14. public float radius;
  15. public string dec;
  16. // private Transform root;
  17. private SceneMonoConfig sceneMonoConfig;
  18. private Map<int, GameObjectPool> _allGameObjectPools = new Map<int, GameObjectPool>();
  19. protected override void ProInit()
  20. {
  21. RenderSettings.fogColor= fogColor;
  22. RenderSettings.fogStartDistance = fogStartDistance;
  23. RenderSettings.fogEndDistance = fogEndDistance;
  24. this.sceneMonoConfig = this;
  25. }
  26. protected override void ProUpdate()
  27. {
  28. Vector3 pos = moveRoot.position;
  29. List<int> removeKey = new List<int>();
  30. for (_allGameObjectPools.Begin(); _allGameObjectPools.Next();)
  31. {
  32. Vector3 objetcPos = _allGameObjectPools.Value.own.transform.position;
  33. if (Vector3.Distance(pos, objetcPos) > 300)
  34. {
  35. removeKey.Add(_allGameObjectPools.Key);
  36. GObjectPool.Instance.Recycle(_allGameObjectPools.Value);
  37. // _allGameObjectPools.Value.SetActive(false);
  38. }
  39. }
  40. for (int i = 0; i < removeKey.Count; i++)
  41. {
  42. _allGameObjectPools.Remove(removeKey[i]);
  43. }
  44. float radius = sceneMonoConfig.radius;
  45. int x = (int)(pos.x / radius);
  46. int z = (int)(pos.z / radius);
  47. float xStartInit = x;
  48. float zStartInit = z;
  49. for (int i = -3; i <= 3; i++)
  50. {
  51. for (int j = -3; j <= 4; j++)
  52. {
  53. // if (i == 0 && j == 0)
  54. // {
  55. // continue;
  56. // }
  57. float currX = (xStartInit + i) * radius;
  58. float currZ = (zStartInit + j) * radius;
  59. int key = (int)(currX * 1000 + currZ);
  60. if (_allGameObjectPools.ContainsKey(key))
  61. {
  62. continue;
  63. }
  64. GameObjectPool gameObjectPool = GetObejct();
  65. float y = Random.Range(-2, 0);
  66. gameObjectPool.own.transform.position = new Vector3(currX, y, currZ);
  67. _allGameObjectPools.Add(key, gameObjectPool);
  68. }
  69. }
  70. }
  71. private GameObjectPool GetObejct()
  72. {
  73. int index = Random.Range(0, sceneMonoConfig.allObject.Length);
  74. GameObject gameObject = sceneMonoConfig.allObject[index];
  75. // GameObject go = GameObject.Instantiate(gameObject);
  76. GameObjectPool gameObjectPool =
  77. GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(gameObject, gameObject.name);
  78. return gameObjectPool;
  79. }
  80. }
  81. }