Exemplo n.º 1
0
 /// <summary>
 /// 将AB资源的路径格式转换为Resources目录中资源的路径
 /// </summary>
 /// <param name="abName"></param>
 /// <param name="assetName"></param>
 string AssetBundlePath2ResourcePath(string abName, string assetName)
 {
     abName = ABNameWithoutExtension(abName);
     if (abName.ToLower() != HotResConst.SPECIAL_AB_NAME) //resources表示从根目录获取资源,则不需要添加目录
     {
         assetName = FileSystem.CombinePaths(abName, assetName);
     }
     return(assetName);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 检查本地的文件,是否存在或者版本号是否一致
 /// <para>PS:版本号一致需要MD5验证,开销较大,暂不加入</para>
 /// </summary>
 public void ConformingLocalRes()
 {
     foreach (var item in _vo.items)
     {
         var filePath = FileSystem.CombinePaths(Runtime.Ins.localResDir, item.name);
         if (!File.Exists(filePath))
         {
             SetVer(item.name, "");
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 将资源所在路径以及资源名合并成一个完整的资源路径
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <returns></returns>
        public string LinkAssetPath(string abName, string assetName)
        {
            if (abName == null)
            {
                abName = "";
            }

            if (assetName == null)
            {
                assetName = null;
            }

            return(FileSystem.CombinePaths(abName, assetName));
        }
Exemplo n.º 4
0
        public void Start(Action onUpdate, Action <string> onError)
        {
            Log.CI(Log.COLOR_BLUE, "「ManifestFileUpdate」Manifest描述文件更新检查...");
            _rt           = Runtime.Ins;
            _manifestName = FileSystem.CombinePaths(HotResConst.AB_DIR_NAME, HotResConst.MANIFEST_FILE_NAME + HotResConst.AB_EXTENSION);
            //Log.CI(Log.COLOR_RED, _manifestName);
            _onUpdate  = onUpdate;
            _onError   = onError;
            _localPath = _rt.localResDir + _manifestName;

            //比较版本号
            if (Runtime.Ins.IsLoadAssetsFromNet && !_rt.netResVer.IsSameVer(_manifestName, _rt.localResVer))
            {
                ILBridge.Ins.StartCoroutine(Update(_rt.netResDir + _manifestName, _rt.netResVer.GetVer(_manifestName)));
            }
            else
            {
                InitAssetBundleMgr();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 得到目标所有的依赖
        /// </summary>
        /// <param name="itemName"></param>
        /// <returns></returns>
        List <string> GetAllDepends(string itemName)
        {
            List <string> nameList = new List <string>();
            string        abDir    = ResMgr.Ins.RootDir.Replace(Runtime.Ins.localResDir, "");

            abDir += "/";
            if (false == itemName.StartsWith(abDir))
            {
                return(nameList);
            }


            string abName       = itemName.Replace(abDir, "");
            var    abDependList = ResMgr.Ins.GetDepends(abName);

            foreach (var ab in abDependList)
            {
                nameList.Add(FileSystem.CombinePaths(abDir, ab));
            }

            return(nameList);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 加载AB包,自动处理依赖问题
        /// </summary>
        /// <param name="abName"></param>
        /// <returns></returns>
        private AssetBundle LoadAssetBundle(string abName)
        {
            MakeABNameNotEmpty(ref abName);
            abName = ABNameWithExtension(abName);
            string abPath = FileSystem.CombinePaths(RootDir, abName);

            if (false == File.Exists(abPath))
            {
                //加载的AB资源不存在
                Log.E(string.Format("[{0}] 不存在", abPath));
                return(null);
            }

            //依赖检查
            string[] dependList = _manifest.GetAllDependencies(abName);
            foreach (string depend in dependList)
            {
                //string dependPath = Path.Combine(_rootDir, depend);
                if (false == _loadedABDic.ContainsKey(depend))
                {
                    _loadedABDic[depend] = LoadAssetBundle(depend);
                }
            }

            AssetBundle ab = null;

            if (_loadedABDic.ContainsKey(abName))
            {
                ab = _loadedABDic[abName];
            }
            else
            {
                ab = AssetBundle.LoadFromFile(abPath);
                _loadedABDic[abName] = ab;
            }
            return(ab);
        }
        /// <summary>
        /// 将AB资源的路径格式转换为Resources目录中资源的路径
        /// </summary>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        string AssetBundlePath2ResourcePath(string abName, string assetName)
        {
            try
            {
                abName = ABNameWithoutExtension(abName);
                string dir;
                if (abName.ToLower() != HotResConst.SPECIAL_AB_NAME) //resources表示从根目录获取资源,则不需要添加目录
                {
                    dir = FileSystem.CombinePaths(_assetRoot, abName);
                }
                else
                {
                    dir = FileSystem.CombinePaths(_assetRoot);
                }

                //模糊匹配资源名称
                var files = Directory.GetFiles(dir);
                foreach (var file in files)
                {
                    if (Path.GetExtension(file) == ".meta")
                    {
                        continue;
                    }

                    if (Path.GetFileNameWithoutExtension(file) == assetName)
                    {
                        return(file);
                    }
                }
            }
            catch
            {
                throw new Exception(string.Format("在[{0}]下无法找到资源文件[{1}/{2}]", _assetRoot, abName, assetName));
            }
            return(null);
        }