StaticLod.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. float interVal = 0;
  15. // Start is called before the first frame update
  16. void Awake()
  17. {
  18. instance = this;
  19. staticImportantsDic = new Dictionary<string, StaticImportant>();
  20. staticImportants = new List<StaticImportant>();
  21. for (int i = 0; i < this.transform.childCount; i++) {
  22. StaticImportant si = this.transform.GetChild(i).GetComponent<StaticImportant>();
  23. if (si != null)
  24. {
  25. staticImportants.Add(si);
  26. staticImportantsDic.Add(si.gameObject.name, si);
  27. }
  28. }
  29. }
  30. public void OnFoucusStatic(int i) {
  31. if (i < 0)
  32. {
  33. currentStatic = staticImportants[staticImportants.Count - math.abs(i)];
  34. }
  35. else {
  36. currentStatic = staticImportants[i];
  37. }
  38. currentStatic.ForceSacnMode();
  39. }
  40. public int OnFoucusStatic(StaticImportant si)
  41. {
  42. currentStatic = si;
  43. currentStatic.ForceSacnMode();
  44. return staticImportants.IndexOf(si);
  45. }
  46. public void OnFoucusStatic(string name_pri)
  47. {
  48. currentStatic = staticImportantsDic[name_pri];
  49. currentStatic.ForceSacnMode();
  50. }
  51. public GameObject GetStaticObj(string name_pri)
  52. {
  53. return staticImportantsDic[name_pri].gameObject;
  54. }
  55. // Update is called once per frame
  56. void Update()
  57. {
  58. interVal -= Time.deltaTime;
  59. if (lodAvalible)
  60. {
  61. if (interVal < 0.0f)
  62. {
  63. interVal = 0.2f;
  64. for (int i = 0; i < staticImportants.Count; i++)
  65. {
  66. if (Vector3.Distance(CameraManager.instance.mainCamera.transform.position, staticImportants[i].foucusPos) < 3200)
  67. {
  68. staticImportants[i].Show();
  69. }
  70. else
  71. {
  72. staticImportants[i].Hide();
  73. }
  74. }
  75. }
  76. }
  77. else {
  78. for (int i = 0; i < staticImportants.Count; i++)
  79. {
  80. staticImportants[i].Show();
  81. }
  82. }
  83. }
  84. }