StaticLod.cs 3.0 KB

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