Reputation: 103
Hello i load texture this code: settingSplit this is string array.
IEnumerator DownloadLogos()
{
WWW www = new WWW(settingsSplit[0]);
while (www.progress < 1)
{
slider.GetComponent<UISlider>().value = www.progress;
if (slider.GetComponent<UISlider>().value > 0.880f)
{
slider.GetComponent<UISlider>().value = 1;
}
yield return new WaitForEndOfFrame();
}
yield return www;
if (www.error == null)
{
fadein = true;
model.GetComponent<Animation>().Play();
texTmp = www.textureNonReadable;
spr = Sprite.Create(texTmp, new Rect(0, 0, texTmp.width, texTmp.height), Vector2.zero, 50);
spr.texture.wrapMode = TextureWrapMode.Clamp;
mat.mainTexture = spr.texture;
decal.sprite = spr;
yield return new WaitForEndOfFrame();
slider.SetActive(false);
float multipier = 1;
if (settingsSplit[2] != null)
{
multipier = float.Parse(settingsSplit[2]);
}
decal.transform.localScale = new Vector3(decal.transform.localScale.x * multipier,
decal.transform.localScale.y * multipier, decal.transform.localScale.z);
BuildDecal(decal);
}
Work fine but When texture load MainThread stop for some time (1-2 second). How i can fix this ? Thanks!
Upvotes: 1
Views: 1781
Reputation: 1172
I don't know if you have solved this, but I was facing the same problem. The problematic line is
spr = Sprite.Create(texTmp, new Rect(0, 0, texTmp.width, texTmp.height), Vector2.zero, 50);
Because the creation of the Sprite takes a while and runs in the main thread, which causes your game to freeze.
My solution was to use a RawImage instead of an Image to display the loaded texture, just delete the mentioned line and replace
decal.sprite = spr;
with
decal.texture = www.texture;
and set the rest of properties/values you want to use.
I hope this helps someone having this problem.
Upvotes: 3
Reputation: 650
WaitForEndOfFrame resumes at the end of the frame. I'm fairly certain if you yield for the end of the frame, at the end of the frame, you still wont progress to the next frame. Just yield null and you will resume the next frame.
while (www.progress < 1)
{
slider.GetComponent<UISlider>().value = www.progress;
if (slider.GetComponent<UISlider>().value > 0.880f)
{
slider.GetComponent<UISlider>().value = 1;
}
yield return null;
}
Upvotes: 0