【发布时间】:2016-02-21 21:48:55
【问题描述】:
我有一个协程在运行时通过 www 类下载一个 .ogg 文件,这目前确实不一致。
视频旨在以其正常大小 (320 x 240px) 显示,有时这可以正常工作。但是,视频经常显示在16 x 16px。
在我看来,这主要是由于没有使用当前协程完全下载视频。我已尽我所能遵循文档(ScriptRef/www-movie),但无济于事,如果有人对为什么会发生这种情况有任何建议,我将不胜感激。
注意:在 uJS 中编写脚本。
非常感谢,
瑞恩
function loadContextVideo(texLocation : String)
{
var wwwDirectory = "file://" + texLocation;
var vidTex = www.movie; //method 01 [using local variables]
// vidTex = www.movie; //method 02 [using public variables]
while(!vidTex.isReadyToPlay){ //****PROBLEM COROUTINE*****
yield www;
if (www.isDone)
{
break;
}
}
var texWidth = vidTex.width;
var texHeight = vidTex.height;
Debug.Log("texWidth: " + texWidth + " texHeight: " + texHeight);
//check img sizes
var mvMaxWidth = imgRect.rect.width;
var mvMaxHeight = imgRect.rect.height;
Debug.Log("mvMaxWidth: " + mvMaxWidth + " mvMaxHeight: " + mvMaxHeight);
if (texHeight > mvMaxHeight)
{
var scaleHFactor = mvMaxHeight /texHeight;
texHeight = texHeight * scaleHFactor;
texWidth = texWidth * scaleHFactor;
}
if (texWidth > mvMaxWidth)
{
var scaleWFactor = mvMaxWidth /texWidth;
texHeight = texHeight * scaleWFactor;
texWidth = texWidth * scaleWFactor;
}
Debug.Log("texWidth: " + texWidth + " texHeight: " + texHeight);
imgRect.sizeDelta = new Vector2(texWidth, texHeight);
//Video Tex assign
var imgView : UI.RawImage = imageView.GetComponent.<RawImage>(); //method 01 [using local variables]
// var imgView = imageRender; //method 02 [using public variables]
imgView.texture = vidTex;
//Video Audio assign
var vidAudio : AudioSource = imageView.GetComponent.<AudioSource>();
vidAudio.clip = vidTex.audioClip;
//curVideo = vidTex;
vidTex.Play();
vidAudio.Play();
}
【问题讨论】:
-
"unityscript" 现已弃用,并将从 Unity 中移除。使用 u/s 做这样的事情是非常困难的。 (幸运的是c#实际上要容易得多)
-
嗨@Joe Blow,感谢您的建议;您在另一个 question 中向我提供了类似的反馈,虽然我认识到需要从 uJS 进行更改,但我当前项目的时间限制不允许我学习 C#。你能告诉我当前协程中的逻辑在哪里失效吗?它似乎非常接近,但并不可靠。
-
尝试删除 www.isDone 检查。
-
嗨@fafase,感谢您的回复!已经测试了你的建议,同样的问题似乎仍然存在。你能解释你的逻辑吗?非常感谢。
标签: video unity3d runtime unityscript coroutine