Пример #1
0
    private void loadAsset <T>(string resPath, LoadCb loadCallBack, ResEnum resEnum, bool isAsync = true) where T : UnityEngine.Object
    {
        if (loadedCacheDict.ContainsKey(resPath))
        {
            if (loadCallBack != null)
            {
                addResRef(resPath);
                loadCallBack(loadedCacheDict[resPath], resPath);
            }
            return;
        }

        if (waitLoadInfoDict.ContainsKey(resPath))
        {
            waitLoadInfoDict[resPath].LoadFinishCb.Insert(0, loadCallBack);
            return;
        }

        ResLoadInfo loadInfo = this.resLoadInfoPool.GetItem();

        loadInfo.ResPath = resPath;
        loadInfo.LoadFinishCb.Insert(0, loadCallBack);

        waitLoadInfoDict[resPath] = loadInfo;

        if (isAsync)
        {
            AssetLoader.Instance.LoadAssetAsync <T>(resPath, loadFinishCallBack);
        }
        else
        {
            AssetLoader.Instance.LoadAsset <T>(resPath, loadFinishCallBack);
        }
    }
Пример #2
0
//        public override T LoadObject<T>(string path, bool blUnLoad = false)
//        {
//            string resPath = ResPath + path;
//            string r = Directory.GetCurrentDirectory() + "/" + resPath;
//            if (System.IO.File.Exists(r))
//            {
//#if UNITY_EDITOR
//                return AssetDatabase.LoadAssetAtPath<T>(resPath);
//#else
//                 return (T)Resources.Load(parsePrefabPath(path));
//#endif

//            }
//            else
//            {
//                return (T)Resources.Load(parsePrefabPath(path));
//            }

//        }


        public override void LoadObjectWWW(string resPath, ResLoadInfo.callback fn = null, object fnPara = null)
        {
            string path = ResPath + resPath;
            string r    = Directory.GetCurrentDirectory() + "/" + path;

            if (System.IO.File.Exists(r))
            {
                #if UNITY_EDITOR
                ResLoadInfo rli = new ResLoadInfo();
                rli.goEditor = AssetDatabase.LoadAssetAtPath <Object>(path);
                rli.success  = true;
                fn(rli, fnPara);
#endif
                return;
            }
            else
            {
                // Debug.Log("LoadObjectWWW no file: " + resPath);
                ResLoadInfo rli = new ResLoadInfo();
                rli.goEditor = Resources.Load(parsePrefabPath(path));
                rli.success  = false;
                fn(rli, fnPara);
            }

            //string originalFullPath = "Assets/Resources_Bundle/" + resPath;
            //string parseCommonPath = "Assets/Resources_Bundle/" + parseCommonAsset(resPath);
            //string md5Str = HashUtils.MD5(parseCommonPath) + ".ab";
            //string assetResPath = Application.streamingAssetsPath + "/res/" + md5Str;

            //if (System.IO.File.Exists(assetResPath))
            //{
            //    string[] dps = mainfest.GetAllDependencies(md5Str);

            //    string[] resPaths = new string[dps.Length + 1];
            //    if (dps != null && dps.Length > 0)
            //    {
            //        for (int i = 0; i < dps.Length; i++)
            //        {
            //            resPaths[i] = ResPathWWW + dps[i];
            //        }
            //    }
            //    resPaths[resPaths.Length - 1] = ResPathWWW + md5Str;// assetResPath;
            //    ResLoadInfo res = new ResLoadInfo();
            //    res.start(Path.GetFileNameWithoutExtension(resPath), resPaths, fn, fnPara);
            //}
            //else
            //{
            //}
        }
Пример #3
0
        public virtual void LoadObjectWWW(string resPath, ResLoadInfo.callback fn = null, object fnPara = null)
        {
            string originalFullPath = "Assets/Resources_Bundle/" + resPath;
            string parseCommonPath  = "Assets/Resources_Bundle/" + parseCommonAsset(resPath);
            string md5Str           = HashUtils.MD5(parseCommonPath) + ".ab";
            string assetResPath     = ResPath + md5Str;

            if (directoryResLoadInfo.ContainsKey(ResPathWWW + md5Str))
            {
                ResLoadInfo rli = directoryResLoadInfo[ResPathWWW + md5Str];
                if (rli.success)
                {
                    rli.currentPrefabName = Path.GetFileNameWithoutExtension(resPath);
                    fn(rli, fnPara);
                }
                else
                {
                    rli.append(Path.GetFileNameWithoutExtension(resPath), fn, fnPara);
                }
                return;
            }
            if (true)//System.IO.File.Exists(assetResPath)
            {
                // Log.Info("LoadObjectWWW :" + Path.GetFileNameWithoutExtension(resPath)+ " " + assetResPath);
                string[] dps = mainfest.GetAllDependencies(md5Str);

                string[] resPaths = new string[dps.Length + 1];
                if (dps != null && dps.Length > 0)
                {
                    for (int i = 0; i < dps.Length; i++)
                    {
                        resPaths[i] = ResPathWWW + dps[i];
                    }
                }
                resPaths[resPaths.Length - 1] = ResPathWWW + md5Str;// assetResPath;
                ResLoadInfo res = new ResLoadInfo();
                res.isCache = parseCommonAssetCache(resPath);
                directoryResLoadInfo.Add(ResPathWWW + md5Str, res);
                res.start(Path.GetFileNameWithoutExtension(resPath), resPaths, fn, fnPara, resPath);
            }
            else
            {
                //Log.Error("LoadObjectWWW: " + parseCommonPath + "  " + md5Str + " not find file!");
                ResLoadInfo res = new ResLoadInfo();
                fn(res, null);
            }
        }
Пример #4
0
        /// <summary>
        /// 加载依赖文件(暂时借用回调)
        /// </summary>
        public virtual void buildMainFest(ExtractCallback ecb)
        {
            //#if UNITY_EDITOR
            //ecb(1, 1);
            //#else
            ResLoadInfo resLoadInfo = new ResLoadInfo();

            string[] ss = new string[1];
            ss[0] = ResPathWWW + "res";
            Debug.Log("Extract" + ss[0]);
            resLoadInfo.start("AssetBundleManifest", ss, (ResLoadInfo res, object param) =>
            {
                mainfest = res.LoadAsset <AssetBundleManifest>();
                //Log.Info(mainfest == null ? "mainfest加载失败" : "mainfest加载成功");
                ecb(1, 1);
            });
        }
Пример #5
0
    private void loadFinishCallBack(UnityEngine.Object obj, string resPath)
    {
        if (waitLoadInfoDict.ContainsKey(resPath))
        {
            loadedCacheDict[resPath] = obj;

            ResLoadInfo info = waitLoadInfoDict[resPath];

            addResRef(resPath);

            if (info != null)
            {
                info.CallLoadCb(obj);
                resLoadInfoPool.ReturnItem(info);
            }

            resLoadInfoPool.ReturnItem(waitLoadInfoDict[resPath]);
            waitLoadInfoDict.Remove(resPath);
        }
    }
Пример #6
0
        public static ResInfo Create(ResLoadInfo resLoadInfo)
        {
            switch (resLoadInfo.mResFromType)
            {
            case ResFromType.ResourcesRes:
                return(ResourcesRes.Allocate(resLoadInfo));

            case ResFromType.NetImageRes:
                return(NetImageRes.Allocate(resLoadInfo));

            case ResFromType.ABRes:
                if (ABDataHolder.Instance.GetABResLoadFrom() == ABResLoadFrom.EditorRes)
#if UNITY_EDITOR
                { return(EditorRes.Allocate(resLoadInfo)); }
#else
                { return(null); }
#endif
                else
                {
                    return(ABRes.Allocate(resLoadInfo));
                }
Пример #7
0
    IEnumerator Load(ResLoadInfo info)
    {
        string pathUrl = "";
        object obj     = null;

        switch (info.m_type)
        {
        case ResourceType.Resource:
            pathUrl += info.resName;
            Logger.Debug(pathUrl);
            ResourceRequest resReq = Resources.LoadAsync(pathUrl);
            yield return(resReq);

            if (resReq.isDone)
            {
                if (resReq.asset != null)
                {
                    obj = UnityEngine.Object.Instantiate(resReq.asset);
                    yield return(obj);

                    info.obj      = obj;
                    info.m_isLoad = true;
                }
            }
            break;

        case ResourceType.AssetBundle: pathUrl += info.resName;
            WWW www = new WWW(pathUrl);
            yield return(www);

            info.m_bundle = www.assetBundle;
            obj           = UnityEngine.Object.Instantiate(info.m_bundle);
            yield return(obj); info.obj = obj;
            info.m_isLoad = true;
            break;
        }
    }
Пример #8
0
    IEnumerator Load(ResLoadInfo info)
    {
        string pathUrl = "";
        WWW    www;

        switch (info.m_type)
        {
        case ResourceType.Resource: pathUrl += info.resName;
            ResourceRequest resReq = Resources.LoadAsync(pathUrl);
            yield return(resReq);

            GameObject go = Instantiate(resReq.asset) as GameObject;
            break;

        case ResourceType.AssetBundle: pathUrl += info.resName; break;
        }

        //yield return www;
        //if (info.OnLoad != null)
        //{
        //    info.OnLoad();
        //}
        //isLoading = false;
    }