ShowModelManager.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using TriLibCore;
  5. using UnityEngine;
  6. public class ShowModelManager : MonoBehaviour
  7. {
  8. public GameObject root;
  9. public TextMeshProUGUI info;
  10. private void OnEnable()
  11. {
  12. this.transform.localPosition = Vector3.zero;
  13. this.transform.localEulerAngles = Vector3.zero;
  14. this.transform.localScale = Vector3.one;
  15. }
  16. public void Onupdate(string url)
  17. {
  18. if(root!=null)
  19. {
  20. Destroy(root);
  21. root = null;
  22. }
  23. TriLibModelLoad.Load(url, (AssetLoaderContext ac) => {
  24. ac.RootGameObject.SetActive(false);
  25. //Debug.Log("模型加载完成");
  26. }, (AssetLoaderContext ac) => {
  27. info.gameObject.SetActive(false);
  28. if (root != null)
  29. {
  30. Destroy(root);
  31. root = null;
  32. }
  33. //Debug.Log("载材质加完成");
  34. root = ac.RootGameObject;
  35. ac.RootGameObject.transform.localEulerAngles = new Vector3(0, -90, 0);
  36. ac.RootGameObject.transform.localPosition = Vector3.zero;
  37. Bounds bounds = GetAllBounds.GetRendererBounds(root);
  38. GameObject obj = new GameObject("Test");
  39. obj.transform.parent = ac.RootGameObject.transform;
  40. obj.transform.position = bounds.center;
  41. float bizhi = 0.4f / bounds.size.x;
  42. ac.RootGameObject.transform.localScale = Vector3.one*bizhi;
  43. ac.RootGameObject.transform.parent = this.transform;
  44. ac.RootGameObject.transform.localPosition = Vector3.zero- obj.transform.position * 1000;
  45. ac.RootGameObject.SetActive(true);
  46. }, (AssetLoaderContext ac, float f) => {
  47. info.gameObject.SetActive(true);
  48. info.text = "模型努力加载中\n" + (f*100).ToString("F2") + "%";
  49. //Debug.Log("加载中==》" + f);
  50. }, (IContextualizedError error) => {
  51. info.gameObject.SetActive(true);
  52. info.text = "加载失败" + error;
  53. //Debug.Log("加载失败" + error);
  54. });
  55. }
  56. }