StaticLod.cs 3.0 KB

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