Пример #1
0
    /// <summary>
    /// 真正异步加载部分重写
    /// </summary>
    /// <returns></returns>
    protected override IEnumerator asyncLoadReal()
    {
        if (state == ResLoadingState.LOADSTATE_UNLOADED)
        {
            state = ResLoadingState.LOADSTATE_LOADING;
            var req = asyncLoadAb(name);
            if (req == null)
            {
                yield break;
            }
            yield return(req);

            bundle   = req.assetBundle;
            refCount = 0;
            #region 异步加载贴图等资源,设置模型参数
            if (bundle != null)
            {
                //异步加载bundle里的资源
                asset = bundle.LoadAsset <GameObject>(effectName);
                if (asset == null)
                {
                    state = ResLoadingState.LOADSTATE_UNLOADED;
                    yield break;
                }

                //针对设备性能,设置特效参数,删除一些配置 判断当前特效等级。如果中低特效,需要删除对应的对象,再加载对应的图片资源
                //TODO....

                state = ResLoadingState.LOADSTATE_LOADING;
#if UNITY_EDITOR
                EditorHelper.SetEditorShader(asset);
#endif
                //异步加载模型贴图资源
                var refholder = asset.AddComponent <InastanceAssetRefHolder>();
                refholder.resType   = ResourceType.Effect;
                refholder.assetName = effectName;
                matHolder           = asset.GetComponent <PrefabMaterialHolder>();
                if (matHolder != null)
                {
                    yield return(matHolder.AsyncLoadMatsTex());
                }
            }
            #endregion
            if (onCmp != null)
            {
                onCmp.Call(this);
            }
            state = ResLoadingState.LOADSTATE_LOADED;
        }
        else
        {
            if (onCmp != null)
            {
                onCmp.Call(this);
            }
        }
    }
Пример #2
0
    /// <summary>
    /// 真正异步加载部分重写
    /// </summary>
    /// <returns></returns>
    protected override IEnumerator asyncLoadReal()
    {
        if (state == ResLoadingState.LOADSTATE_UNLOADED)
        {
            state = ResLoadingState.LOADSTATE_LOADING;
            var req = asyncLoadAb(name);
            if (req == null)
            {
                if (onCmp != null)
                {
                    onCmp.Clear();
                }
                Logger.err("async load bundle error:" + name);
                state = ResLoadingState.LOADSTATE_UNLOADED;
                yield break;
            }
            yield return(req);

            bundle   = req.assetBundle;
            refCount = 0;
            #region 异步加载贴图等资源,设置模型参数
            if (bundle != null)
            {
                //异步加载bundle里的资源
                var assetReq = bundle.LoadAssetAsync <GameObject>(modelName);
                yield return(assetReq);

                asset = assetReq.asset as GameObject;
                if (asset == null)
                {
                    state = ResLoadingState.LOADSTATE_UNLOADED;
                    yield break;
                }
                state = ResLoadingState.LOADSTATE_LOADING;
#if UNITY_EDITOR
                EditorHelper.SetEditorShader(asset);
#endif
                //异步加载模型贴图资源
                var refholder = asset.AddComponent <InastanceAssetRefHolder>();
                refholder.resType   = ResourceType.Model;
                refholder.assetName = modelName;
                matHolder           = asset.GetComponent <PrefabMaterialHolder>();
                if (matHolder != null)
                {
                    yield return(matHolder.AsyncLoadMatsTex());
                }

                //异步加载动作clip资源
                clipHolder = asset.GetComponent <AnimationHolder>();
                if (clipHolder != null)
                {
                    yield return(clipHolder.AsyncLoadClips());
                }

                #endregion
                if (onCmp != null)
                {
                    onCmp.Call(this);
                }
                state = ResLoadingState.LOADSTATE_LOADED;
            }
            else
            {
                if (onCmp != null)
                {
                    onCmp.Clear();
                }
                Logger.err("async load bundle error:" + name);
                state = ResLoadingState.LOADSTATE_UNLOADED;
            }
        }
        else
        {
            if (onCmp != null)
            {
                onCmp.Call(this);
            }
        }
    }