Skip to content

Commit

Permalink
Merge pull request #2 from hibzzgames/disable-scriptable-asset-creator
Browse files Browse the repository at this point in the history
Added option to disable Scriptable Singleton Asset Creator
  • Loading branch information
sliptrixx authored Jul 23, 2023
2 parents f07d84e + 4d8f1f0 commit d8fd413
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
38 changes: 38 additions & 0 deletions Editor/DefineRegistrant.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Used to register the defines
/// </summary>
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
11 changes: 11 additions & 0 deletions Editor/DefineRegistrant.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Editor/SingletonsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +22,9 @@ public static class SingletonsEditor
" Please use <i>CreateScriptableSingletonAsset</i> attribute to use this functionality. \n";

#endregion


const string CREATE_SINGLETON_ASSET_PATH = BASE_PATH + "Create Scriptable Singleton Assets";

/// <summary>
/// Create ScriptableSingleton assets for all classes that has a
Expand Down Expand Up @@ -94,6 +99,9 @@ private static bool CreateScriptableSingletonAsset(Type type)
// return true indicating that the process was successful
return true;
}

#endif
#endregion
}
}

Expand Down
3 changes: 2 additions & 1 deletion Editor/com.hibzz.singletons.editor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "com.hibzz.singletons.editor",
"rootNamespace": "Hibzz.Singletons.Editor",
"references": [
"GUID:b2fef9eae29790340a713d8578864b00"
"GUID:b2fef9eae29790340a713d8578864b00",
"GUID:b844f493a2cd07b4cbf81917a23ac063"
],
"includePlatforms": [
"Editor"
Expand Down
8 changes: 5 additions & 3 deletions Scripts/Attributes/CreateScriptableSingletonAssetAttribute.cs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d8fd413

Please sign in to comment.