SceneMonoConfig.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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) > 1600)
  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 = -15; i <= 15; i++)
  50. {
  51. for (int j = -15; j <= 15; 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. float xoff = Random.Range(-3.0f, 3.0f);
  67. float zoff = Random.Range(-2.0f, 2.0f);
  68. gameObjectPool.own.transform.position = new Vector3(currX+xoff, y, currZ+zoff);
  69. float ry = Random.Range(0, 360);
  70. Vector3 eulerAngles = gameObjectPool.own.transform.eulerAngles;
  71. gameObjectPool.own.transform.eulerAngles = new Vector3(eulerAngles.x, ry, eulerAngles.z);
  72. _allGameObjectPools.Add(key, gameObjectPool);
  73. }
  74. }
  75. }
  76. private GameObjectPool GetObejct()
  77. {
  78. int index = Random.Range(0, sceneMonoConfig.allObject.Length);
  79. GameObject gameObject = sceneMonoConfig.allObject[index];
  80. // GameObject go = GameObject.Instantiate(gameObject);
  81. GameObjectPool gameObjectPool =
  82. GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(gameObject, gameObject.name);
  83. return gameObjectPool;
  84. }
  85. }
  86. }