Beispiel #1
0
    static void Init()
    {
        _fenBaos.Clear();
        _package_list.Clear();
        _res_package_infos.Clear();
        _assetPackFlags.Clear();
        _target = UnpackCommon.Target;

        ResVersionEditor.Current.Read();

        _fenBaoVersion = UnpackCommon.GetFenBaoVersion();
        _fenBaoPath    = AssetBundleServerPath.FenBao.GetFenBaoPath(UnpackCommon.DefaultABPath);
        _sourcePath    = UnpackPath.Get();

        AssetBundle assetBundle = AssetBundle.LoadFromFile(UnpackPath.GetMainAssetBundleName());;

        _assetBundleManifest = assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
        assetBundle.Unload(false);
    }
    public static void CopyABToServer()
    {
        ePlatformType osType       = UnpackCommon.GetOsType();
        string        abSourcePath = UnpackPath.Get();
        string        abTargetPath = AssetBundleServerPath.ABCache.GetABCachePath(osType);

        DirectoryInfo source = new DirectoryInfo(abSourcePath);

        FileInfo[] fileInfos = source.GetFiles();
        for (int i = 0; i < fileInfos.Length; i++)
        {
            string abSourceFileName = fileInfos[i].FullName;
            string abTargetFileName = abTargetPath + "/" + fileInfos[i].Name;
            if (File.Exists(abTargetFileName))
            {
                File.Delete(abTargetFileName);
            }

            File.Copy(abSourceFileName, abTargetFileName);
        }
    }
    public static void BuildAssetBundle(BuildTarget target)
    {
        ResVersionEditor.Current.Read();

        ClearLuaFile();
        CopyLuaToTempDir();

        if (UnpackCommon.GetSettingInfo().ResetAssetBundleName)
        {
            ResetNames();
        }

        AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(
            UnpackPath.Get(),
            UnpackCommon.GetSettingInfo().Options,
            target);

        ResVersionEditor.Current.Save(PackageType.OnlyABPack);
        AssetBundlesFileInfoEditor.Current.Save(manifest.GetAllAssetBundles());

        ClearLuaFile();
        CopyABToServer();
    }
    public void Save(PackageType packageType)
    {
        // 写入版本
        _local_version             = new VersionInfo();
        _local_version.Version     = UnpackCommon.GetSettingInfo().Version;
        _local_version.OsType      = UnpackCommon.Target.ToString();
        _local_version.CurrentTime = System.DateTime.Now.ToString();
        _local_version.Type        = packageType.ToString(); //默认散包

        // 写入assetbundlemanifest

        string unpackPath          = UnpackPath.Get();
        string mainAssetBundleName = string.Format("{0}/{1}", unpackPath, UnpackCommon.GetOsType());
        string mainManifestName    = string.Format("{0}/{1}.manifest", unpackPath, UnpackCommon.GetOsType());

        long mainAssetBundleLength = 0;
        long mainManifestLength    = 0;

        string mainABMD5       = string.Empty;
        string mainManifestMD5 = string.Empty;

        if (File.Exists(mainAssetBundleName))
        {
            using (FileStream fs = File.Open(mainAssetBundleName, FileMode.Open))
            {
                mainAssetBundleLength = fs.Length;
                mainABMD5             = FileUtils.GetFileMD5ByStream(fs);
                fs.Close();
            }
        }

        if (File.Exists(mainManifestName))
        {
            using (FileStream fs = File.Open(mainManifestName, FileMode.Open))
            {
                mainManifestLength = fs.Length;
                mainManifestMD5    = FileUtils.GetFileMD5ByStream(fs);
                fs.Close();
            }
        }

        string fileName = AssetsCommon.GetPlatformFolderName(AssetsCommon.GetPlatform());

        _local_version.AssetBundleManifestNames   = new string[2];
        _local_version.AssetBundleManifestLengths = new string[2];
        _local_version.AssetBundleManifestMD5s    = new string[2];

        _local_version.AssetBundleManifestNames[0] = fileName;
        _local_version.AssetBundleManifestNames[1] = string.Format("{0}.manifest", fileName);

        _local_version.AssetBundleManifestLengths[0] = mainAssetBundleLength.ToString();
        _local_version.AssetBundleManifestLengths[1] = mainManifestLength.ToString();

        _local_version.AssetBundleManifestMD5s[0] = mainABMD5;
        _local_version.AssetBundleManifestMD5s[1] = mainManifestMD5;

        string jsonStr     = JsonUtility.ToJson(_local_version);
        string versionPath = AssetBundleServerPath.FileManifest.GetVersionFileName(UnpackCommon.DefaultABPath);

        if (File.Exists(versionPath))
        {
            File.Delete(versionPath);
        }

        using (FileStream stream = File.Create(versionPath))
        {
            byte[] bytes = Encoding.Default.GetBytes(jsonStr);
            stream.Write(bytes, 0, bytes.Length);
            stream.Close();
        }


        bool hasVersion = false;

        for (int i = 0; i < _all_version_number.Count; i++)
        {
            if (_all_version_number[i] == _local_version.Version)
            {
                hasVersion = true;
                break;
            }
        }

        if (!hasVersion)
        {
            _all_version_number.Add(_local_version.Version);
        }

        string versionListPath = AssetBundleServerPath.FileManifest.GetVersionListFileName(UnpackCommon.GetOsType());

        if (File.Exists(versionListPath))
        {
            File.Delete(versionListPath);
        }

        using (FileStream fs = File.Create(versionListPath))
        {
            string context = string.Empty;
            for (int i = 0; i < _all_version_number.Count; i++)
            {
                if (i == _all_version_number.Count - 1)
                {
                    context += _all_version_number[i];
                }
                else
                {
                    context += _all_version_number[i] + "\n";
                }
            }

            byte[] bytes = System.Text.Encoding.Default.GetBytes(context);
            fs.Write(bytes, 0, bytes.Length);
            fs.Close();
        }
    }