StaticLod.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using Newtonsoft.Json;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Unity.Mathematics;
  5. using Unity.VisualScripting;
  6. using UnityEngine;
  7. public class StaticLod : MonoBehaviour
  8. {
  9. public List<StaticImportant> staticImportants;
  10. public Dictionary<string, StaticImportant> staticImportantsDic;
  11. public static StaticLod instance;
  12. public bool lodAvalible = true;
  13. public StaticImportant currentStatic;
  14. public GameObject hetiGaoLiang;
  15. float interVal = 0;
  16. // Start is called before the first frame update
  17. void Awake()
  18. {
  19. instance = this;
  20. staticImportantsDic = new Dictionary<string, StaticImportant>();
  21. staticImportants = new List<StaticImportant>();
  22. for (int i = 0; i < this.transform.childCount; i++) {
  23. StaticImportant si = this.transform.GetChild(i).GetComponent<StaticImportant>();
  24. if (si != null)
  25. {
  26. if (si.important)
  27. {
  28. staticImportants.Add(si);
  29. //si.Hide();
  30. }
  31. staticImportantsDic.Add(si.gameObject.name, si);
  32. }
  33. }
  34. }
  35. public void OnFoucusStatic(int i) {
  36. if (i < 0)
  37. {
  38. currentStatic = staticImportants[staticImportants.Count - math.abs(i)];
  39. }
  40. else {
  41. currentStatic = staticImportants[i];
  42. }
  43. currentStatic.ForceSacnMode();
  44. }
  45. public int OnFoucusStatic(StaticImportant si)
  46. {
  47. currentStatic = si;
  48. currentStatic.ForceSacnMode();
  49. return staticImportants.IndexOf(si);
  50. }
  51. public void OnFoucusStatic(string name_pri)
  52. {
  53. currentStatic = staticImportantsDic[name_pri];
  54. currentStatic.ForceSacnMode();
  55. }
  56. public GameObject GetStaticObj(string name_pri)
  57. {
  58. return staticImportantsDic[name_pri].gameObject;
  59. }
  60. // Update is called once per frame
  61. void Update()
  62. {
  63. interVal -= Time.deltaTime;
  64. if (CameraManager.instance.mainCamera.enabled)
  65. {
  66. if (lodAvalible)
  67. {
  68. if (interVal < 0.0f)
  69. {
  70. interVal = 0.8f;
  71. for (int i = 0; i < staticImportants.Count; i++)
  72. {
  73. if (Vector3.Distance(CameraManager.instance.mainCamera.transform.position, staticImportants[i].foucusPos) < 3200)
  74. {
  75. staticImportants[i].Show();
  76. }
  77. else
  78. {
  79. staticImportants[i].Hide();
  80. }
  81. }
  82. if (hetiGaoLiang != null)
  83. {
  84. if (CameraManager.instance.mainCamera.transform.position.y > 3000)
  85. {
  86. hetiGaoLiang.gameObject.SetActive(true);
  87. }
  88. else
  89. {
  90. hetiGaoLiang.gameObject.SetActive(false);
  91. }
  92. }
  93. }
  94. }
  95. else
  96. {
  97. for (int i = 0; i < staticImportants.Count; i++)
  98. {
  99. staticImportants[i].Show();
  100. }
  101. }
  102. }
  103. }
  104. }