diff --git a/Assets/Editor/Resources/WorkshopItem.asset b/Assets/Editor/Resources/WorkshopItem.asset index 4cb69e5..dae9ca8 100644 --- a/Assets/Editor/Resources/WorkshopItem.asset +++ b/Assets/Editor/Resources/WorkshopItem.asset @@ -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 diff --git a/Assets/Editor/Scripts/AssetBundler.cs b/Assets/Editor/Scripts/AssetBundler.cs index 62bd0be..4599399 100644 --- a/Assets/Editor/Scripts/AssetBundler.cs +++ b/Assets/Editor/Scripts/AssetBundler.cs @@ -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(); @@ -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().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)) @@ -387,6 +425,73 @@ protected void CreateModInfo() File.WriteAllText(outputFolder + "/modInfo.json", ModConfig.Instance.ToJson()); } + /// + /// Copies the modSettings.json file from Assets to the OUTPUT_FOLDER. + /// + protected void CopyModSettings() + { + if(File.Exists("Assets/modSettings.json")) + { + File.Copy("Assets/modSettings.json", outputFolder + "/modSettings.json"); + } + } + /// + /// Copies PDF manual pages to Manual folder in OUTPUT_FOLDER to be used for manual combination + /// + protected void CopyManual() + { + if(Directory.Exists("Manual/pdfs")) + { + DirectoryCopyPDFs("Manual/pdfs", outputFolder + "/Manual", true); + } + } + + /// + /// Helper method to copy directory + /// + 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); + } + } + } + + /// /// 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. diff --git a/Manual/pdfs/Appendix/.gitignore b/Manual/pdfs/Appendix/.gitignore new file mode 100644 index 0000000..b5a0b1c --- /dev/null +++ b/Manual/pdfs/Appendix/.gitignore @@ -0,0 +1 @@ +#Just to add empty folders \ No newline at end of file diff --git a/Manual/pdfs/Modules/.gitignore b/Manual/pdfs/Modules/.gitignore new file mode 100644 index 0000000..22dc08b --- /dev/null +++ b/Manual/pdfs/Modules/.gitignore @@ -0,0 +1,2 @@ +#Just to add empty folders +*.pdf diff --git a/Manual/pdfs/NeedyModules/.gitignore b/Manual/pdfs/NeedyModules/.gitignore new file mode 100644 index 0000000..b5a0b1c --- /dev/null +++ b/Manual/pdfs/NeedyModules/.gitignore @@ -0,0 +1 @@ +#Just to add empty folders \ No newline at end of file