public IEnumerator GetResourceAsync <T>(string path, string name, OnGetResourceAsyncComplete <T> onComplete) where T : UnityEngine.Object { WWW www = new WWW("file://" + Application.dataPath + "/" + path + name); yield return(www); onComplete(null); // Not sure what should be in there ... // Job done, this guy can get lost GameObject.Destroy(gameObject); }
private static T GetResourceAsync <T>(string path, string name, OnGetResourceAsyncComplete <T> onComplete) where T : UnityEngine.Object { if (_dictionary == null) { _dictionary = new Dictionary <string, Object>(); } UnityEngine.Object result; if (_dictionary.TryGetValue(name, out result)) { return(result as T); } else { // Create a temporary monobehaviour to execute the coroutine GameObject go = new GameObject(); go.hideFlags = HideFlags.HideAndDontSave; ResourceLoader rl = go.AddComponent <ResourceLoader>(); rl.StartCoroutine(rl.GetResourceAsync(path, name, onComplete)); return(null); } }
public static GameObject LoadPrefabAsync(string prefabName, OnGetResourceAsyncComplete <GameObject> onComplete) { return(GetResourceAsync <GameObject>(PREFABS_PATH, prefabName, onComplete)); }
public static GUISkin LoadSkinAsync(string skinName, OnGetResourceAsyncComplete <GUISkin> onComplete) { return(GetResourceAsync <GUISkin>(SKINS_PATH, skinName, onComplete)); }
public static Font LoadFontAsync(string fontName, OnGetResourceAsyncComplete <Font> onComplete) { return(GetResourceAsync <Font>(FONTS_PATH, fontName, onComplete)); }
public static Texture2D LoadTextureGui3DAsync(string texName, OnGetResourceAsyncComplete <Texture2D> onComplete) { return(GetResourceAsync <Texture2D>(GUI3D_PATH, texName, onComplete)); }
public static Shader LoadShaderAsync(string shaName, OnGetResourceAsyncComplete <Shader> onComplete) { return(GetResourceAsync <Shader>(SHADER_PATH, shaName, onComplete)); }
public static Material LoadMaterialAsync(string matName, OnGetResourceAsyncComplete <Material> onComplete) { return(GetResourceAsync <Material>(MATERIAL_PATH, matName, onComplete)); }