SceneCJ2MonoConfig.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System.Collections.Generic;
  2. using Fort23.UTool;
  3. using UnityEngine;
  4. using Utility;
  5. namespace GameLogic.Combat.CombatTool.SceneTool
  6. {
  7. public class SceneCJ2MonoConfig : SceneMonoConfigBasic
  8. {
  9. public Color fogColor;
  10. public float fogStartDistance;
  11. public float fogEndDistance;
  12. public GameObject[] allObject;
  13. public float radius;
  14. private Map<int, GameObjectPool> _allGameObjectPools = new Map<int, GameObjectPool>();
  15. private Map<int, GameObjectPool> _downAllGameObjectPools = new Map<int, GameObjectPool>();
  16. protected override void ProInit()
  17. {
  18. RenderSettings.fogColor = fogColor;
  19. RenderSettings.fogStartDistance = fogStartDistance;
  20. RenderSettings.fogEndDistance = fogEndDistance;
  21. }
  22. protected override void ProUpdate()
  23. {
  24. Vector3 pos = moveRoot.position;
  25. List<int> removeKey = new List<int>();
  26. for (_allGameObjectPools.Begin(); _allGameObjectPools.Next();)
  27. {
  28. if (_allGameObjectPools.Value == null)
  29. {
  30. continue;
  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. removeKey.Clear();
  45. for (_downAllGameObjectPools.Begin(); _downAllGameObjectPools.Next();)
  46. {
  47. if (_downAllGameObjectPools.Value == null)
  48. {
  49. continue;
  50. }
  51. Vector3 objetcPos = _downAllGameObjectPools.Value.own.transform.position;
  52. if (Vector3.Distance(pos, objetcPos) > 1600)
  53. {
  54. removeKey.Add(_downAllGameObjectPools.Key);
  55. GObjectPool.Instance.Recycle(_downAllGameObjectPools.Value);
  56. // _allGameObjectPools.Value.SetActive(false);
  57. }
  58. }
  59. for (int i = 0; i < removeKey.Count; i++)
  60. {
  61. _downAllGameObjectPools.Remove(removeKey[i]);
  62. }
  63. // float radius = radius;
  64. int x = (int)(pos.x / radius);
  65. int z = (int)(pos.z / radius);
  66. float xStartInit = x;
  67. float zStartInit = z;
  68. for (int i = -4; i <= 10; i++)
  69. {
  70. for (int j = -4; j <= 20; j++)
  71. {
  72. float currX = (xStartInit + i) * radius;
  73. float currZ = (zStartInit + j) * radius;
  74. int key = (int)(currX * 1000 + currZ);
  75. InitUp(key, currX, currZ);
  76. InitDown(key, currX, currZ, i, j);
  77. }
  78. }
  79. }
  80. private void InitUp(int key, float currX, float currZ)
  81. {
  82. if (_allGameObjectPools.ContainsKey(key))
  83. {
  84. return;
  85. }
  86. GameObjectPool gameObjectPool = GetObejct(80);
  87. if (gameObjectPool != null)
  88. {
  89. float y = Random.Range(45.0f, 65.0f);
  90. float x = Random.Range(-3.0f, 3.0f);
  91. float z = Random.Range(-2.0f, 2.0f);
  92. gameObjectPool.own.transform.position = new Vector3(currX + x, y, currZ + z);
  93. float ry = Random.Range(0, 360);
  94. Vector3 eulerAngles = gameObjectPool.own.transform.eulerAngles;
  95. gameObjectPool.own.transform.eulerAngles = new Vector3(eulerAngles.x, ry, eulerAngles.z);
  96. gameObjectPool.own.transform.localScale = Vector3.one * 1.5f;
  97. }
  98. _allGameObjectPools.Add(key, gameObjectPool);
  99. }
  100. private void InitDown(int key, float currX, float currZ, int xintdex, int yindex)
  101. {
  102. if (_downAllGameObjectPools.ContainsKey(key))
  103. {
  104. return;
  105. }
  106. int odds = 50;
  107. GameObjectPool gameObjectPool = GetObejct(odds);
  108. if (gameObjectPool != null)
  109. {
  110. float y = Random.Range(-10.0f, 1.0f);
  111. int d = Mathf.Abs(Mathf.Abs(xintdex) - 1);
  112. if (d <= 1)
  113. {
  114. y = Random.Range(-10.0f - d * 10, -5.0f - d * 10);
  115. }
  116. float x = Random.Range(-3.0f, 3.0f);
  117. float z = Random.Range(-3.0f, 3.0f);
  118. gameObjectPool.own.transform.position = new Vector3(currX + x, y, currZ + z);
  119. float ry = Random.Range(0, 360);
  120. Vector3 eulerAngles = gameObjectPool.own.transform.eulerAngles;
  121. gameObjectPool.own.transform.eulerAngles = new Vector3(eulerAngles.x, ry, eulerAngles.z);
  122. gameObjectPool.own.transform.localScale = Vector3.one;
  123. }
  124. _downAllGameObjectPools.Add(key, gameObjectPool);
  125. }
  126. private GameObjectPool GetObejct(int currOdds)
  127. {
  128. int odds = Random.Range(0, 100);
  129. if (odds < currOdds)
  130. {
  131. return null;
  132. }
  133. int index = Random.Range(0, allObject.Length);
  134. GameObject gameObject = allObject[index];
  135. // GameObject go = GameObject.Instantiate(gameObject);
  136. GameObjectPool gameObjectPool =
  137. GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(gameObject, gameObject.name);
  138. return gameObjectPool;
  139. }
  140. }
  141. }