diff --git a/Assets/Editor/CreateAssetBundles.cs b/Assets/Editor/CreateAssetBundles.cs index 008089a3..23f02412 100644 --- a/Assets/Editor/CreateAssetBundles.cs +++ b/Assets/Editor/CreateAssetBundles.cs @@ -1,12 +1,10 @@ using System.IO; -using System; -using System.Collections.Generic; -using System.Linq; using UnityEditor; -using UnityEditor.Build; -using UnityEditor.Build.Reporting; using UnityEngine; +using SatorImaging.UnitySourceGenerator.Editor; +using HeavenStudio; + public class CreateAssetBundles { [MenuItem("Assets/Build AssetBundles/Current Platform")] @@ -17,6 +15,8 @@ public class CreateAssetBundles { Directory.CreateDirectory(assetBundleDirectory); } + AssetDatabase.Refresh(); + USGUtility.ForceGenerateByType(typeof(Minigames)); BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); } @@ -28,6 +28,8 @@ public class CreateAssetBundles { Directory.CreateDirectory(assetBundleDirectory); } + AssetDatabase.Refresh(); + USGUtility.ForceGenerateByType(typeof(Minigames)); BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows); } @@ -39,6 +41,8 @@ public class CreateAssetBundles { Directory.CreateDirectory(assetBundleDirectory); } + AssetDatabase.Refresh(); + USGUtility.ForceGenerateByType(typeof(Minigames)); BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneLinux64); } @@ -50,6 +54,8 @@ public class CreateAssetBundles { Directory.CreateDirectory(assetBundleDirectory); } + AssetDatabase.Refresh(); + USGUtility.ForceGenerateByType(typeof(Minigames)); BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneOSX); } } \ No newline at end of file diff --git a/Assets/Editor/CreateMinigameScriptTemplate.cs b/Assets/Editor/CreateMinigameScriptTemplate.cs new file mode 100644 index 00000000..b32a887b --- /dev/null +++ b/Assets/Editor/CreateMinigameScriptTemplate.cs @@ -0,0 +1,14 @@ +using UnityEngine; +using UnityEditor; +using SatorImaging.UnitySourceGenerator.Editor; + +public class CreateMinigameScriptTemplate +{ + [MenuItem("Assets/Heaven Studio/Create Minigame Script From Template", priority = 0)] + public static void CreateMinigameScript() + { + ProjectWindowUtil.CreateScriptAssetFromTemplateFile("Assets/Editor/ScriptTemplates/MinigameScriptTemplate.txt", "NewMinigame.cs"); + AssetDatabase.Refresh(); + USGUtility.ForceGenerateByType(typeof(HeavenStudio.Minigames)); + } +} diff --git a/Assets/Editor/CreateMinigameScriptTemplate.cs.meta b/Assets/Editor/CreateMinigameScriptTemplate.cs.meta new file mode 100644 index 00000000..adfc9fa1 --- /dev/null +++ b/Assets/Editor/CreateMinigameScriptTemplate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 24bc0d119c30f3a41aee57b4e85dbf64 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/ScriptTemplates.meta b/Assets/Editor/ScriptTemplates.meta new file mode 100644 index 00000000..b125f502 --- /dev/null +++ b/Assets/Editor/ScriptTemplates.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 12ec433916efb3c4a895be2ac0dd6935 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/ScriptTemplates/MinigameScriptTemplate.txt b/Assets/Editor/ScriptTemplates/MinigameScriptTemplate.txt new file mode 100644 index 00000000..a570e280 --- /dev/null +++ b/Assets/Editor/ScriptTemplates/MinigameScriptTemplate.txt @@ -0,0 +1,52 @@ +using System; +using System.Linq; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +using HeavenStudio.Util; +using HeavenStudio.InputSystem; + +using Jukebox; + +namespace HeavenStudio.Games.Loaders +{ + using static Minigames; + /// Minigame loaders handle the setup of your minigame. + /// Here, you designate the game prefab, define entities, and mark what AssetBundle to load + + /// Names of minigame loaders follow a specific naming convention of `PlatformcodeNameLoader`, where: + /// `Platformcode` is a three-leter platform code with the minigame's origin + /// `Name` is a short internal name + /// `Loader` is the string "Loader" + + /// Platform codes are as follows: + /// Agb: Gameboy Advance ("Advance Gameboy") + /// Ntr: Nintendo DS ("Nitro") + /// Rvl: Nintendo Wii ("Revolution") + /// Ctr: Nintendo 3DS ("Centrair") + /// Mob: Mobile + /// Pco: PC / Other + + /// Fill in the loader class label, "*prefab name*", and "*Display Name*" with the relevant information + /// For help, feel free to reach out to us on our discord, in the #development channel. + public static class _______________ + { + public static Minigame AddGame(EventCaller eventCaller) + { + return new Minigame("*prefab name*", "*Display Name*", "ffffff", false, false, new List() + { + } + ); + } + } +} + +namespace HeavenStudio.Games +{ + /// This class handles the minigame logic. + /// Minigame inherits directly from MonoBehaviour, and adds Heaven Studio specific methods to override. + public class #SCRIPTNAME# : Minigame + { + } +} \ No newline at end of file diff --git a/Assets/Editor/ScriptTemplates/MinigameScriptTemplate.txt.meta b/Assets/Editor/ScriptTemplates/MinigameScriptTemplate.txt.meta new file mode 100644 index 00000000..8a8b7f83 --- /dev/null +++ b/Assets/Editor/ScriptTemplates/MinigameScriptTemplate.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: a701bb5358c08074b991f83428d52446 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index e3c9128c..74f9caf9 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -21,7 +21,7 @@ using System.IO; namespace HeavenStudio { - [UnitySourceGenerator(typeof(MinigameLoaderGenerator), OverwriteIfFileExists = false)] + [UnitySourceGenerator(typeof(MinigameLoaderGenerator), OverwriteIfFileExists = true)] public partial class Minigames { public enum RecommendedControlStyle diff --git a/Assets/Scripts/SourceGenerators/MinigameLoaderGenerator.cs b/Assets/Scripts/SourceGenerators/MinigameLoaderGenerator.cs index d6fcfc4a..a686aa5a 100644 --- a/Assets/Scripts/SourceGenerators/MinigameLoaderGenerator.cs +++ b/Assets/Scripts/SourceGenerators/MinigameLoaderGenerator.cs @@ -110,7 +110,12 @@ namespace {context.TargetClass.Namespace} "); // USG: return true to tell USG to write content into OutputPath. false to do nothing. - return true; + // only write if changes are made. + if (!System.IO.File.Exists(context.OutputPath)) + return true; + + string oldContent = System.IO.File.ReadAllText(context.OutputPath); + return sb.ToString() != oldContent; } #pragma warning restore IDE0051 diff --git a/ProjectSettings/SatorImaging.UnitySourceGenerator.Editor.ProjectSettingsData.asset b/ProjectSettings/SatorImaging.UnitySourceGenerator.Editor.ProjectSettingsData.asset index 430138a6..1c5f64d9 100644 --- a/ProjectSettings/SatorImaging.UnitySourceGenerator.Editor.ProjectSettingsData.asset +++ b/ProjectSettings/SatorImaging.UnitySourceGenerator.Editor.ProjectSettingsData.asset @@ -18,11 +18,8 @@ MonoBehaviour: DenseViewWidthThreshold: 512 _disableAutoReloadInBackground: 0 ImportedScriptPaths: - - Assets/Scripts/InputSystem/PlayerInput.cs - - Assets/Scripts/SourceGenerators/ControllerLoaderGenerator.cs - - Assets/Scripts/SourceGenerators/MinigameLoaderGenerator.cs - - Assets/Scripts/GlobalGameManager.cs - - Assets/Scripts/InputSystem/InputController.cs - Assets/Scripts/Minigames.cs + - Assets/Editor/CreateAssetBundles.cs + - Assets/Editor/CreateMinigameScriptTemplate.cs PathsToSkipImportEvent: [] PathsToIgnoreOverwriteSettingOnAttribute: []