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; bool onShow = true; public ModelAniTool _ModelAni; private List models = new List(); 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() { if (onShow) return; onShow = true; for (int i = 0; i < models.Count; i++) { models[i].SetActive(true); } CheckChangeModels(); } public void Hide() { if (!onShow) return; onShow = false; 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(); if (birdCamera != null) { MeshRenderer fader = birdCamera.transform.GetChild(0).GetComponent(); 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, new Vector2(rotateXAngle, rotateYAngle)); } public void SetCameraToCenter(Vector3 centerPos, float distance, Vector2 rota) { targetDistance = distance; rotateXAngle = rota.x; rotateYAngle = rota.y; CameraBird birdCamera = CameraManager.instance.mainCamera.GetComponent(); if (birdCamera != null) { MeshRenderer fader = birdCamera.transform.GetChild(0).GetComponent(); 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(); for (int i = 0; i < objs.Length; i++) { GameObject insObj = Instantiate(objs[i], this.transform); insObj.layer = 9; for (int j = 0; j < insObj.transform.childCount; j++) { insObj.transform.GetChild(j).gameObject.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; if (_ModelAni != null) { _ModelAni.FindObje(); } } else { Debug.LogError($"{model_ab_Name}下载失败:{www.error}"); } www.Dispose(); } }