Exemple #1
0
    protected static void BuildModBundle(bool useMSBuild)
    {
        Debug.LogFormat("Creating \"{0}\" AssetBundle...", BUNDLE_FILENAME);

        if (ModConfig.Instance == null ||
            ModConfig.ID == "" ||
            ModConfig.OutputFolder == "")
        {
            Debug.LogError("You must configure your mod from the \"Keep Talking ModKit / Configure Mod\" menu first.");
            return;
        }

        AssetBundler bundler = new AssetBundler();

        bundler.assemblyName = ModConfig.ID;
        bundler.outputFolder = ModConfig.OutputFolder + "/" + bundler.assemblyName;

        bool success = false;

        try
        {
            bundler.WarnIfExampleAssetsAreIncluded();
            bundler.WarnIfAssetsAreNotTagged();
            bundler.CheckForAssets();

            //Delete the cotnents of OUTPUT_FOLDER
            bundler.CleanBuildFolder();

            //Change all non-Editor scripts to reference ASSEMBLY_NAME instead of Assembly-CSharp
            bundler.AdjustMonoScripts();

            //Build the assembly using either MSBuild or Unity EditorUtility methods
            if (useMSBuild)
            {
                bundler.CompileAssemblyWithMSBuild();
            }
            else
            {
                bundler.CompileAssemblyWithEditor();
            }

            //Copy any other non-Editor managed assemblies to the output folder
            bundler.CopyManagedAssemblies();

            //Create the modInfo.json file
            bundler.CreateModInfo();

            //Copy the modSettings.json file from Assets into the build
            bundler.CopyModSettings();

            //Copy PDF manual pages to Manual folder in build
            bundler.CopyManual();

            //Lastly, create the asset bundle itself and copy it to the output folder
            bundler.CreateAssetBundle();

            success = true;
        }
        catch (Exception e)
        {
            Debug.LogErrorFormat("Failed to build AssetBundle: {0}\n{1}", e.Message, e.StackTrace);
        }
        finally
        {
            //Restore script references to Assembly-CSharp, as expected by the Unity Editor
            bundler.RestoreMonoScripts();
        }

        if (success)
        {
            Debug.LogFormat("{0} Build complete! Output: {1}", System.DateTime.Now.ToLocalTime(), bundler.outputFolder);
        }
    }