Skip to content

Instantly share code, notes, and snippets.

@WestHillApps
Last active April 10, 2019 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WestHillApps/d34ffe886572bf801dd1 to your computer and use it in GitHub Desktop.
Save WestHillApps/d34ffe886572bf801dd1 to your computer and use it in GitHub Desktop.
Resources.LoadAsyncのテスト
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