Add: OnInspectorDestroyAttribute

This commit is contained in:
AnnulusGames 2024-02-17 12:21:27 +09:00
parent 8e0d608191
commit 2401642ac8
2 changed files with 19 additions and 4 deletions

View File

@ -28,10 +28,10 @@ namespace Alchemy.Editor
{ {
foreach (var target in targets) foreach (var target in targets)
{ {
foreach (var onEnableMethod in ReflectionHelper.GetAllMethodsIncludingBaseNonPublic(target.GetType()) foreach (var method in ReflectionHelper.GetAllMethodsIncludingBaseNonPublic(target.GetType())
.Where(x => x.HasCustomAttribute<OnInspectorEnableAttribute>())) .Where(x => x.HasCustomAttribute<OnInspectorEnableAttribute>()))
{ {
onEnableMethod.Invoke(target, null); method.Invoke(target, null);
} }
} }
} }
@ -40,10 +40,22 @@ namespace Alchemy.Editor
{ {
foreach (var target in targets) foreach (var target in targets)
{ {
foreach (var onEnableMethod in ReflectionHelper.GetAllMethodsIncludingBaseNonPublic(target.GetType()) foreach (var method in ReflectionHelper.GetAllMethodsIncludingBaseNonPublic(target.GetType())
.Where(x => x.HasCustomAttribute<OnInspectorDisableAttribute>())) .Where(x => x.HasCustomAttribute<OnInspectorDisableAttribute>()))
{ {
onEnableMethod.Invoke(target, null); method.Invoke(target, null);
}
}
}
void OnDestroy()
{
foreach (var target in targets)
{
foreach (var method in ReflectionHelper.GetAllMethodsIncludingBaseNonPublic(target.GetType())
.Where(x => x.HasCustomAttribute<OnInspectorDestroyAttribute>()))
{
method.Invoke(target, null);
} }
} }
} }

View File

@ -194,4 +194,7 @@ namespace Alchemy.Inspector
[AttributeUsage(AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Method)]
public sealed class OnInspectorDisableAttribute : Attribute { } public sealed class OnInspectorDisableAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Method)]
public sealed class OnInspectorDestroyAttribute : Attribute { }
} }