123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using Newtonsoft.Json;
- using System.Collections;
- using System.Collections.Generic;
- using Unity.Mathematics;
- using Unity.VisualScripting;
- using UnityEngine;
- public class StaticLod : MonoBehaviour
- {
- public List<StaticImportant> staticImportants;
- public Dictionary<string, StaticImportant> staticImportantsDic;
- public static StaticLod instance;
- public bool lodAvalible = true;
- public StaticImportant currentStatic;
- public GameObject hetiGaoLiang;
- float interVal = 0;
- // Start is called before the first frame update
- void Awake()
- {
- instance = this;
- staticImportantsDic = new Dictionary<string, StaticImportant>();
- staticImportants = new List<StaticImportant>();
- for (int i = 0; i < this.transform.childCount; i++) {
- StaticImportant si = this.transform.GetChild(i).GetComponent<StaticImportant>();
- if (si != null)
- {
- staticImportants.Add(si);
- staticImportantsDic.Add(si.gameObject.name, si);
- si.Hide();
- }
- }
- }
- public void OnFoucusStatic(int i) {
- if (i < 0)
- {
- currentStatic = staticImportants[staticImportants.Count - math.abs(i)];
- }
- else {
- currentStatic = staticImportants[i];
- }
-
- currentStatic.ForceSacnMode();
- }
- public int OnFoucusStatic(StaticImportant si)
- {
- currentStatic = si;
- currentStatic.ForceSacnMode();
- return staticImportants.IndexOf(si);
- }
- public void OnFoucusStatic(string name_pri)
- {
- currentStatic = staticImportantsDic[name_pri];
- currentStatic.ForceSacnMode();
- }
- public GameObject GetStaticObj(string name_pri)
- {
- return staticImportantsDic[name_pri].gameObject;
- }
- // Update is called once per frame
- void Update()
- {
- interVal -= Time.deltaTime;
- if (lodAvalible)
- {
- if (interVal < 0.0f)
- {
- interVal = 0.8f;
- for (int i = 0; i < staticImportants.Count; i++)
- {
- if (Vector3.Distance(CameraManager.instance.mainCamera.transform.position, staticImportants[i].foucusPos) < 3200)
- {
- staticImportants[i].Show();
- }
- else
- {
- staticImportants[i].Hide();
- }
- }
- if (hetiGaoLiang != null) {
- if (CameraManager.instance.mainCamera.transform.position.y > 3000)
- {
- hetiGaoLiang.gameObject.SetActive(true);
- }
- else{
- hetiGaoLiang.gameObject.SetActive(false);
- }
- }
- }
- }
- else {
- for (int i = 0; i < staticImportants.Count; i++)
- {
- staticImportants[i].Show();
- }
- }
- }
- }
|