private static void InitAsset(WaitingAssetsInfo waitInfo)
        {
            var path      = waitInfo.path;
            var extension = Path.GetExtension(path).ToLower();

            if (ABConfig.IsExcludeExtention(extension))
            {
                return;
            }
            ABAssetsInfo info = null;

            if (!s_AssetInfoDic.ContainsKey(path))
            {
                var assetType = ABConfig.GetAssetType(extension);
                var width     = 0;
                var height    = 0;
                if (assetType == AssetsType.Texture)
                {
                    ABHelper.GetTextureWidthAndHeight(path, out width, out height);
                }
                info = new ABAssetsInfo()
                {
                    type          = assetType,
                    name          = Path.GetFileNameWithoutExtension(path),
                    extension     = extension,
                    path          = path,
                    abName        = ABHelper.GetABName(path),
                    textureWidth  = width,
                    textureHeight = height
                };
                s_AssetInfoDic[path] = info;
            }
            else
            {
                info = s_AssetInfoDic[path];
            }
            info.size = ABHelper.GetAssetSize(path);
            if (info.type == AssetsType.Texture)
            {
                var maxSize = 0;
                ABHelper.GetTextureMaxSize(s_TargetPlatform, info.path, out maxSize);
                info.textureMaxSize = maxSize;
            }
            foreach (var ab in waitInfo.parents)
            {
                info.AddRefAB(ab);
            }
            if (!s_AssetTypeStat.ContainsKey(AssetsType.None))
            {
                s_AssetTypeStat[AssetsType.None] = new StatInfo();
            }
            if (!s_AssetTypeStat.ContainsKey(info.type))
            {
                s_AssetTypeStat[info.type] = new StatInfo();
            }
            s_AssetTypeStat[AssetsType.None].Stat(1, info.size);
            s_AssetTypeStat[info.type].Stat(1, info.size);
            s_CurrentAssetsList.Add(info);
            s_AssetDirty = true;
        }
Example #2
0
 private IEnumerator loadForLocalABPath(string keyPath)
 {
     using (DecompressWhileRef counter = new DecompressWhileRef())
     {
         string abFilePath = ABPathHelper.AssetsWWWStreamURL + keyPath;
         if (abFilePath.IndexOf(ABPathHelper.MP4Suffix) < 0)
         {
             WWW wwwWithPakFile = new WWW(abFilePath);
             if (wwwWithPakFile != null)
             {
                 while (!wwwWithPakFile.isDone)
                 {
                     yield return(null);
                 }
                 abFilePath = ABPathHelper.AssetsLocalABURL + keyPath;
                 ABHelper.CacheFile(abFilePath, wwwWithPakFile.bytes);
                 wwwWithPakFile.Dispose();
             }
         }
     }
 }
 private static long GetABFileSize(string abName)
 {
     return(ABHelper.GetFileSize(s_ABDirPath + abName));
 }
Example #4
0
    public static void CopyDir(string srcPath, string aimPath)
    {
        try
        {
            // 检查目标目录是否以目录分割字符结束如果不是则添加之
            if (aimPath[aimPath.Length - 1] != Path.DirectorySeparatorChar)
            {
                aimPath += Path.DirectorySeparatorChar;
            }
            // 判断目标目录是否存在如果不存在则新建之
            if (!Directory.Exists(aimPath))
            {
                Directory.CreateDirectory(aimPath);
            }
            // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
            // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
            // string[] fileList = Directory.GetFiles(srcPath);
            string[] fileList = Directory.GetFileSystemEntries(srcPath);
            // 遍历所有的文件和目录
            foreach (string file in fileList)
            {
                // 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
                if (Directory.Exists(file))
                {
                    CopyDir(file, aimPath + Path.GetFileName(file));
                }
                // 否则直接Copy文件
                else
                {
                    fileExt     = Path.GetExtension(file);
                    curFileName = Path.GetFileName(file);
                    if (fileExt.Equals(".manifest"))
                    {
                        continue;
                    }

                    outFileName = aimPath + curFileName;
                    if (fileExt.Equals(ABPathHelper.Unity3dSuffix))
                    {
                        string fileName = file.Replace("\\", "/");
                        byte[] fileData = null;
                        using (FileStream fs = new FileStream(file, FileMode.Open))
                        {
                            fileData = new byte[fs.Length];
                            fs.Read(fileData, 0, (int)fs.Length);
                        }

                        ABHelper.CacheCompressFile(outFileName, fileData);

                        curFileIndex++;
                        ShowProgress();
                    }
                    else
                    {
                        File.Copy(file, outFileName, true);
                    }
                }
            }
        }
        catch
        {
            Debug.LogError("无法复制!" + srcPath + "  到   " + aimPath);
        }
    }