我正在尝试为 OculusGO 构建一个应用程序,但文件太大,所以我正在使用 AssetBundles 来减小大小。到目前为止,我一直在使用此链接在 Unity 中构建和加载 Assetbundles,但我不知道如何处理视频。
我目前将此作为应用程序的加载程序,但我需要从 AssetBundle 加载它
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
[CreateAssetMenu(fileName = "Situation", menuName = "Situation", order = 1)]
public class SituationData : ScriptableObject
{
public VideoClip video;
public AssetBundle.LoadFromFileAsync(Assets/StreamingAssets/AssetBundles);
public Sprite screenshot;
public Sprite situationPanel;
public Sprite situationPanelSelected;
public string objectiveText;
public string sessionName;
public float startRotation;
IEnumerator LoadAsset(string assetBundleName, string objectNameToLoad)
{
string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "AssetBundles");
filePath = System.IO.Path.Combine(filePath, assetBundleName);
//Load "animals" AssetBundle
var assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(filePath);
yield return assetBundleCreateRequest;
AssetBundle asseBundle = assetBundleCreateRequest.assetBundle;
//Load the "dog" Asset (Use Texture2D since it's a Texture. Use GameObject if prefab)
AssetBundleRequest asset = asseBundle.LoadAssetAsync<VideoClip>(objectNameToLoad);
yield return asset;
//Retrieve the object (Use Texture2D since it's a Texture. Use GameObject if prefab)
VideoClip loadedAsset = asset.asset as VideoClip;
//Do something with the loaded loadedAsset object (Load to RawImage for example)
image.texture = loadedAsset;
}
}
为了清楚起见,我已经构建了 AssetBundle,我只是不知道如何加载它们而不是实际的视频文件,因此我可以减小文件大小。