SceneCJ2MonoConfig.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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) > 600)
  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) > 600)
  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 <= 20; 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. }
  97. _allGameObjectPools.Add(key, gameObjectPool);
  98. }
  99. private void InitDown(int key, float currX, float currZ, int xintdex, int yindex)
  100. {
  101. if (_downAllGameObjectPools.ContainsKey(key))
  102. {
  103. return;
  104. }
  105. int odds = 50;
  106. GameObjectPool gameObjectPool = GetObejct(odds);
  107. if (gameObjectPool != null)
  108. {
  109. float y = Random.Range(-1.0f, 5.0f);
  110. if(Mathf.Abs(Mathf.Abs(xintdex)-1)<=1)
  111. {
  112. y = Random.Range(-1.0f, 1.0f);
  113. }
  114. float x = Random.Range(-3.0f, 3.0f);
  115. float z = Random.Range(-2.0f, 2.0f);
  116. gameObjectPool.own.transform.position = new Vector3(currX + x, y, currZ + z);
  117. float ry = Random.Range(0, 360);
  118. Vector3 eulerAngles = gameObjectPool.own.transform.eulerAngles;
  119. gameObjectPool.own.transform.eulerAngles = new Vector3(eulerAngles.x, ry, eulerAngles.z);
  120. }
  121. _downAllGameObjectPools.Add(key, gameObjectPool);
  122. }
  123. private GameObjectPool GetObejct(int currOdds)
  124. {
  125. int odds = Random.Range(0, 100);
  126. if (odds < currOdds)
  127. {
  128. return null;
  129. }
  130. int index = Random.Range(0, allObject.Length);
  131. GameObject gameObject = allObject[index];
  132. // GameObject go = GameObject.Instantiate(gameObject);
  133. GameObjectPool gameObjectPool =
  134. GObjectPool.Instance.FetchAsyncForGameObject<GameObjectPool>(gameObject, gameObject.name);
  135. return gameObjectPool;
  136. }
  137. }
  138. }