Beispiel #1
0
    public UnityEngine.Object LoadAssetSync(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }

        AssetLoader loader = null;

        loaderCache.TryGetValue(path, out loader);
        if (loader != null)
        {
            if (loader.IsAlive())
            {
                return(loader.asset);
            }
            else
            {
                loaderPool.Store(loader);
                loaderCache.Remove(path);
            }
        }

        UnityEngine.Object asset = Resources.Load(path);
        loader = loaderPool.Fetch();
        loader.BindAsset(asset);
        loaderCache.Add(path, loader);
        return(asset);
    }
Beispiel #2
0
    IEnumerator LoadAsyncCorotine(string path, Action <UnityEngine.Object> callback)
    {
        var request = Resources.LoadAsync(path);

        while (!request.isDone)
        {
            yield return(null);
        }
        UnityEngine.Object asset  = request.asset;
        AssetLoader        loader = loaderPool.Fetch();

        loader.BindAsset(asset);
        loaderCache.Add(path, loader);
        callback(asset);
    }