Created
April 6, 2018 07:53
-
-
Save sassembla/2a42d8e8bae0146e3d236fb8337f3830 to your computer and use it in GitHub Desktop.
ResourcesController for Autoya.
This file contains hidden or 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 System; | |
using System.Collections; | |
using AutoyaFramework; | |
using UnityEngine; | |
public class ResourcesController | |
{ | |
public static void LoadAsset<T>(string assetPath, Action<string, T> succeeded, Action<string, int, string, object> failed) where T : UnityEngine.Object | |
{ | |
var resRequest = Resources.LoadAsync(assetPath); | |
var cor = RequestCoroutine(assetPath, resRequest, succeeded, failed); | |
Autoya.Mainthread_Commit(cor); | |
} | |
private static IEnumerator RequestCoroutine<T>(string assetPath, ResourceRequest req, Action<string, T> succeeded, Action<string, int, string, object> failed) where T : UnityEngine.Object | |
{ | |
while (!req.isDone) | |
{ | |
yield return null; | |
} | |
if (req.asset == null) | |
{ | |
failed(assetPath, -1, "failed to find asset.", new object()); | |
yield break; | |
} | |
// req.asset is not null. | |
Debug.Log("req.asset:" + req.asset); | |
var casted = req.asset as T; | |
if (casted == null) | |
{ | |
failed(assetPath, -2, "failed to cast asset to required type.", new object()); | |
yield break; | |
} | |
succeeded(assetPath, casted); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage