-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# CHANGED - Package version increased to v1.1.0 # ADDED - Added configuration option for whitelisting assemblies on GenesisSettings. This is an recommended feature for data providers to optionally limit which assemblies are searched via reflection. - Added new overloads to ReflectionTools to make it easier to search via reflection using a whitelist of assemblies. # FIXED - Modified assertion for TypeExtensions where wrong Type was being checked as interface - Mitigated inspector performance issue for CodeGeneratorConfigDrawer that was causing CPU and GC spikes every editor frame. REMOVED - Removed unused methods GetRealTypeName and GetEnumName in ReflectionTools
- Loading branch information
Showing
11 changed files
with
530 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
namespace JCMG.Genesis.Editor | ||
{ | ||
/// <summary> | ||
/// A configuration for enabling user customization of assemblies to search for types via reflection. | ||
/// </summary> | ||
public sealed class AssembliesConfig : AbstractConfigurableConfig | ||
{ | ||
/// <summary> | ||
/// Returns true if reflection-based logic should only search types in <see cref="WhiteListedAssemblies"/>, | ||
/// otherwise false. | ||
/// </summary> | ||
public bool DoUseWhitelistOfAssemblies | ||
{ | ||
get | ||
{ | ||
var value = _settings.GetOrSetValue(DO_USE_WHITE_LIST_KEY, DEFAULT_DO_USE_WHITE_LIST_VALUE).ToLower(); | ||
|
||
// If for some reason we can't parse this bool, default to false for white-listing. | ||
if(!bool.TryParse(value, out var result)) | ||
{ | ||
result = false; | ||
} | ||
|
||
return result; | ||
} | ||
set | ||
{ | ||
_settings.SetValue(DO_USE_WHITE_LIST_KEY, value.ToString().ToLower()); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// An array of assemblies white-listed for use in reflection; only types from these assemblies will be searched | ||
/// if <see cref="DoUseWhitelistOfAssemblies"/> is true. | ||
/// </summary> | ||
public string[] WhiteListedAssemblies | ||
{ | ||
get | ||
{ | ||
return _settings.GetOrSetValue(WHITE_LIST_ASSEMBLIES_KEY, DEFAULT_ASSEMBLIES_VALUE).ArrayFromCSV(); | ||
} | ||
set | ||
{ | ||
_settings.SetValue(WHITE_LIST_ASSEMBLIES_KEY, value.ToCSV()); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Used for UI | ||
/// </summary> | ||
internal string RawWhiteListedAssemblies | ||
{ | ||
get { return _settings.GetOrSetValue(WHITE_LIST_ASSEMBLIES_KEY, DEFAULT_ASSEMBLIES_VALUE); } | ||
set { _settings.SetValue(WHITE_LIST_ASSEMBLIES_KEY, value); } | ||
} | ||
|
||
// Keys | ||
private const string DO_USE_WHITE_LIST_KEY = "Genesis.DoUseWhiteListedAssemblies"; | ||
private const string WHITE_LIST_ASSEMBLIES_KEY = "Genesis.WhiteListedAssemblies"; | ||
|
||
// Defaults | ||
private const string DEFAULT_DO_USE_WHITE_LIST_VALUE = "false"; | ||
private const string DEFAULT_ASSEMBLIES_VALUE = "Assembly-CSharp, Assembly-CSharp-Editor"; | ||
|
||
/// <summary>Configures preferences</summary> | ||
/// <param name="settings"></param> | ||
public override void Configure(GenesisSettings settings) | ||
{ | ||
base.Configure(settings); | ||
|
||
settings.SetIfNotPresent(DO_USE_WHITE_LIST_KEY, DEFAULT_DO_USE_WHITE_LIST_VALUE); | ||
settings.SetIfNotPresent(WHITE_LIST_ASSEMBLIES_KEY, DEFAULT_ASSEMBLIES_VALUE); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using UnityEditor; | ||
|
||
namespace JCMG.Genesis.Editor | ||
{ | ||
internal sealed class AssembliesConfigDrawer : AbstractSettingsDrawer | ||
{ | ||
/// <summary> | ||
/// The display title for this drawer | ||
/// </summary> | ||
public override string Title => TITLE; | ||
|
||
private readonly AssembliesConfig _config; | ||
|
||
// UI | ||
private const string TITLE = "Assemblies"; | ||
private const string DO_USE_WHITE_LIST_LABEL = "Do Use Whitelist"; | ||
private const string DO_USE_WHITE_LIST_DESCRIPTION = "If enabled, searching via reflection for Data Providers " + | ||
"will be limited to the array of assemblies below. Otherwise " + | ||
"all loaded assemblies will be searched."; | ||
|
||
private const string ASSEMBLY_WHITE_LIST_LABEL = "Assembly Whitelist"; | ||
private const string ASSEMBLY_WHITE_LIST_DESCRIPTION = "The comma delimited array of assemblies that searching " + | ||
"via reflection for Data Providers should be limited to."; | ||
|
||
public AssembliesConfigDrawer() | ||
{ | ||
_config = new AssembliesConfig(); | ||
} | ||
|
||
/// <summary>Initializes any setup for the drawer prior to rendering any GUI.</summary> | ||
/// <param name="settings"></param> | ||
public override void Initialize(GenesisSettings settings) | ||
{ | ||
base.Initialize(settings); | ||
|
||
_config.Configure(settings); | ||
} | ||
|
||
protected override void DrawContentBody(GenesisSettings settings) | ||
{ | ||
// Do Use white-list | ||
EditorGUILayout.HelpBox(DO_USE_WHITE_LIST_DESCRIPTION, MessageType.Info); | ||
using (new EditorGUILayout.HorizontalScope()) | ||
{ | ||
EditorGUILayout.LabelField(DO_USE_WHITE_LIST_LABEL); | ||
|
||
using (var scope = new EditorGUI.ChangeCheckScope()) | ||
{ | ||
var newValue = EditorGUILayout.Toggle(_config.DoUseWhitelistOfAssemblies); | ||
|
||
if (scope.changed) | ||
{ | ||
_config.DoUseWhitelistOfAssemblies = newValue; | ||
|
||
EditorUtility.SetDirty(settings); | ||
} | ||
} | ||
} | ||
|
||
// White-Listed Assemblies | ||
EditorGUILayout.HelpBox(ASSEMBLY_WHITE_LIST_DESCRIPTION, MessageType.Info); | ||
using (new EditorGUI.DisabledScope(!_config.DoUseWhitelistOfAssemblies)) | ||
{ | ||
using (new EditorGUILayout.HorizontalScope()) | ||
{ | ||
EditorGUILayout.LabelField(ASSEMBLY_WHITE_LIST_LABEL); | ||
|
||
using (var scope = new EditorGUI.ChangeCheckScope()) | ||
{ | ||
var newValue = EditorGUILayout.TextField(_config.RawWhiteListedAssemblies); | ||
|
||
if (scope.changed) | ||
{ | ||
_config.RawWhiteListedAssemblies = newValue; | ||
|
||
EditorUtility.SetDirty(settings); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.