コード例 #1
0
ファイル: AssetLoader.cs プロジェクト: Liangzg/GEX_1.X
    /// <summary>
    /// 异步加载资源
    /// </summary>
    /// <param name="path">资源的相对路径,相对于Assets的根目录 eg: CustomRes/XXX.prefab</param>
    /// <param name="assetType">其它的基础数据类型</param>
    /// <param name="callback">加载完成时的回调</param>
    /// <returns></returns>
    public IEnumerator AsyncLoadAtPath(string path, EAssetBaseType assetType, Action <object> callback)
    {
        string finalPath = AppPathUtils.IsSeachExist(path, true);
        WWW    _www      = new WWW(finalPath);

        yield return(_www);

        if (_www.error != null)
        {
            Debugger.LogError(_www.error + " , path -->> " + finalPath);
            callback(null);
            yield break;
        }

        object obj = null;

        if (assetType == EAssetBaseType.Text)
        {
            obj = _www.text;
        }
        else if (assetType == EAssetBaseType.ByteArray)
        {
            obj = _www.bytes;
        }
        else if (assetType == EAssetBaseType.Texture2D)
        {
            obj = _www.texture;
        }
        if (callback != null)
        {
            callback(obj);
        }
    }
コード例 #2
0
ファイル: AssetLoader.cs プロジェクト: Liangzg/GEX_1.X
    /// <summary>
    /// 异步加载资源
    /// </summary>
    /// <param name="bundName">未加密的Bundle文件名</param>
    /// <param name="callback">加载完成时的回调</param>
    public IEnumerator AsyncLoadBundleAtPath(string bundName, Action <AssetBundle> callback, Action <float, float> progress)
    {
        string finalPath = AppPathUtils.IsSeachExist(GetBundleEncrypeName(bundName), true);
        WWW    _www      = new WWW(finalPath);

        if (progress == null)
        {
            yield return(_www);
        }
        else
        {
            int totalProgress = 0, curTotalProgress;
            int offset = 0;
            while (!_www.isDone)
            {
                curTotalProgress = (int)(_www.progress * 100);
                offset           = curTotalProgress - totalProgress;
                totalProgress    = curTotalProgress;
                progress.Invoke(offset, totalProgress);
                yield return(null);
            }

            curTotalProgress = totalProgress == 0 ? (int)(_www.progress * 100) : totalProgress;
            offset           = 100 - curTotalProgress;
            totalProgress    = 100;
            progress.Invoke(offset, totalProgress);
            while (curTotalProgress < totalProgress)
            {
                curTotalProgress++;
                yield return(null);
            }

            yield return(null);
        }
        if (_www.error != null)
        {
            Debugger.LogError(_www.error + " , path -->> " + finalPath);
            callback(null);
            yield break;
        }

        if (callback != null)
        {
            callback(_www.assetBundle);
        }
    }