赞
踩
使用的是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
主要代码
- using System.Collections;
- using UnityEngine;
- using Siccity.GLTFUtility;
- using UnityEngine.UI;
- using UnityEngine.Networking;
-
- public class GLTFTest : MonoBehaviour
- {
- public Button button;
- public GameObject loadGo = null;
-
- // Start is called before the first frame update
- void Start()
- {
- button.onClick.AddListener(delegate
- {
- StartCoroutine(LoadGo());
- });
- }
-
- private IEnumerator LoadGo()
- {
- if (loadGo != null)
- {
- DestroyImmediate(loadGo);
- Resources.UnloadUnusedAssets();
- }
- var request = UnityWebRequest.Get("https://www.xuefei.net.cn/unitywebgl/WaterBottle.glb");
- yield return request.SendWebRequest();
- if (request.result != UnityWebRequest.Result.Success)
- {
- Debug.LogError(request.error);
- }
- else
- {
- Debug.Log(request.downloadHandler.text);
- loadGo = Importer.LoadFromBytes(request.downloadHandler.data);
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。