123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- using System;
- using AIPagedLod;
- using LitJson;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using Unity.VisualScripting;
- using DG.Tweening;
- using UnityAsync;
- using System.Threading.Tasks;
- using UnityEngine.UIElements;
- public class StaticImportant : MonoBehaviour
- {
- public Vector3 foucusPos;
- public float targetDistance;
- public float rotateXAngle;
- public float rotateYAngle;
- public bool findChangeObjs = false;
- public string[] FarObjName;
- public string[] NearObjName;
- public GameObject[] FarShowObj;
- public GameObject[] nearShowObj;
- public float showDistance = 100;
- private bool showNear = false;
- public bool waitCreatModels = false;
- public string model_ab_Name;
- private List<GameObject> models = new List<GameObject>();
- private void Awake()
- {
- foucusPos = this.transform.position;
- if (!waitCreatModels)
- {
- for (int i = 0; i < this.transform.childCount; i++)
- {
- models.Add(this.transform.GetChild(i).gameObject);
- }
- if (findChangeObjs)
- {
- FarShowObj = new GameObject[FarObjName.Length];
- nearShowObj = new GameObject[NearObjName.Length];
- for (int i = 0; i < FarObjName.Length; i++)
- {
- FarShowObj[i] = this.transform.Find(FarObjName[i]).gameObject;
- }
- for (int i = 0; i < nearShowObj.Length; i++)
- {
- nearShowObj[i] = this.transform.Find(NearObjName[i]).gameObject;
- }
- }
- }
- }
- private void Start()
- {
- if (waitCreatModels)
- {
- StartCoroutine(CreatModels());
- }
- }
- public void Show()
- {
- for (int i = 0; i < models.Count; i++)
- {
- models[i].SetActive(true);
- }
- CheckChangeModels();
- }
- public void Hide()
- {
- for (int i = 0; i < models.Count; i++)
- {
- models[i].SetActive(false);
- }
- }
- public void ForceSacnMode()
- {
- gameObject.SetActive(true);
- SetCameraToCenter();
- }
- private void Update()
- {
- if (waitCreatModels)
- {
- return;
- }
- if (CameraManager.instance.mainCamera.transform.position.y < showDistance)
- {
- if (showNear != true)
- {
- showNear = true;
- for (int i = 0; i < FarShowObj.Length; i++)
- {
- FarShowObj[i].SetActive(false);
- }
- for (int i = 0; i < nearShowObj.Length; i++)
- {
- nearShowObj[i].SetActive(true);
- }
- }
- }
- else
- {
- if (showNear != false)
- {
- showNear = false;
- for (int i = 0; i < FarShowObj.Length; i++)
- {
- FarShowObj[i].SetActive(true);
- }
- for (int i = 0; i < nearShowObj.Length; i++)
- {
- nearShowObj[i].SetActive(false);
- }
- }
- }
- }
- private void CheckChangeModels()
- {
- if (CameraManager.instance.mainCamera.transform.position.y < showDistance)
- {
- showNear = true;
- for (int i = 0; i < FarShowObj.Length; i++)
- {
- FarShowObj[i].SetActive(false);
- }
- for (int i = 0; i < nearShowObj.Length; i++)
- {
- nearShowObj[i].SetActive(true);
- }
- }
- else
- {
- showNear = false;
- for (int i = 0; i < FarShowObj.Length; i++)
- {
- FarShowObj[i].SetActive(true);
- }
- for (int i = 0; i < nearShowObj.Length; i++)
- {
- nearShowObj[i].SetActive(false);
- }
- }
- }
- public void SetCameraToCenter()
- {
- CameraBird birdCamera = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
- if (birdCamera != null)
- {
- MeshRenderer fader = birdCamera.transform.GetChild(0).GetComponent<MeshRenderer>();
- fader.gameObject.SetActive(true);
- fader.material.DOColor(Color.white, 0.1f).onComplete = () =>
- {
- fader.material.DOColor(Color.clear, 1.5f).onComplete = () => { fader.gameObject.SetActive(false); };
- };
- birdCamera.target.localPosition = foucusPos;
- Debug.Log(birdCamera.target.position);
- birdCamera.currentDistance = targetDistance;
- birdCamera.rotateXAngle = rotateXAngle;
- birdCamera.rotateYAngle = rotateYAngle;
- birdCamera.Blink();
- }
- ModelCameraCtrl._Instance.SetCameraPos(birdCamera.target,targetDistance);
- }
- public void SetCameraToCenter(Vector3 centerPos, float distance,Vector2 rota)
- {
- targetDistance = distance;
- rotateXAngle = rota.x;
- rotateYAngle = rota.y;
- CameraBird birdCamera = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
- if (birdCamera != null)
- {
- MeshRenderer fader = birdCamera.transform.GetChild(0).GetComponent<MeshRenderer>();
- fader.gameObject.SetActive(true);
- fader.material.DOColor(Color.white, 0.1f).onComplete = () =>
- {
- fader.material.DOColor(Color.clear, 1.5f).onComplete = () => { fader.gameObject.SetActive(false); };
- };
- birdCamera.target.localPosition = centerPos;
- Debug.Log(birdCamera.target.position);
- birdCamera.currentDistance = targetDistance;
- birdCamera.rotateXAngle = rotateXAngle;
- birdCamera.rotateYAngle = rotateYAngle;
- birdCamera.Blink();
- }
- }
- IEnumerator CreatModels()
- {
- WaitForEndOfFrame wait = new WaitForEndOfFrame();
- WWW www = WWW.LoadFromCacheOrDownload($"{Application.streamingAssetsPath}/{model_ab_Name}", 0);
- yield return www;
- if (www.isDone)
- {
- var tempAb = www.assetBundle;
- GameObject[] objs = tempAb.LoadAllAssets<GameObject>();
- for (int i = 0; i < objs.Length; i++)
- {
- GameObject insObj = Instantiate(objs[i], this.transform);
- insObj.layer = 9;
- models.Add(insObj);
- yield return wait;
- }
- if (findChangeObjs)
- {
- FarShowObj = new GameObject[FarObjName.Length];
- nearShowObj = new GameObject[NearObjName.Length];
- for (int i = 0; i < FarObjName.Length; i++)
- {
- FarShowObj[i] = this.transform.Find(FarObjName[i] + "(Clone)").gameObject;
- }
- for (int i = 0; i < nearShowObj.Length; i++)
- {
- nearShowObj[i] = this.transform.Find(NearObjName[i] + "(Clone)").gameObject;
- }
- }
- waitCreatModels = false;
- }
- else
- {
- Debug.LogError($"{model_ab_Name}下载失败:{www.error}");
- }
- www.Dispose();
- }
- }
|