private void DoUnpack(PackageResourceConfig config)
        {
            if (config.version == m_strUnpackedVersion)
            {
                // do noting
                OnComplate();
                return;
            }
            // mark new version
            m_strUnpackedVersion = config.version;

            var tmpLoader = m_Root.GetComponent <PackageResourceUnpackerTool>();

            if (null != tmpLoader)
            {
                GameObject.Destroy(tmpLoader);
            }
            tmpLoader = m_Root.AddComponent <PackageResourceUnpackerTool>();

            tmpLoader.SetAllSucceedCallback(OnAllSucceedCallback);
            tmpLoader.SetErrorCallback(OnErrorCallback);
            tmpLoader.SetProcessCallback(OnProcessCallback);

            tmpLoader.LoadAssetToFileSystem(Application.persistentDataPath + "/", config.fileList, null);
        }
示例#2
0
        private void BeginPackPackageResource(PackageResourceCompressType compressType, string sourceDirectory, string targetDirectory)
        {
            m_ReportConfig = new PackageResourceConfig();

            m_ReportConfig.compressType = (int)compressType;
            m_ReportConfig.fileList     = new List <string>();

            // get compressor
            var compressor = PackageResourceCompressHelper.GetCompress(compressType);

            if (null == compressor)
            {
                Debug.LogError("Unsupport compress type " + compressType);
                return;
            }
            // sign list
            StringBuilder allFileCRC32Code = new StringBuilder();

            // create file list
            var fileList = GetFileList(sourceDirectory, targetDirectory);

            for (int i = 0; i < fileList.Count; ++i)
            {
                var elem = fileList[i];

                // load file to memory
                byte[] content = File.ReadAllBytes(elem.GetSourcePath());

                // compess file with compress type
                content = CompressFile(content, compressor);

                // get crc32
                allFileCRC32Code.Append(CRC32.GetCRC32byte(content));

                // get output path
                string outputPath = elem.GetOutputPath();

                // ensure folder
                PackageResourceTool.EnsureFolder(outputPath);

                // write file to target directory
                File.WriteAllBytes(outputPath, content);

                // update  report
                m_ReportConfig.fileList.Add(elem.GetSubpath());
            }

            // update report version
            m_ReportConfig.version = CRC32.GetCRC32Str(allFileCRC32Code.ToString()).ToString();

            // save report file
            var reportFile = XmlConfigBase.Serialize(m_ReportConfig);

            File.WriteAllText(targetDirectory + m_strPackageResourceConfigName, reportFile);
        }