StaticLod.cs 3.6 KB

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