Esempio n. 1
0
    public override T LoadAsset <T>(string path)
    {
        //已加载过
        if (AssetDic.ContainsKey(path))
        {
            AssetDic[path].Retain();
            return(AssetDic[path].obj as T);
        }
        string abName = GetAbName(path);

        if (!IsLoadBundle(abName))
        {
            //依赖
            LoadAssetBundleDepends(abName);
            BundleInfo.CreateInfo(abName, LoadAssetBundle(abName));
        }
        else
        {
            bundleDic[abName].Retain();
        }
        T t = null;

        if (bundleDic[abName].bundle != null)
        {
            t = bundleDic[abName].bundle.LoadAsset <T>(path);
        }
        AssetInfo.CreateInfo(path, t);
        return(t);
    }
Esempio n. 2
0
    public override T LoadAsset <T>(string path)
    {
        if (IsLoadAsset(path))
        {
            AssetDic[path].Retain();
            return(AssetInfo.GetRes <T>(path));
        }
        T t = Resources.Load <T>(GetResourceLoadPath(path));

        AssetInfo.CreateInfo(path, t);
        return(t);
    }
Esempio n. 3
0
    IEnumerator LoadAssetCoroutineHelper <T>(string path) where T : Object
    {
        if (IsLoadAsset(path))
        {
            AssetDic[path].Retain();
            yield break;
        }
        T t = AssetDatabase.LoadAssetAtPath <T>(path);

        AssetInfo.CreateInfo(path, t);
        yield return(null);
    }
Esempio n. 4
0
    public override T LoadAsset <T>(string path)
    {
        if (IsLoadAsset(path))
        {
            AssetDic[path].Retain();
            return(AssetInfo.GetRes <T>(path));
        }
        T t = AssetDatabase.LoadAssetAtPath <T>(path);

        AssetInfo.CreateInfo(path, t);
        return(t);
    }
Esempio n. 5
0
    IEnumerator LoadAssetCoroutineHelper <T>(string path) where T : Object
    {
        if (IsLoadAsset(path))
        {
            if (prepareLoadDic.ContainsKey(path))
            {
                while (prepareLoadDic.ContainsKey(path))
                {
                    //Debug.Log("while(AssetDic[path].obj == null)");
                    yield return(null);
                }
                if (AssetDic.ContainsKey(path))
                {
                    AssetDic[path].Retain();
                    yield break;
                }
                //这里有个极特殊情况,最开始没考虑到,同时异步加载两个资源时,目前的写法是加载第二个资源时进行等待
                //但是有可能第一个资源加载完之后立刻卸载了,导致第二个资源等待完之后全都没了,所以需要触发重新加载
                else
                {
                    yield return(LoadAssetCoroutineHelper <T>(path));
                }
            }
            else
            {
                AssetDic[path].Retain();
                yield break;
            }
            //AssetDic[path].Retain();
            //yield break;
        }
        AddPrepareLoadDic(path);
        AssetInfo.CreateInfo(path, null);
        var request = Resources.LoadAsync <T>(GetResourceLoadPath(path));

        yield return(request);

        AssetInfo.SetObject(path, request.asset);
        //移除加载中列表
        RemovePrepareLoadDic(path);
        //在异步加载时进来一个卸载,都加载完后在这里统一删除
        if (unLoadCacheDic.ContainsKey(path))
        {
            RemoveUnLoadCacheDic(path);
        }
    }
Esempio n. 6
0
    IEnumerator LoadAssetCoroutineHelper <T>(string path) where T : Object
    {
        //Debug.Log("LoadAssetCoroutineHelper begin");
        if (IsLoadAsset(path))
        {
            //如果重复对同样的资源进行异步加载,需要等待
            if (prepareLoadDic.ContainsKey(path))
            {
                while (prepareLoadDic.ContainsKey(path))
                {
                    yield return(null);
                }
                if (AssetDic.ContainsKey(path))
                {
                    AssetDic[path].Retain();
                    yield break;
                }
                //这里有个极特殊情况,最开始没考虑到,同时异步加载两个资源时,目前的写法是加载第二个资源时进行等待
                //但是有可能第一个资源加载完之后立刻卸载了,导致第二个资源等待完之后全都没了,所以需要触发重新加载
                else
                {
                    yield return(LoadAssetCoroutineHelper <T>(path));
                }
            }
            else
            {
                AssetDic[path].Retain();
                yield break;
            }
        }
        AddPrepareLoadDic(path);
        //先添加进容器
        AssetInfo.CreateInfo(path, null);
        string abName = GetAbName(path);

        if (!IsLoadBundle(abName))
        {
            //先添加进容器,防止重复调用
            BundleInfo.CreateInfo(abName, null);
            yield return(LoadAssetBundleDependsAsync(abName));

            //Debug.Log("LoadAssetCoroutineHelper abName=" + abName);
            var bundleRequest = AssetBundle.LoadFromFileAsync(GetLoadPath(abName));
            yield return(bundleRequest);

            bundleDic[abName].bundle = bundleRequest.assetBundle;
        }
        else
        {
            //Debug.Log("LoadAssetCoroutineHelper IsLoadAbName=" + abName);
            bundleDic[abName].Retain();
        }
        AssetBundle bundle = bundleDic[abName].bundle;
        //Debug.Log("LoadAssetCoroutineHelper path=" + path);
        AssetBundleRequest request = bundle.LoadAssetAsync <T>(path);

        yield return(request);

        AssetInfo.SetObject(path, request.asset);
        //Debug.Log("LoadAssetCoroutineHelper over");
        //移除加载中列表
        RemovePrepareLoadDic(path);
        //在异步加载时进来一个卸载,都加载完后在这里统一删除
        if (unLoadCacheDic.ContainsKey(path))
        {
            Debug.Log("unLoadCacheDic=" + path);
            RemoveUnLoadCacheDic(path);
            UnLoadAsset(path);
        }
    }