コード例 #1
0
ファイル: ResourcesLoader.cs プロジェクト: jasonyuji/hugula
        /// <summary>
        /// 加载场景
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="sceneName"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        /// <param name="allowSceneActivation"></param>
        /// <param name="loadSceneMode"></param>
        /// <returns></returns>
        static public void LoadScene(string abName, string sceneName, System.Action <object, object> onComplete, System.Action <object, object> onEnd, object userData = null, bool allowSceneActivation = true, LoadSceneMode loadSceneMode = LoadSceneMode.Additive)
        {
            var req = CRequest.Get();

            req.assetName       = sceneName;
            req.assetType       = LoaderType.Typeof_ABScene;
            req.assetBundleName = abName;
            req.OnComplete      = onComplete;
            req.OnEnd           = onEnd;
            req.userData        = userData;

            AsyncOperation request = null;

            if ((request = CacheManager.GetLoadingScene(sceneName)) != null)
            {
                request.allowSceneActivation = allowSceneActivation; //开始激活
                UnityEngine.Events.UnityAction <Scene, LoadSceneMode> onSceneLoaded = null;
                onSceneLoaded = (scene, model) =>
                {
                    SceneManager.sceneLoaded -= onSceneLoaded;
                    CacheManager.RemoveLoadingScene(req.assetName);
                    DispatchReqAssetOperation(req, false, 0, true);
                    CheckAllComplete();
                };

                SceneManager.sceneLoaded += onSceneLoaded;
            }
            else
            {
                LoadSceneAsset(req, allowSceneActivation, loadSceneMode);
            }
        }
コード例 #2
0
        /// <summary>
        ///  以 WWW 方式加载网络非ab资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="head"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        static public HttpLoadOperation WWWRequestCoroutine(string url, object head, System.Type type)
        {
            var req = CRequest.Get();

            req.relativeUrl = url;
            req.head        = head;
            req.assetType   = type;
            return(WWWRequest(req, true));
        }
コード例 #3
0
        /// <summary>
        /// 以 Coroutine方式加载ab资源
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <param name="type"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        static public AssetBundleLoadAssetOperation LoadAssetCoroutine(string abName, string assetName, System.Type type, int priority = 0)
        {
            var req = CRequest.Get();

            req.priority    = priority;
            req.assetName   = assetName;
            req.assetType   = type;
            req.relativeUrl = abName;
            return(LoadAsset(req, true));
        }
コード例 #4
0
        /// <summary>
        /// 以 WWW 方式加载网络非ab资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="head"></param>
        /// <param name="type"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        static public void WWWRequest(string url, object head, System.Type type, System.Action <CRequest> onComplete, System.Action <CRequest> onEnd)
        {
            var req = CRequest.Get();

            req.relativeUrl = url;
            req.head        = head;
            req.assetType   = type;
            req.OnComplete  = onComplete;
            req.OnEnd       = onEnd;
            WWWRequest(req);
        }
コード例 #5
0
ファイル: ResourcesLoader.cs プロジェクト: luankun/hugula
        static public void HttpWebRequest(string url, object uploadData, System.Type type, System.Action <CRequest> onComplete, System.Action <CRequest> onEnd)
        {
            var req = CRequest.Get();

            req.vUrl       = url;
            req.uploadData = uploadData;
            req.assetType  = type;
            req.OnComplete = onComplete;
            req.OnEnd      = onEnd;
            LoadWebHttpInternal(req);
        }
コード例 #6
0
ファイル: ResourcesLoader.cs プロジェクト: xubingyue/hugula
        /// <summary>
        /// 以 WWW 方式加载网络非ab资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="head"></param>
        /// <param name="type"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        static public void HttpWebRequest(string url, WebHeaderCollection head, System.Type type, System.Action <CRequest> onComplete, System.Action <CRequest> onEnd)
        {
            var req = CRequest.Get();

            req.vUrl       = url;
            req.head       = head;
            req.assetType  = type;
            req.OnComplete = onComplete;
            req.OnEnd      = onEnd;
            HttpWebRequest(req);
        }
コード例 #7
0
ファイル: ResourcesLoader.cs プロジェクト: GouDanYuan/hugula
        /// <summary>
        /// 以 回调方式加载 sub资源
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <param name="type"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        /// <param name="priority"></param>
        /// <returns >返回标识id可以取消完成后的complete回调</returns>
        static public int LoadAssetWithSubAssetsAsync(string abName, string assetName, System.Type type, System.Action <object, object> onComplete, System.Action <object, object> onEnd)
        {
            var req = CRequest.Get();

            req.assetName       = assetName;
            req.assetType       = type;
            req.assetBundleName = abName;
            req.OnComplete      = onComplete;
            req.OnEnd           = onEnd;
            return(LoadAsset(req, true, true));
        }
コード例 #8
0
ファイル: ResourcesLoader.cs プロジェクト: luankun/hugula
        /// <summary>
        /// 以 回调方式加载 ab资源
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <param name="type"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        /// <param name="priority"></param>
        static public void LoadAsset(string abName, string assetName, System.Type type, System.Action <CRequest> onComplete, System.Action <CRequest> onEnd, int priority = 0)
        {
            var req = CRequest.Get();

            req.priority   = priority;
            req.assetName  = assetName;
            req.assetType  = type;
            req.vUrl       = abName;
            req.OnComplete = onComplete;
            req.OnEnd      = onEnd;
            LoadAsset(req);
        }
コード例 #9
0
ファイル: ResourcesLoader.cs プロジェクト: GouDanYuan/hugula
        /// <summary>
        /// 以同步方式加载ab资源
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <returns></returns>
        static public UnityEngine.Object LoadAsset(string abName, string assetName, Type assetType)
        {
            var req = CRequest.Get();

            req.assetName       = assetName;
            req.assetType       = assetType;
            req.assetBundleName = abName;
            LoadAsset(req, false);
            UnityEngine.Object t = (UnityEngine.Object)req.data;
            req.ReleaseToPool();
            return(t);
        }
コード例 #10
0
ファイル: ResourcesLoader.cs プロジェクト: GouDanYuan/hugula
        /// <summary>
        /// 以同步方式加载 sub资源
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <param name="type"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        /// <param name="priority"></param>
        static public UnityEngine.Object[] LoadAssetWithSubAssets(string abName, string assetName, System.Type type)
        {
            var req = CRequest.Get();

            req.assetName       = assetName;
            req.assetType       = type;
            req.assetBundleName = abName;
            LoadAsset(req, false, true);
            UnityEngine.Object[] t = (UnityEngine.Object[])req.data;
            req.ReleaseToPool();
            return(t);
        }
コード例 #11
0
ファイル: ResourcesLoader.cs プロジェクト: GouDanYuan/hugula
        /// <summary>
        /// 以 回调方式加载 ab资源
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <param name="type"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        /// <param name="priority"></param>
        /// <returns >返回标识id可以取消完成后的complete回调</returns>
        static public int LoadAssetAsync(string abName, string assetName, System.Type type, System.Action <object, object> onComplete, System.Action <object, object> onEnd, object userData = null)
        {
            var req = CRequest.Get();

            req.assetName       = assetName;
            req.assetType       = type;
            req.assetBundleName = abName;
            req.OnComplete      = onComplete;
            req.OnEnd           = onEnd;
            req.userData        = userData;
            return(LoadAsset(req));
        }
コード例 #12
0
ファイル: CRequest.cs プロジェクト: xubingyue/hugula
        // private void Init

        // /// <summary>
        // /// 获取当前 URL
        // /// </summary>
        // private static string GetURL (CRequest req) {
        //     string url = string.Empty;
        //     var uris = req.uris;
        //     int index = req.index;
        //     if (uris != null && uris.count > index && index >= 0) {
        //         url = CUtils.PathCombine (uris[index], req.relativeUrl);
        //     }
        //     return url;
        // }

        //创建一个CRequest
        public static CRequest Create(string assetBundleName, string assetName, Type assetType, System.Action <CRequest> onComp, System.Action <CRequest> onEnd)
        {
            var req = CRequest.Get();

            req.vUrl      = assetBundleName;
            req.assetName = assetName;
            req.assetType = assetType;

            req.OnComplete = onComp;
            req.OnEnd      = onEnd;

            return(req);
        }
コード例 #13
0
ファイル: ResourcesLoader.cs プロジェクト: GouDanYuan/hugula
        static Queue <AssetOperation> waitOperations = new Queue <AssetOperation>();             //等待队列

        /// <summary>
        /// 以同步方式加载ab资源
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <returns></returns>
        static public T LoadAsset <T>(string abName, string assetName)
        {
            var req = CRequest.Get();

            req.assetName       = assetName;
            req.assetType       = typeof(T);
            req.assetBundleName = abName;
            LoadAsset(req, false);
            T t = (T)req.data;

            req.ReleaseToPool();
            return(t);
        }
コード例 #14
0
ファイル: ResourcesLoader.cs プロジェクト: xubingyue/hugula
        /// <summary>
        ///  以 WWW 方式加载网络非ab资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="head"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        static public HttpLoadOperation HttpWebRequestCoroutine(string url, WebHeaderCollection head, System.Type type)
        {
            var req = CRequest.Get();

            req.vUrl      = url;
            req.head      = head;
            req.assetType = type;
            HttpWebRequestOperation op = new HttpWebRequestOperation();

            req.assetOperation = op;
            op.SetRequest(req);
            inProgressOperations.Add(op);
            op.BeginDownload();
            return(op);
        }
コード例 #15
0
        /// <summary>
        /// 加载场景
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="sceneName"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        /// <param name="allowSceneActivation"></param>
        /// <param name="loadSceneMode"></param>
        /// <returns></returns>
        static public void LoadScene(string abName, string sceneName, System.Action <object, object> onComplete, System.Action <object, object> onEnd, bool allowSceneActivation = true, LoadSceneMode loadSceneMode = LoadSceneMode.Additive)
        {
            var req = CRequest.Get();

            req.assetName       = sceneName;
            req.assetType       = LoaderType.Typeof_ABScene;
            req.assetBundleName = abName;
            req.OnComplete      = onComplete;
            req.OnEnd           = onEnd;
            // if (CacheManager.GetSceneBundle(sceneName) == null) //没有加载场景
            LoadSceneAsset(req, allowSceneActivation, loadSceneMode);
            // else
            // {
            //     DispatchReqAssetOperation(req, false);
            // }
        }
コード例 #16
0
ファイル: CRequest.cs プロジェクト: pengjugame/hugula
        //创建一个CRequest
        public static CRequest Create(string relativeUrl, string assetName, Type assetType, System.Action <CRequest> onComp, System.Action <CRequest> onEnd,
                                      object head, bool async)
        {
            var req = CRequest.Get();

            req.relativeUrl = relativeUrl;
            req.assetName   = assetName;
            req.assetType   = assetType;

            req.OnComplete = onComp;
            req.OnEnd      = onEnd;
            req.head       = head;
            req.async      = async;

            return(req);
        }
コード例 #17
0
        /// <summary>
        /// 加载场景
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="sceneName"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        /// <param name="allowSceneActivation"></param>
        /// <param name="loadSceneMode"></param>
        /// <returns></returns>
        static public void LoadScene(string abName, string sceneName, System.Action <object, object> onComplete, System.Action <object, object> onEnd, object userData = null, bool allowSceneActivation = true, LoadSceneMode loadSceneMode = LoadSceneMode.Additive)
        {
            var req = CRequest.Get();

            req.assetName       = sceneName;
            req.assetType       = LoaderType.Typeof_ABScene;
            req.assetBundleName = abName;
            req.OnComplete      = onComplete;
            req.OnEnd           = onEnd;
            req.userData        = userData;

            AsyncOperation request = null;

            if ((request = CacheManager.GetLoadingScene(sceneName)) != null)
            {
                instance.StartCoroutine(LoadDeActiveScene(request, req, allowSceneActivation));
            }
            else
            {
                LoadSceneAsset(req, allowSceneActivation, loadSceneMode);
            }
        }
コード例 #18
0
        /// <summary>
        /// load LoadDependencies assetbundle
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected int[] LoadDependencies(CRequest req, CRequest parent)
        {
            string[] deps = ManifestManager.fileManifest.GetDirectDependencies(req.assetBundleName);
            if (deps.Length == 0)
            {
                return(null);
            }
            string abName = string.Empty;

            if (parent != null)
            {
                abName = CUtils.GetBaseName(parent.assetBundleName);
            }

#if HUGULA_PROFILER_DEBUG
            Profiler.BeginSample(string.Format("LoadDependencies ({0},{1},{2}) new int[deps.Length]", req.assetName, req.key, req.isShared));
#endif
            string   dep_url;
            string   depAbName = "";
            CRequest item;
            int[]    hashs = new int[deps.Length];
            int      keyhash;
#if HUGULA_PROFILER_DEBUG
            Profiler.EndSample();
#endif

            for (int i = 0; i < deps.Length; i++)
            {
                depAbName = CUtils.GetBaseName(deps[i]);
                if (abName == depAbName)
                {
#if UNITY_EDITOR
                    Debug.LogErrorFormat("Dependencies({1}) Contains the parent({0}) ! ", req.assetBundleName, abName);
#else
                    Debug.LogWarningFormat("Dependencies({1}) Contains the parent({0}) ! ", req.assetBundleName, abName);
#endif
                    hashs[i] = 0;
                    continue;
                }

                dep_url = ManifestManager.RemapVariantName(depAbName);//string gc alloc

                keyhash  = LuaHelper.StringToHash(dep_url);
                hashs[i] = keyhash;

                CacheData sharedCD = CacheManager.TryGetCache(keyhash);
                if (sharedCD != null)
                {
                    sharedCD.count++;
                    int count = sharedCD.count;//CountMananger.WillAdd(keyhash); //引用数量加1;
#if HUGULA_CACHE_DEBUG
                    HugulaDebug.FilterLogFormat(dep_url, " <color=#fcfcfc> add  (assetBundle={0},parent={1},hash={2},count={3}) frameCount={4}</color>", dep_url, req.key, keyhash, count, UnityEngine.Time.frameCount);
#endif
                    if (count == 1)//相加后为1,可能在回收列表,需要对所有依赖项目引用+1
                    {
                        ABDelayUnloadManager.CheckRemove(keyhash);
                    }
#if HUGULA_LOADER_DEBUG
                    HugulaDebug.FilterLogFormat(req.key, " <color=#15A0A1> 1.1 Shared  AssetBundle is Done Request(assetName={0})  Parent Req(assetName={1},key={2},isShared={3}) </color>", sharedCD.assetBundleKey, req.assetName, req.key, req.isShared);
#endif
                }
                else
                {
#if HUGULA_CACHE_DEBUG
                    int count = CountMananger.WillAdd(keyhash); //引用数量加1
                    HugulaDebug.FilterLogFormat(dep_url, " <color=#fcfcfc> will add  (assetBundle={0},parent={1},hash={2},count={3}) frameCount={4}</color>", dep_url, req.key, keyhash, count, UnityEngine.Time.frameCount);
#else
                    CountMananger.WillAdd(keyhash); //引用数量加1
#endif
                    item              = CRequest.Get();
                    item.relativeUrl  = dep_url;
                    item.isShared     = true;
                    item.async        = req.async;
                    item.priority     = req.priority;
                    item.dependencies = LoadDependencies(item, req);
                    item.uris         = req.uris;
#if HUGULA_LOADER_DEBUG
                    HugulaDebug.FilterLogFormat(req.key, "<color=#15A0A1>1.1  Load Dependencies Req({1},keyHashCode{2})  AssetBundleInternal  Parent Request(assetname={0}), dependencies.count={3},frameCount{4}</color>", req.assetName, item.assetName, item.keyHashCode, item.dependencies == null ? 0 : item.dependencies.Length, Time.frameCount);
#endif

                    LoadAssetBundleInternal(item);
                }
            }

            return(hashs);
        }
コード例 #19
0
ファイル: ResourcesLoader.cs プロジェクト: luankun/hugula
        /// <summary>
        /// load LoadDependencies assetbundle
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected int[] LoadDependencies(CRequest req, string[] deps)
        {
            // string[] deps = ManifestManager.fileManifest.GetDirectDependencies (req.key);
            if (deps.Length == 0)
            {
                return(null);
            }
            string abName = string.Empty;

            string   dep_url;
            string   depAbName = "";
            CRequest item;

            int[] hashs = new int[deps.Length];
            int   keyhash;

            for (int i = 0; i < deps.Length; i++)
            {
                depAbName = CUtils.GetBaseName(deps[i]);
                dep_url   = ManifestManager.RemapVariantName(depAbName); //string gc alloc

                keyhash  = LuaHelper.StringToHash(dep_url);
                hashs[i] = keyhash;

                CacheData sharedCD = CacheManager.TryGetCache(keyhash);
                if (sharedCD != null)
                {
                    sharedCD.count++;
                    int count = sharedCD.count; //CountMananger.WillAdd(keyhash); //引用数量加1;
#if HUGULA_CACHE_DEBUG
                    HugulaDebug.FilterLogFormat(dep_url, " <color=#fcfcfc> add  (assetBundle={0},parent={1},hash={2},count={3}) frameCount={4}</color>", dep_url, req.key, keyhash, count, UnityEngine.Time.frameCount);
#endif
                    if (count == 1) //相加后为1,可能在回收列表,需要对所有依赖项目引用+1
                    {
                        ABDelayUnloadManager.CheckRemove(keyhash);
                    }
                }
                else
                {
#if HUGULA_CACHE_DEBUG
                    int count = CountMananger.WillAdd(keyhash);  //引用数量加1
                    HugulaDebug.FilterLogFormat(dep_url, " <color=#fcfcfc> will add  (assetBundle={0},parent={1},hash={2},count={3}) frameCount={4}</color>", dep_url, req.key, keyhash, count, UnityEngine.Time.frameCount);
#else
                    CountMananger.WillAdd(keyhash);  //引用数量加1
#endif
                    item          = CRequest.Get();
                    item.vUrl     = dep_url;
                    item.isShared = true;
                    item.async    = req.async;
                    item.priority = req.priority;
                    string[] deps1 = ManifestManager.fileManifest.GetDirectDependencies(item.key);
                    if (deps1.Length > 0)
                    {
                        item.dependencies = LoadDependencies(req, deps1);
                    }
                    LoadAssetBundleInternal(item);
                }
            }

            return(hashs);
        }
コード例 #20
0
        /// <summary>
        /// load LoadDependencies assetbundle
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected int[] LoadDependencies(CRequest req)
        {
            string[] deps = ManifestManager.fileManifest.GetDirectDependencies(req.assetBundleName);
            if (deps.Length == 0)
            {
                return(null);
            }
#if HUGULA_PROFILER_DEBUG
            Profiler.BeginSample(string.Format("LoadDependencies ({0},{1},{2}) new int[deps.Length]", req.assetName, req.key, req.isShared));
#endif
            string   dep_url;
            string   depAbName = "";
            CRequest item;
            int[]    hashs = new int[deps.Length];
            int      keyhash;
#if HUGULA_PROFILER_DEBUG
            Profiler.EndSample();
#endif
            for (int i = 0; i < deps.Length; i++)
            {
                depAbName = deps[i];
                if (string.IsNullOrEmpty(depAbName)) // Dependency assetbundle name is empty  unity bug?
                {
#if UNITY_EDITOR
                    Debug.LogWarningFormat("the request({0},{1}) Dependencies {2} is empty ", req.assetName, req.url, i);
#endif
                    hashs[i] = 0;
                    continue;
                }

                dep_url  = ManifestManager.RemapVariantName(depAbName);//string gc alloc
                dep_url  = depAbName;
                keyhash  = LuaHelper.StringToHash(dep_url);
                hashs[i] = keyhash;

                CacheData sharedCD = CacheManager.TryGetCache(keyhash);
                if (sharedCD != null)
                {
                    int count = 0;
#if HUGULA_CACHE_DEBUG
                    count = CountMananger.WillAdd(keyhash); //引用数量加1
                    HugulaDebug.FilterLogFormat(req.key + "," + dep_url, " <color=#fcfcfc> will add  (assetBundle={0},hash={1},count={2}) frameCount{3}</color>", dep_url, keyhash, count, UnityEngine.Time.frameCount);
#else
                    count = CountMananger.WillAdd(keyhash); //引用数量加1
#endif
                    bool dependenciesRefer = count == 1;    //the cache count == 0
                    if (dependenciesRefer)
                    {
                        ABDelayUnloadManager.AddDependenciesReferCount(sharedCD, dependenciesRefer);
                    }
#if HUGULA_LOADER_DEBUG
                    HugulaDebug.FilterLogFormat(req.key, " <color=#15A0A1> 1.1 Shared  AssetBundle is Done Request(assetName={0})  Parent Req(assetName={1},key={2},isShared={3}) </color>", sharedCD.assetBundleKey, req.assetName, req.key, req.isShared);
#endif
                }
                else
                {
#if HUGULA_CACHE_DEBUG
                    int count = CountMananger.WillAdd(keyhash); //引用数量加1
                    HugulaDebug.FilterLogFormat(req.key + "," + dep_url, " <color=#fcfcfc> will add  (assetBundle={0},hash={1},count={2}) frameCount{3}</color>", dep_url, keyhash, count, UnityEngine.Time.frameCount);
#else
                    CountMananger.WillAdd(keyhash); //引用数量加1
#endif
                    item              = CRequest.Get();
                    item.relativeUrl  = dep_url;
                    item.isShared     = true;
                    item.async        = req.async;
                    item.priority     = req.priority;
                    item.dependencies = LoadDependencies(item);
                    item.uris         = req.uris;
#if HUGULA_LOADER_DEBUG
                    HugulaDebug.FilterLogFormat(req.key, "<color=#15A0A1>1.1  Load Dependencies Req({1},keyHashCode{2})  AssetBundleInternal  Parent Request(assetname={0}), dependencies.count={3},frameCount{4}</color>", req.assetName, item.assetName, item.keyHashCode, item.dependencies == null ? 0 : item.dependencies.Length, Time.frameCount);
#endif

                    LoadAssetBundleInternal(item);
                }
            }

            return(hashs);
        }