Exemple #1
0
    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);
    }
Exemple #2
0
    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);
        }
    }
Exemple #3
0
 public static GameObject LoadPrefabAsync(string prefabName, OnGetResourceAsyncComplete <GameObject> onComplete)
 {
     return(GetResourceAsync <GameObject>(PREFABS_PATH, prefabName, onComplete));
 }
Exemple #4
0
 public static GUISkin LoadSkinAsync(string skinName, OnGetResourceAsyncComplete <GUISkin> onComplete)
 {
     return(GetResourceAsync <GUISkin>(SKINS_PATH, skinName, onComplete));
 }
Exemple #5
0
 public static Font LoadFontAsync(string fontName, OnGetResourceAsyncComplete <Font> onComplete)
 {
     return(GetResourceAsync <Font>(FONTS_PATH, fontName, onComplete));
 }
Exemple #6
0
 public static Texture2D LoadTextureGui3DAsync(string texName, OnGetResourceAsyncComplete <Texture2D> onComplete)
 {
     return(GetResourceAsync <Texture2D>(GUI3D_PATH, texName, onComplete));
 }
Exemple #7
0
 public static Shader LoadShaderAsync(string shaName, OnGetResourceAsyncComplete <Shader> onComplete)
 {
     return(GetResourceAsync <Shader>(SHADER_PATH, shaName, onComplete));
 }
Exemple #8
0
 public static Material LoadMaterialAsync(string matName, OnGetResourceAsyncComplete <Material> onComplete)
 {
     return(GetResourceAsync <Material>(MATERIAL_PATH, matName, onComplete));
 }