当前位置:   article > 正文

Unity的WebGL平台动态加载glb/gltf测试_unity webgl 动态加载

unity webgl 动态加载

使用的是GLTFUtility GitHub - Siccity/GLTFUtility: Simple GLTF importer for Unity
gltf样品库 GitHub - KhronosGroup/glTF-Sample-Models: glTF Sample Models
我的测试模型 https://www.xuefei.net.cn/unitywebgl/WaterBottle.glb
我的webgl测试地址 Unity WebGL Player | GLTFUtility
主要代码

  1. using System.Collections;
  2. using UnityEngine;
  3. using Siccity.GLTFUtility;
  4. using UnityEngine.UI;
  5. using UnityEngine.Networking;
  6. public class GLTFTest : MonoBehaviour
  7. {
  8. public Button button;
  9. public GameObject loadGo = null;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. button.onClick.AddListener(delegate
  14. {
  15. StartCoroutine(LoadGo());
  16. });
  17. }
  18. private IEnumerator LoadGo()
  19. {
  20. if (loadGo != null)
  21. {
  22. DestroyImmediate(loadGo);
  23. Resources.UnloadUnusedAssets();
  24. }
  25. var request = UnityWebRequest.Get("https://www.xuefei.net.cn/unitywebgl/WaterBottle.glb");
  26. yield return request.SendWebRequest();
  27. if (request.result != UnityWebRequest.Result.Success)
  28. {
  29. Debug.LogError(request.error);
  30. }
  31. else
  32. {
  33. Debug.Log(request.downloadHandler.text);
  34. loadGo = Importer.LoadFromBytes(request.downloadHandler.data);
  35. }
  36. }
  37. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/91994
推荐阅读
相关标签
  

闽ICP备14008679号