Last active
April 10, 2019 13:38
-
-
Save westhillapps/d34ffe886572bf801dd1 to your computer and use it in GitHub Desktop.
Resources.LoadAsyncのテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class ResLoadAsyncTest : MonoBehaviour | |
{ | |
// リソースフォルダ以下のファイルパス | |
[SerializeField] | |
string filePath; | |
void Start () | |
{ | |
StartCoroutine (LoadAsyncTextureCoroutine (filePath)); | |
} | |
/// <summary> | |
/// リソースからテクスチャを非同期でロードするコルーチン | |
/// </summary> | |
public IEnumerator LoadAsyncTextureCoroutine (string filePath) | |
{ | |
// リソースの非同期読込開始 | |
ResourceRequest resReq = Resources.LoadAsync<Texture2D> (filePath); | |
// 終わるまで待つ | |
while (resReq.isDone == false) { | |
Debug.Log ("Loading progress:" + resReq.progress.ToString ()); | |
yield return null; | |
} | |
// テクスチャ表示 | |
renderer.material.mainTexture = resReq.asset as Texture2D; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment