C# 在Unity中作为纹理加载和播放电影
我遇到了一个奇怪的情况,下面的脚本将成功加载并在unity中播放电影纹理:C# 在Unity中作为纹理加载和播放电影,c#,unity3d,textures,movie,C#,Unity3d,Textures,Movie,我遇到了一个奇怪的情况,下面的脚本将成功加载并在unity中播放电影纹理: using UnityEngine; using System.Collections; public class Tester : MonoBehaviour { MovieTexture _tex; Renderer _rend; bool _initTex = false; // Use this for initialization void Start () {
using UnityEngine;
using System.Collections;
public class Tester : MonoBehaviour {
MovieTexture _tex;
Renderer _rend;
bool _initTex = false;
// Use this for initialization
void Start () {
_rend = GetComponent(typeof(Renderer)) as Renderer;
}
// Update is called once per frame
void Update () {
if (!_initTex) {
initTex();
} else {
if (!_tex.isReadyToPlay) {
Debug.Log("Waiting for _tex");
} else if (!_tex.isPlaying) {
_rend.material.mainTexture = _tex;
_tex.Play();
}
}
}
void initTex() {
WWW req = new WWW("http://www.unity3d.com/webplayers/Movie/sample.ogg");
if (req.error != null) {
Debug.Log("Error: " + req.error);
} else {
Debug.Log("Got movie = " + (req.movie != null).ToString());
_tex = req.movie;
_initTex = true;
}
}
}
但是,如果我将其放入我的资产文件夹并更改行:
WWW req = new WWW("http://www.unity3d.com/webplayers/Movie/sample.ogg");
致:
我收到无休止的等待_tex
消息(见上文)。正在成功加载MovieTexture
,但\u tex.isReadyToPlay
永远不会为真
这是怎么回事
此外,当播放电影文件时,加载和播放之间通常会有很长的延迟。是否有更有效的方法将电影加载并准备到
MovieTexture
?电影文件需要放在名为StreamingAssets的文件夹(资产中的任何位置)中。使用Application.streamingassetpath代替Application.dataPath
这将确保无论您的目标平台是什么,找到电影的路径都是正确的
string path = Application.dataPath + "/Videos/sample.ogg";
WWW req = new WWW(path);