Skip to content

Commit

Permalink
Remove example missions from mod bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
timtmok committed Aug 8, 2016
1 parent 482e2dc commit b416ada
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 11 deletions.
11 changes: 7 additions & 4 deletions Assets/Editor/Resources/WorkshopItem.asset
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5cf2299c8864afe4ab42466f546ae20d, type: 3}
m_Name: WorkshopItem
m_EditorClassIdentifier:
WorkshopPublishedFileID: 0
WorkshopPublishedFileID: 733438645
Title: Anagrams
Description:
PreviewImage: {fileID: 0}
Tags: []
Description: These letters are confusing. I think they're in the wrong order. Randomly
punching in the letters will eventually give me a word. One of the arrangements
must work, right?
PreviewImage: {fileID: 2800000, guid: 00aaab98b20855b46a08d2ecabe68399, type: 3}
Tags:
- Regular Module
119 changes: 112 additions & 7 deletions Assets/Editor/Scripts/AssetBundler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ protected static void BuildModBundle(bool useMSBuild)
//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();

Expand Down Expand Up @@ -231,15 +237,47 @@ void CompileAssemblyWithEditor()

managedReferences.Add("Library/UnityAssemblies/UnityEngine");

var compilerOutput = EditorUtility.CompileCSharp(
scriptAssetPaths.ToArray(),
managedReferences.ToArray(),
allDefines.Split(';'),
outputFilename);
//Next we need to grab some type references and use reflection to build things the way Unity does.
//Note that EditorUtility.CompileCSharp will do *almost* exactly the same thing, but it unfortunately
//defaults to "unity" rather than "2.0" when selecting the .NET support for the classlib_profile.

string[] scriptArray = scriptAssetPaths.ToArray();
string[] referenceArray = managedReferences.ToArray();
string[] defineArray = allDefines.Split(';');

//MonoIsland to compile
string classlib_profile = "2.0";
Assembly assembly = Assembly.GetAssembly(typeof(MonoScript));
var monoIslandType = assembly.GetType("UnityEditor.Scripting.MonoIsland");
object monoIsland = Activator.CreateInstance(monoIslandType, BuildTarget.StandaloneWindows, classlib_profile, scriptArray, referenceArray, defineArray, outputFilename);

//MonoCompiler itself
var monoCompilerType = assembly.GetType("UnityEditor.Scripting.Compilers.MonoCSharpCompiler");
object monoCompiler = Activator.CreateInstance(monoCompilerType, monoIsland, false);

MethodInfo beginCompilingMethod = monoCompilerType.GetMethod("BeginCompiling");
MethodInfo pollMethod = monoCompilerType.GetMethod("Poll");
MethodInfo getMessagesMethod = monoCompilerType.GetMethod("GetCompilerMessages");

foreach (var log in compilerOutput)
//CompilerMessage
var compilerMessageType = assembly.GetType("UnityEditor.Scripting.Compilers.CompilerMessage");
FieldInfo messageField = compilerMessageType.GetField("message");

//Start compiling
beginCompilingMethod.Invoke(monoCompiler, null);
while (!(bool)pollMethod.Invoke(monoCompiler, null))
{
System.Threading.Thread.Sleep(50);
}

//Now check and output any messages returned by the compiler
object returnedObj = getMessagesMethod.Invoke(monoCompiler, null);
object[] cmArray = ((Array)returnedObj).Cast<object>().ToArray();

foreach (object cm in cmArray)
{
Debug.LogFormat("Compiler: {0}", log);
string str = (string)messageField.GetValue(cm);
Debug.LogFormat("Compiler: {0}", str);
}

if (!File.Exists(outputFilename))
Expand Down Expand Up @@ -387,6 +425,73 @@ protected void CreateModInfo()
File.WriteAllText(outputFolder + "/modInfo.json", ModConfig.Instance.ToJson());
}

/// <summary>
/// Copies the modSettings.json file from Assets to the OUTPUT_FOLDER.
/// </summary>
protected void CopyModSettings()
{
if(File.Exists("Assets/modSettings.json"))
{
File.Copy("Assets/modSettings.json", outputFolder + "/modSettings.json");
}
}
/// <summary>
/// Copies PDF manual pages to Manual folder in OUTPUT_FOLDER to be used for manual combination
/// </summary>
protected void CopyManual()
{
if(Directory.Exists("Manual/pdfs"))
{
DirectoryCopyPDFs("Manual/pdfs", outputFolder + "/Manual", true);
}
}

/// <summary>
/// Helper method to copy directory
/// </summary>
private static void DirectoryCopyPDFs(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);

if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}

DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}

// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
if(file.Extension.ToLower() == ".pdf")
{
file.CopyTo(temppath, false);
}

}

// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopyPDFs(subdir.FullName, temppath, copySubDirs);
}
}
}


/// <summary>
/// All assets tagged with "mod.bundle" will be included in the build, including the Example assets. Print out a
/// warning to notify mod authors that they may wish to delete the examples.
Expand Down
1 change: 1 addition & 0 deletions Manual/pdfs/Appendix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Just to add empty folders
2 changes: 2 additions & 0 deletions Manual/pdfs/Modules/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Just to add empty folders
*.pdf
1 change: 1 addition & 0 deletions Manual/pdfs/NeedyModules/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Just to add empty folders

0 comments on commit b416ada

Please sign in to comment.