1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.Collections;
- using System.Collections.Generic;
- using TMPro;
- using TriLibCore;
- using UnityEngine;
- public class ShowModelManager : MonoBehaviour
- {
- public GameObject root;
- public TextMeshProUGUI info;
- private void OnEnable()
- {
- this.transform.localPosition = Vector3.zero;
- this.transform.localEulerAngles = Vector3.zero;
- this.transform.localScale = Vector3.one;
- }
- public void Onupdate(string url)
- {
- if(root!=null)
- {
- Destroy(root);
- root = null;
- }
- TriLibModelLoad.Load(url, (AssetLoaderContext ac) => {
- ac.RootGameObject.SetActive(false);
-
- }, (AssetLoaderContext ac) => {
- info.gameObject.SetActive(false);
- if (root != null)
- {
- Destroy(root);
- root = null;
- }
-
- root = ac.RootGameObject;
- ac.RootGameObject.transform.localEulerAngles = new Vector3(0, -90, 0);
- ac.RootGameObject.transform.localPosition = Vector3.zero;
- Bounds bounds = GetAllBounds.GetRendererBounds(root);
- GameObject obj = new GameObject("Test");
- obj.transform.parent = ac.RootGameObject.transform;
- obj.transform.position = bounds.center;
- float bizhi = 0.4f / bounds.size.x;
- ac.RootGameObject.transform.localScale = Vector3.one*bizhi;
- ac.RootGameObject.transform.parent = this.transform;
- ac.RootGameObject.transform.localPosition = Vector3.zero- obj.transform.position * 1000;
- ac.RootGameObject.SetActive(true);
- }, (AssetLoaderContext ac, float f) => {
- info.gameObject.SetActive(true);
- info.text = "模型努力加载中\n" + (f*100).ToString("F2") + "%";
-
- }, (IContextualizedError error) => {
- info.gameObject.SetActive(true);
- info.text = "加载失败" + error;
-
- });
- }
- }
|