Example #1
0
    // 加载mesh动画文件
    //Modify by Aoicocoon 2017/12/06
    //修改打包士兵数据+动画文件
    public override void LoadSoldierAnim(string meshName, string animName, bool IsCache, AssetLoadHook pfun)
    {
        if (null == pfun)
        {
            return;
        }

        string folder = ResourcesPath.GetRelativePath(ResourcesType.ActorSoldierMesh, ResourcesPathMode.AssetBundle);
        string key    = GetKey(folder, meshName + "/" + animName.ToLower());
        string path   = key + ConstantData.ABEXT;

        Object obj = FindAssetObj(key);

        if (null != obj)
        {
            pfun.Invoke(obj);
        }
        else
        {
            ABLoad.LoadAB(path, true,
                          (ab) =>
            {
                LoadQueue.AddLoadTask(path, animName, typeof(Texture2D), IsCache, IsCache, false, pfun);
            });
        }
    }
Example #2
0
    /// <summary>
    /// 以同步的方式加载资源
    /// </summary>
    /// <param name="resType"></param>
    /// <param name="abName"></param>
    /// <param name="objName"></param>
    /// <param name="type"></param>
    /// <param name="isCache"></param>
    /// <param name="isCacheAb"></param>
    /// <param name="isFreeUnUseAbRes"></param>
    /// <returns></returns>
    private Object LoadObjSync(string resType, string abName, string objName, Type type, bool isCache, bool isCacheAb, bool isFreeUnUseAbRes)
    {
        string relativePath = ABLoad.GetRelativePath(resType, abName);
        string key          = GetKey(relativePath, objName);
        Object obj          = FindAssetObj(key);

        if (obj != null)
        {
            return(obj);
        }

        AssetBundle assetBundle = ABLoad.LoadAbSync(relativePath, isCacheAb);

        if (assetBundle == null)
        {
            return(null);
        }

        obj = LoadObjByAb(assetBundle, objName, type, isCacheAb, isFreeUnUseAbRes);
        if (isCache == true && obj != null)
        {
            AddCache(key, obj);
        }

        return(obj);
    }
Example #3
0
    public static ABData GetObject(string url, string resname, System.Type type)
    {
        ABLoad load = mUti.mFactory.Get(url, version);

        if (load == null)
        {
            return(null);
        }

        if (load.Error())
        {
            return(null);
        }

        Object o = load.GetObject(resname, type, ShowParticleSys);

        if (o == null)
        {
            return(null);
        }

        if (null == type)
        {
            return(null);
        }

        ABData data = new ABData(url, resname, type, load);

        datas.Add(data);

        return(data);
    }
Example #4
0
 //   清理资源
 public static void Clear()
 {
     if (g_AssetLoad != null)
     {
         g_AssetLoad.Clear();
     }
     ABLoad.Clear();
 }
Example #5
0
    /// <summary>
    /// 获取指定wwwurl的对象资源
    /// </summary>
    /// <param name="url">用于www加载的路径</param>
    /// <param name="resname">包内的资源名</param>
    /// <param name="type">包内资源名的加载类型</param>
    /// <param name="abtype">加载的路径是MPQ里的还是本地文件的</param>
    /// <returns></returns>
    public static bool GetAB(string url, string resname, System.Type type, ABDataType abtype = ABDataType.Mpq)
    {
        //  如果是声音,强制变成Normal.
        if (typeof(AudioClip) == type)
        {
            abtype = ABDataType.Normal;
        }

        ABLoad mAB = null;

        //Debuger.Log("GetAB " + url);

        do
        {
            //  获取已有
            mAB = mUti.mFactory.Get(url, version);

            //Debuger.Log("mAB " + mAB);

            if (mAB == null)
            {
                break;
            }

            //  获取资源对象
            Object res = mAB.GetObject(resname, type, ShowParticleSys);

            //Debuger.Log("res " + res);

            if (res == null)
            {
                break;
            }

            //  返回
            if (OnFinishLoading != null)
            {
                //Debuger.Log("AssetBundleUti.OnFinishLoading " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString());

                OnFinishLoading(url, resname, type, true);
            }

            return(true);
        } while (true);

        if (mAB == null)
        {
            mAB = mUti.mFactory.Add(url, version, abtype);
        }

        mUti.StartCoroutine(mUti.CallBackSync(mAB, url, resname, type, abtype));

        return(true);
    }
Example #6
0
    private void releaseAllBundles()
    {
        while (releaseQueue.Count > 0)
        {
            ABLoad loader = releaseQueue.Dequeue();

            if (loader != null)
            {
                loader.Release();
            }
        }
    }
Example #7
0
    // 加载配置文件
    public override Object LoadConfig(string name)
    {
        Object data = null;

        string      path = ABLoad.GetRelativePath(ResourcesType.Config, "config");
        AssetBundle ab   = ABLoad.LoadAbSync(path, true);

        if (ab != null)
        {
            data = ab.LoadAsset <Object>(name);
        }

        return(data);
    }
Example #8
0
    public ABData(string url, string resname, System.Type type, ABLoad load)
    {
        mLoad    = load;
        mUrl     = url;
        mResname = resname;
        mType    = type;

        Create();

        mRef++;
        mReferenceList.Add(this);

        mCount    = 0;
        mProgress = 1;
    }
 /// <summary>
 /// 开始任务
 /// </summary>
 public void StartTask()
 {
     m_IsRun = true;
     ResourceManger.AsyncGo.StartCoroutine(ABLoad.LoadABasync(m_ABRelativePath, m_IsCacheAB,
                                                              (ab) =>
     {
         AssetLoadRun run = ResourceManger.gAssetLoad as AssetLoadRun;
         ResourceManger.AsyncGo.StartCoroutine(run.LoadObjAsync(ab, m_ObjName, m_type, m_IsCacheAB, m_IsFreeUnUseABRes,
                                                                (g) =>
         {
             run.LoadAssetCallBack(g, m_ABRelativePath + m_ObjName, m_IsCacheAsset, m_fun);
             FinishTask();
         }));
     }));
 }
Example #10
0
    // 加载lua
    public override byte[] LoadLua(string luaName, bool IsCache)
    {
        byte[] bytes = null;

        string      path = ABLoad.GetRelativePath(ResourcesType.luaData, "lua");
        AssetBundle ab   = ABLoad.LoadAbSync(path, true);

        if (ab != null)
        {
            TextAsset asset = ab.LoadAsset <TextAsset>(luaName);
            if (asset != null)
            {
                bytes = asset.bytes;
            }
        }

        return(bytes);
    }
Example #11
0
    // 加载lua
    public override byte[] LoadLua(string luaName, bool IsCache)
    {
        string key = GetKey(ResourcesType.luaData, luaName, luaName);

        byte[] AB = FindBytes(key);
        if (AB != null)
        {
            return(AB);
        }
        else
        {
            string path = ABLoad.GetRelativePath(ResourcesType.luaData, luaName);
            AB = ABLoad.Loadbytes(path);
            if (AB != null && IsCache == true)
            {
                AddBytesCache(key, AB);
            }
            return(AB);
        }
    }
Example #12
0
    // 加载asset接口
    private void LoadObj(string ResType,
                         string ABName,
                         string ObjName,
                         Type type,
                         bool IsCacheAsset,
                         bool IsCacheAB,
                         bool IsFreeUnUseABRes,
                         bool async,
                         AssetLoadHook pfun)
    {
        string RelativePath = ABLoad.GetRelativePath(ResType, ABName);
        string key          = GetKey(RelativePath, ObjName);

        UnityEngine.Object obj = FindAssetObj(key);
        if (obj != null)
        {
            if (pfun != null)
            {
                pfun(obj);
            }
        }
        else
        {
            if (async == false)
            {
                ABLoad.LoadAB(RelativePath, IsCacheAB,
                              (ab) => {
                    Object g = LoadObjByAb(ab, ObjName, type, IsCacheAB, IsFreeUnUseABRes);
                    LoadAssetCallBack(g, key, IsCacheAsset, pfun);
                });
            }
            else
            {
                // 异步加载队列
                LoadQueue.AddLoadTask(RelativePath, ObjName, type, IsCacheAsset, IsCacheAB, IsFreeUnUseABRes, pfun);
            }
        }
    }
Example #13
0
    IEnumerator LoadSceneAsync(string sceneName, SceneLoadHook pfun)
    {
        string abPath = ABLoad.GetAssetBundlePath(ABLoad.GetRelativePath(ResourcesType.Scene, sceneName).ToLower());
        AssetBundleCreateRequest requestAB = AssetBundle.LoadFromFileAsync(abPath);

        while (requestAB.progress < 1)
        {
            if (pfun != null)
            {
                pfun(requestAB.progress * 0.5f);
            }

            yield return(s_WaitForEndOfFrame);
        }

        AsyncOperation requestScene = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName);

        while (requestScene.progress < 1)
        {
            if (pfun != null)
            {
                pfun(0.5f + requestScene.progress * 0.5f);
            }

            yield return(s_WaitForEndOfFrame);
        }

        if (requestAB.assetBundle != null)
        {
            requestAB.assetBundle.Unload(false);
        }

        if (pfun != null)
        {
            pfun(1f);
        }
    }
Example #14
0
    public virtual void Destory()
    {
        if (mLoad != null)
        {
            mLoad = null;
        }
        if (_ABLoadGoMono != null)
        {
            _ABLoadGoMono.Clear();
            GameObject.DestroyImmediate(_ABLoadGoMono);
            _ABLoadGoMono = null;
        }

        if (_gameobject != null)
        {
            _gameobject.SetActive(false);
            GameObject.DestroyImmediate(_gameobject);
            _gameobject = null;
        }
        _gameobject = null;
        _audioclip  = null;
        _mat        = null;
        _texture2d  = null;
    }
Example #15
0
    // 获取key 的接口
    private string GetKey(string ResType, string ABName, string ObjName)
    {
        string RelativePath = ABLoad.GetRelativePath(ResType, ABName);

        return(GetKey(RelativePath, ObjName));
    }
Example #16
0
 // 初始化资源模块
 public static void InitCache()
 {
     ABLoad.Init();
     g_AssetLoad.Init();
 }
Example #17
0
    public IEnumerator CallBackSync(ABLoad mAB, string url, string resname, System.Type type, ABDataType abtype)
    {
        //Debuger.Log("AssetBundleUti.CallBack " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString());

        Count++;

        callbackerror = string.Empty;
        bCallback     = true;

        do
        {
            if (!mAB.Create(url))
            {
                callbackerror = "ABLoad Create Error " + url;
                bCallback     = false;

                break;
            }

            yield return(StartCoroutine(mAB.Waiting()));

            //Debuger.Log("Waiting End ");

            while (true)
            {
                if (mAB.IsWWW())
                {
                    break;
                }

                yield return(null);
            }

            //Debuger.Log("Error " + mAB.Error());

            if (mAB.Error())
            {
                Debuger.LogError(mAB.GetErrorMsg());
                callbackerror = mAB.GetErrorMsg();
                bCallback     = false;

                break;
            }
            else
            {
                if (typeof(AudioClip) == type)
                {
                    AudioClip ac = mAB.Load(resname);

                    //Debuger.Log(resname + " " + ac.length + " " + ac.samples + " " + ac.isReadyToPlay + " " + ac.channels);
                    //Debuger.Log(ac.isReadyToPlay);

                    if (ac != null)
                    {
                        while (true)
                        {
                            if (ac.isReadyToPlay)
                            {
                                break;
                            }

                            yield return(null);
                        }

                        ac.name = resname;
                        mAB.Pair(resname, ac, type);

                        //  返回
                        if (OnFinishLoading != null)
                        {
                            //Debuger.Log("AssetBundleUti.OnFinishLoading " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString());

                            OnFinishLoading(url, resname, type, true);
                        }
                    }
                    else
                    {
                        //Debuger.LogError("Load " + resname + " in " + url);

                        callbackerror = mAB.GetErrorMsg();
                        bCallback     = false;

                        break;
                    }
                }
                else
                {
                    AssetBundle ab = mAB.GetAb();
                    if (ab == null)
                    {
                        callbackerror = "AssetBundle == null";
                        bCallback     = false;

                        break;
                    }

                    AssetBundleRequest request = ab.LoadAssetAsync(resname, type);
                    if (request == null)
                    {
                        callbackerror = "LoadAsync AssetBundleRequest == null";
                        bCallback     = false;

                        break;
                    }

                    while (true)
                    {
                        if (request.isDone)
                        {
                            break;
                        }

                        yield return(null);
                    }

                    mAB.Pair(resname, request.asset, type);

                    //  返回
                    if (OnFinishLoading == null)
                    {
                        //Debuger.Log("AssetBundleUti.OnFinishLoading " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString());
                        callbackerror = "OnFinishLoading == null";
                        bCallback     = false;

                        break;
                    }

                    OnFinishLoading(url, resname, type, true);
                }
            }
        }while (false);

        if (!bCallback)
        {
            Debuger.LogError("Error " + mAB.Error() + " callbackerror: " + callbackerror);

            MessageBox(callbackerror + " \r\n " + OnFinishLoading.ToString());

            OnFinishLoading(url, resname, type, false, callbackerror);

            if (mAB != null)
            {
                mAB.Dispose();
                mAB = null;
            }
        }
        else
        {
            releaseQueue.Enqueue(mAB);
        }

        Count--;

        if (Count <= 0)
        {
            Count = 0;
            releaseAllBundles();
        }
    }
Example #18
0
 public static void LoadDependeAB(string dir, string ABName)
 {
     ABLoad.LoadABbyPath(dir, ABName, true);
 }