Unity Hololens Asset streaming optimization

329 Views Asked by At

I'm working on a Hololens app that displays a PNG image with info for the user. The images are loaded from a StreamingAssets folder in a coroutine. The issue lies in the speed at which these assets are loaded. If the user cycles to another page, the app momentarily drops to about 1-3 FPS on a PC.

What I hope some of you can help me with is think of ways to optimize the storage and streaming of these images. Is there a way to for example, load the image in a lower resolution to save on time and memory (with the hardware's very limited memory) and load in the additional detail when it actually needs to be displayed? Would multi-threading make the framerate better while loading the image?

1

There are 1 best solutions below

0
Wopsie On

So Programmer's suggestion in the comments helped eliminate the performance issues completely. The code down below is the coroutine that is used to stream in the required image(s) upon startup.

IEnumerator LoadImages()
{
    int oldImgIndx = imageIndex;
    imageIndex = 1;

    bool thereAreImages = true;
    while (thereAreImages && imageIndex < 1000)
    {
        if (System.IO.File.Exists(CreateFilePath(imageIndex)))
        {
            string url = "File:///" + CreateFilePath(imageIndex);
            Texture2D tex = new Texture2D(4, 4);
            WWW www = new WWW(url);
            yield return www;
            www.LoadImageIntoTexture(tex);
            spriteList.Add(Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f)));
            imageIndex++;
        }
        else
        {
            thereAreImages = false;
        }
    }
    finished = true;
    imageIndex = oldImgIndx;
}

The issue on the Hololens lies in the www.LoadImageIntoTexture(tex); line. This code is required when displaying multiple images on the PC side of things, however on the Hololens, where only one image is displayed at a time it can be left out.