StaticLod.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. //Debug.Log(si.gameObject.name);
  33. //Debug.Log(si);
  34. }
  35. }
  36. }
  37. public void OnFoucusStatic(int i) {
  38. if (currentStatic != null)
  39. currentStatic.ReleaseSacnMode();
  40. if (i < 0)
  41. {
  42. currentStatic = staticImportants[staticImportants.Count - math.abs(i)];
  43. }
  44. else {
  45. currentStatic = staticImportants[i];
  46. }
  47. currentStatic.ForceSacnMode();
  48. }
  49. public int OnFoucusStatic(StaticImportant si)
  50. {
  51. if (currentStatic != null)
  52. currentStatic.ReleaseSacnMode();
  53. currentStatic = si;
  54. currentStatic.ForceSacnMode();
  55. return staticImportants.IndexOf(si);
  56. }
  57. public void OnFoucusStatic(string name_pri)
  58. {
  59. if (currentStatic != null)
  60. currentStatic.ReleaseSacnMode();
  61. currentStatic = staticImportantsDic[name_pri];
  62. currentStatic.ForceSacnMode();
  63. }
  64. public GameObject GetStaticObj(string name_pri)
  65. {
  66. return staticImportantsDic[name_pri].gameObject;
  67. }
  68. // Update is called once per frame
  69. void Update()
  70. {
  71. interVal -= Time.deltaTime;
  72. if (CameraManager.instance.mainCamera.enabled)
  73. {
  74. if (lodAvalible)
  75. {
  76. if (interVal < 0.0f)
  77. {
  78. interVal = 0.8f;
  79. for (int i = 0; i < staticImportants.Count; i++)
  80. {
  81. if (Vector3.Distance(CameraManager.instance.mainCamera.transform.position, staticImportants[i].foucusPos) < 3200)
  82. {
  83. staticImportants[i].Show();
  84. }
  85. else
  86. {
  87. //Debug.Log(staticImportants[i].name);
  88. staticImportants[i].Hide();
  89. }
  90. }
  91. if (hetiGaoLiang != null)
  92. {
  93. if (CameraManager.instance.mainCamera.transform.position.y > 3000)
  94. {
  95. hetiGaoLiang.gameObject.SetActive(true);
  96. }
  97. else
  98. {
  99. hetiGaoLiang.gameObject.SetActive(false);
  100. }
  101. }
  102. }
  103. }
  104. else
  105. {
  106. for (int i = 0; i < staticImportants.Count; i++)
  107. {
  108. staticImportants[i].Show();
  109. }
  110. }
  111. }
  112. }
  113. }