12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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;
- 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);
- }
- }
- }
- 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.2f;
- 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();
- }
- }
- }
- }
- else {
- for (int i = 0; i < staticImportants.Count; i++)
- {
- staticImportants[i].Show();
- }
- }
- }
- }
|