Unity

Unity 다운로드 이미지 표시방법

Dean83 2022. 3. 24. 22:11

//예시

    public Image raw;

private IEnumerator GetImageFiles(string fileName)
    {
        if(string.IsNullOrEmpty(fileName))
        {
            LogManager.ErrorLog("fileName is empty. Location : AIStudyExpansion->GetImageFiles");
            yield break;
        }
        string url = string.Format("{0}{1}", Constant.AWS_ADDRESS, fileName);
        
        var www = new WWW(url);
        // wait until the download is done
        yield return www;
        // Create a texture in DXT1 format
        Texture2D texture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.DXT1, false);

        // assign the downloaded image to sprite
        www.LoadImageIntoTexture(texture);
        Rect rec = new Rect(0, 0, texture.width, texture.height);
        Sprite spriteToUse = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100);
        raw.sprite = spriteToUse;

        www.Dispose();
        www = null;
    }

'Unity' 카테고리의 다른 글

코드난독화 어셋 사용법  (0) 2022.03.24
StopCoroutine, StartCoroutine 관련  (0) 2022.03.24
Pico VR 기기 컨트롤러 UI 연동  (0) 2022.03.24
Unity 다국어 관련  (0) 2022.03.24
Unity에서 AWS 스트리밍 관련  (0) 2022.03.24