Ejemplo n.º 1
0
        /// <summary>
        /// 添加一个节点到表头
        /// </summary>
        /// <param name="t"></param>
        public DoubleLinkedListNode <T> AddToHeader(T t)
        {
            DoubleLinkedListNode <T> pList = m_DoubleLinkNodePool.Spawn(true);

            pList.next = null;
            pList.prev = null;
            pList.t    = t;
            return(AddToHeader(pList));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载单个AssetBundle,根据名称
        /// </summary>
        /// <param name="name">AssetBundle名称</param>
        /// <returns></returns>
        public AssetBundle LoadAssetBundle(string name)
        {
            AssetBundleItem abItem = null;
            uint            crc    = Crc32.GetCrc32(name); //根据名称获取Crc值

            if (!m_AssetBundleItemDic.TryGetValue(crc, out abItem))
            {
                AssetBundle assetBundle = null;

                //热更下来的AB包放在Application.persistentDataPath + "/DownLoad" 目录下

                //打包到游戏包里的AB包放在Application.streamingAssetsPath 目录下

                //所以要根据资源文件名称来判断是否是热更的AB包

                string hotAbPath = HotPatchManager.Instance.ComputeABPath(name);

                string fullPath = string.IsNullOrEmpty(hotAbPath) ? ABLoadPath + name : hotAbPath;

                //加密后的ab包要先解密,才能加载
                if (Encrypt)
                {
                    byte[] bytes = AES.AESFileByteDecrypt(fullPath, FrameConstr.m_ABSecretKey);

                    assetBundle = AssetBundle.LoadFromMemory(bytes);
                }
                else
                {
                    assetBundle = AssetBundle.LoadFromFile(fullPath);
                }

                if (assetBundle == null)
                {
                    Debug.LogError("Load AssetBundle Error:" + fullPath);
                }

                abItem             = m_AssetBundleItemPool.Spawn(true);
                abItem.assetBundle = assetBundle;
                abItem.RefCount++;
                m_AssetBundleItemDic.Add(crc, abItem);
            }
            else
            {
                abItem.RefCount++;
            }

            return(abItem.assetBundle);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 异步资源加载,外部直接调用,(仅仅加载不需要实例化的资源,例如Texture和音频之类的)
        /// </summary>
        public void AsyncLoadResource(string path, OnAsyncFinish dealFinish, LoadResPriority priority, bool isSprite = false, uint crc = 0, params object[] paramList)
        {
            if (crc == 0)
            {
                crc = Crc32.GetCrc32(path);
            }

            AssetBundleInfo abInfo = GetCacheAssetBundleInfo(crc);

            if (abInfo != null)
            {
                dealFinish?.Invoke(path, abInfo.m_Obj, paramList);
                return;
            }

            //判断是否在加载中
            AsyncLoadResUnit unit = null;

            //没有找到这个异步加载单位,或者这个异步加载单位是空
            if (!m_LoadingAssetDic.TryGetValue(crc, out unit) || unit == null)
            {
                unit            = m_AsyncLoadResParamPool.Spawn(true);
                unit.m_Crc      = crc;
                unit.m_Path     = path;
                unit.m_Sprite   = isSprite;
                unit.m_Priority = priority;

                m_LoadingAssetDic.Add(crc, unit);            //添加到正在异步加载的资源dic中

                m_loadingAssetList[(int)priority].Add(unit); //按照加载优先级,添加到对应的正在异步加载的资源列表中
            }

            //往回调列表里面添加回调
            AsynCallBack callBack = m_AsynCallBackPool.Spawn(true);

            callBack.m_DealFinish = dealFinish;
            callBack.m_Params     = paramList;

            //往这个异步加载单位的回调列表中添加一个回调
            //可能多个地方加载同一份资源,这样做只加载一次资源,
            //加载完了后,根据回调列表一次返回这份资源
            unit.m_CallBackList.Add(callBack);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 同步加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="setSceneObj">是否存到</param>
        /// <param name="bClear">跳场景是否清空</param>
        /// <returns></returns>
        public GameObject InstantiateObject(string path, bool setSceneObj = false, bool bClear = true)
        {
            uint crc = Crc32.GetCrc32(path);
            //从缓存池获取
            ResourceObj resObj = GetObjectFromPool(crc);

            if (resObj == null)
            {
                resObj          = m_ResObjClassPool.Spawn(true);
                resObj.m_Crc    = crc;
                resObj.m_bClear = bClear;

                //ResourceManager提供加载方法
                //给resObj.m_AssetBundleInfo 赋值
                //给resObj.m_AssetBundleInfo.m_Obj赋值
                resObj = ResourceManager.Instance.LoadResource(path, resObj);

                if (resObj.m_AssetBundleInfo.m_Obj != null)
                {
                    resObj.m_CloneObj = GameObject.Instantiate(resObj.m_AssetBundleInfo.m_Obj) as GameObject;

                    resObj.m_offlineData = resObj.m_CloneObj.GetComponent <OfflineData>();
                }
            }

            //setParent会造成性能消耗,所以加个布尔值控制下
            if (setSceneObj)
            {
                resObj.m_CloneObj.transform.SetParent(SceneTrs, false);
            }

            int tempID = resObj.m_CloneObj.GetInstanceID();

            if (!m_ResObjDic.ContainsKey(tempID))
            {
                m_ResObjDic.Add(tempID, resObj);
            }

            return(resObj.m_CloneObj);
        }