StaticLod.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Newtonsoft.Json;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Unity.VisualScripting;
  5. using UnityEngine;
  6. public class StaticLod : MonoBehaviour
  7. {
  8. public List<StaticImportant> staticImportants;
  9. public Dictionary<string, StaticImportant> staticImportantsDic;
  10. public static StaticLod instance;
  11. public StaticImportant currentStatic;
  12. float interVal = 0;
  13. // Start is called before the first frame update
  14. void Awake()
  15. {
  16. instance = this;
  17. staticImportantsDic = new Dictionary<string, StaticImportant>();
  18. staticImportants = new List<StaticImportant>();
  19. for (int i = 0; i < this.transform.childCount; i++) {
  20. StaticImportant si = this.transform.GetChild(i).GetComponent<StaticImportant>();
  21. if (si != null)
  22. {
  23. staticImportants.Add(si);
  24. staticImportantsDic.Add(si.gameObject.name, si);
  25. }
  26. }
  27. }
  28. public void OnFoucusStatic(int i) {
  29. currentStatic = staticImportants[i];
  30. Debug.Log("11111111111111111:" + currentStatic);
  31. currentStatic.ForceSacnMode();
  32. }
  33. public int OnFoucusStatic(StaticImportant si)
  34. {
  35. currentStatic = si;
  36. currentStatic.ForceSacnMode();
  37. return staticImportants.IndexOf(si);
  38. }
  39. public void OnFoucusStatic(string name_pri)
  40. {
  41. currentStatic = staticImportantsDic[name_pri];
  42. currentStatic.ForceSacnMode();
  43. }
  44. public GameObject GetStaticObj(string name_pri)
  45. {
  46. return staticImportantsDic[name_pri].gameObject;
  47. }
  48. // Update is called once per frame
  49. void Update()
  50. {
  51. interVal -= Time.deltaTime;
  52. if (interVal < 0.0f) {
  53. interVal = 0.2f;
  54. for (int i = 0; i < staticImportants.Count; i++)
  55. {
  56. if (Vector3.Distance(CameraManager.instance.mainCamera.transform.position, staticImportants[i].foucusPos) < 3200)
  57. {
  58. staticImportants[i].Show();
  59. }
  60. else {
  61. staticImportants[i].Hide();
  62. }
  63. }
  64. }
  65. }
  66. }