From 4d8f1f0a5312d3938cbd9492543439aa7fdefd0b Mon Sep 17 00:00:00 2001 From: Hibnu Hishath Date: Sun, 23 Jul 2023 21:09:23 +0530 Subject: [PATCH] Added option to disable Scriptable Singleton Asset Creator --- Editor/DefineRegistrant.cs | 38 +++++++++++++++++++ Editor/DefineRegistrant.cs.meta | 11 ++++++ Editor/SingletonsEditor.cs | 10 ++++- Editor/com.hibzz.singletons.editor.asmdef | 3 +- ...CreateScriptableSingletonAssetAttribute.cs | 8 ++-- 5 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 Editor/DefineRegistrant.cs create mode 100644 Editor/DefineRegistrant.cs.meta diff --git a/Editor/DefineRegistrant.cs b/Editor/DefineRegistrant.cs new file mode 100644 index 0000000..30411ff --- /dev/null +++ b/Editor/DefineRegistrant.cs @@ -0,0 +1,38 @@ +// This script should only run when define manager is installed +#if ENABLE_DEFINE_MANAGER + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Hibzz.DefineManager; + +namespace Hibzz.Singletons.Editor +{ + /// + /// Used to register the defines + /// + internal class DefineRegistrant + { + [RegisterDefine] + static DefineRegistrationData RegisterDisableScriptableObjectCreator() + { + DefineRegistrationData data = new DefineRegistrationData(); + + data.Define = "DISABLE_SCRIPTABLE_SINGLETON_CREATOR"; + data.DisplayName = "Disable Scriptable Singleton Creator"; + data.Category = "Hibzz.Singletons"; + data.Description = "The scriptable singleton creator functionality " + + "lets users mark any ScriptableSingleton class with an attribute " + + "called `CreateScriptableSingletonAsset`. When the user presses " + + "the \"Create Scriptable Singleton Assets\" button, the system " + + "will create any missing assets for those singletons in the " + + "\"Resources/Singletons\" folder. \n\n" + + "Installing this define will disable this feature."; + data.EnableByDefault = false; + + return data; + } + } +} + +#endif diff --git a/Editor/DefineRegistrant.cs.meta b/Editor/DefineRegistrant.cs.meta new file mode 100644 index 0000000..d8c471c --- /dev/null +++ b/Editor/DefineRegistrant.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5d102ff7287dff5428ec3eefcfeabc60 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/SingletonsEditor.cs b/Editor/SingletonsEditor.cs index d2dee03..88b646f 100644 --- a/Editor/SingletonsEditor.cs +++ b/Editor/SingletonsEditor.cs @@ -9,7 +9,9 @@ public static class SingletonsEditor { // These are menu paths const string BASE_PATH = "Hibzz/Singletons/"; - const string CREATE_SINGLETON_ASSET_PATH = BASE_PATH + "Create Scriptable Singleton Assets"; + + #region Scriptable Singleton Asset Creator Code + #if !DISABLE_SCRIPTABLE_SINGLETON_CREATOR // when feature isn't disabled // these are debug logs made into consts #region Debug Logs @@ -20,6 +22,9 @@ public static class SingletonsEditor " Please use CreateScriptableSingletonAsset attribute to use this functionality. \n"; #endregion + + + const string CREATE_SINGLETON_ASSET_PATH = BASE_PATH + "Create Scriptable Singleton Assets"; /// /// Create ScriptableSingleton assets for all classes that has a @@ -94,6 +99,9 @@ private static bool CreateScriptableSingletonAsset(Type type) // return true indicating that the process was successful return true; } + + #endif + #endregion } } diff --git a/Editor/com.hibzz.singletons.editor.asmdef b/Editor/com.hibzz.singletons.editor.asmdef index 33db1a8..f772297 100644 --- a/Editor/com.hibzz.singletons.editor.asmdef +++ b/Editor/com.hibzz.singletons.editor.asmdef @@ -2,7 +2,8 @@ "name": "com.hibzz.singletons.editor", "rootNamespace": "Hibzz.Singletons.Editor", "references": [ - "GUID:b2fef9eae29790340a713d8578864b00" + "GUID:b2fef9eae29790340a713d8578864b00", + "GUID:b844f493a2cd07b4cbf81917a23ac063" ], "includePlatforms": [ "Editor" diff --git a/Scripts/Attributes/CreateScriptableSingletonAssetAttribute.cs b/Scripts/Attributes/CreateScriptableSingletonAssetAttribute.cs index b2cb436..3ca6911 100644 --- a/Scripts/Attributes/CreateScriptableSingletonAssetAttribute.cs +++ b/Scripts/Attributes/CreateScriptableSingletonAssetAttribute.cs @@ -1,9 +1,11 @@ using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; + +// as long as the scriptable singleton asset creator isn't disabled +#if !DISABLE_SCRIPTABLE_SINGLETON_CREATOR namespace Hibzz.Singletons { public class CreateScriptableSingletonAssetAttribute : Attribute { } } + +#endif