使用的是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);
}
}
}
Siccity/GLTFUtility: Simple GLTF importer for Unity 停在了21年,看样子是嘎了,建议转向 KhronosGroup/UnityGLTF: Runtime glTF 2.0 Loader for Unity3D
https://www.xuefei.net.cn/UnityGLTF/
https://gitee.com/awnuxcvbn/GLTFUtility
运行报错未解决
UnityGLTF.framework.js:3Error loading file: WaterBottle.glb Message: UnityGLTF/PBRGraph not found. Did you forget to add it to the build? For more information, see:https://github.com/KhronosGroup/UnityGLTF?tab=readme-ov-file#ensure-shaders-are-available-in-your-build StackTrace: at UnityGLTF.BaseGraphMap..ctor (System.String shaderName, System.String fallbackGuid) [0x00000] in ……