예제 #1
0
    public static void MakeBundlesWithPath(string toPath, string targetPlatform)
    {
        var target = BuildTarget.iOS;

        if (targetPlatform == "android")
        {
            target = BuildTarget.Android;
        }
        else if (targetPlatform == "osx")
        {
            target = BuildTarget.StandaloneOSX;
        }

        // Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
        AssignAssetBundles();
        //      ClearAssetBundleScene();

        Directory.CreateDirectory(toPath);

        AssetBundleManifest manifest = null;

        // this has to be false or some color information
        // on the mesh will be lost
        PlayerSettings.stripUnusedMeshComponents = false;

        if (target == BuildTarget.Android)
        {
            Debug.Log("Build to dir111:" + toPath);
            manifest = BuildPipeline.BuildAssetBundles(toPath,
                                                       BuildAssetBundleOptions.StrictMode |
                                                       BuildAssetBundleOptions.DeterministicAssetBundle |
                                                       BuildAssetBundleOptions.ChunkBasedCompression,
                                                       // BuildAssetBundleOptions.UncompressedAssetBundle,// |
                                                       // BuildAssetBundleOptions.ForceRebuildAssetBundle,
                                                       target);
        }
        else
        {
            Debug.Log("Build to dir222:" + toPath);
            manifest = BuildPipeline.BuildAssetBundles(toPath,
                                                       BuildAssetBundleOptions.StrictMode |
                                                       BuildAssetBundleOptions.DeterministicAssetBundle |
                                                       BuildAssetBundleOptions.ChunkBasedCompression,
                                                       target);
        }

        BundleEncoder.Init(LBootApp.BUNDLE_KEY, LBootApp.BUNDLE_IV);
        // foreach (string bundleFile in Directory.GetFiles(toPath,
        //     "*" + LBootApp.DEFAULT_BUNDLE_EXTENSION, SearchOption.AllDirectories))
        // {
        //     EncodeBundleFile(bundleFile);
        // }

        File.Delete(toPath + FI.ManifestFile);
        File.Copy(toPath + targetPlatform, toPath + FI.ManifestFile);
        // EncodeBundleFile(toPath + FI.ManifestFile);

        // WriteBundleHashFile(toPath, targetPlatform);
    }
예제 #2
0
 static void EncodeBundleFile(string bundleFile)
 {
     LogUtil.Debug("Encoding bundle file: " + bundleFile);
     if (BundleEncoder.GetEncodingOfFile(bundleFile) == BundleEncoder.Encoding.Unknown)
     {
         BundleEncoder.EncodeOverwriteBundleFile(bundleFile);
     }
     else
     {
         LogUtil.Debug("This bundle file is already encoded: " + bundleFile);
     }
 }
예제 #3
0
    // Unity AssetBundle building is not stable
    // Let's write our own hashes for asset bundle updates
    static void WriteBundleHashFile(string toPath, string targetPlatform)
    {
        var filename = toPath + "/" + targetPlatform + "_hashes.json";

        LogUtil.Debug("WriteBundleHashFile: hash filename=" + filename);

        var writer = new ScannerJsonWriter();

        writer.WriteObjectStart();

        var manifestFile   = toPath + "/" + targetPlatform;
        var manifestBundle = BundleEncoder.CreateBundleFromFile(manifestFile);
        var manifest       = manifestBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");

        LogUtil.Debug("WriteBundleHashFile: manifestFile=" + manifestFile);

        var dependants = new Dictionary <string, List <string> >();

        foreach (var file in manifest.GetAllAssetBundles())
        {
            string[] dependencies = manifest.GetAllDependencies(file);
            foreach (var depend in dependencies)
            {
                if (!dependants.ContainsKey(depend))
                {
                    dependants[depend] = new List <string>();
                }
                dependants[depend].Add(file);
            }
        }

        foreach (var file in manifest.GetAllAssetBundles())
        {
            writer.WritePropertyName(file);
            writer.WriteObjectStart();

            writer.WritePropertyName("hash");
            writer.Write(ComputeBundleAssetHash(toPath, targetPlatform, file));

            writer.WritePropertyName("depends");
            writer.WriteArrayStart();
            string[] dependencies = manifest.GetAllDependencies(file);
            foreach (var depend in dependencies)
            {
                writer.Write(depend);
            }
            writer.WriteArrayEnd();

            writer.WritePropertyName("dependants");
            writer.WriteArrayStart();
            List <string> files = null;
            if (dependants.TryGetValue(file, out files))
            {
                foreach (var dependant in files)
                {
                    writer.Write(dependant);
                }
            }
            else
            {
                LogUtil.Debug("WriteBundleHashFile: file " + file + " has no dependants!");
            }
            writer.WriteArrayEnd();

            writer.WriteObjectEnd();
        }

        writer.WriteObjectEnd();
        writer.OutputToFile(filename);
    }