1.9.0: Added support for attributes for drawing handles in the scene

This commit is contained in:
Anders Ejlersen 2024-02-11 22:02:10 +01:00
parent 81906d49dd
commit 5ce34bde70
48 changed files with 1354 additions and 8 deletions

View file

@ -76,6 +76,7 @@ namespace Module.Inspector.Editor.Utilities
var valueModifiers = new List<ResultValue<ValueModifierPropertyAttribute, ValueModifierPropertyDrawer>>(2);
var accessModifiers = new List<ResultValue<AccessModifierPropertyAttribute, AccessModifierPropertyDrawer>>(2);
var validators = new List<ResultValue<ValidatePropertyAttribute, ValidatePropertyDrawer>>(2);
var handleDrawers = new List<ResultValue<HandleDrawerPropertyAttribute, HandlePropertyDrawer>>(2);
object[] attributes = fieldInfo.GetCustomAttributes(false);
string tooltip = null;
var isObsolete = false;
@ -123,6 +124,13 @@ namespace Module.Inspector.Editor.Utilities
if (prop != null)
validators.Add(new ResultValue<ValidatePropertyAttribute, ValidatePropertyDrawer>(validator, prop));
}
else if (att is HandleDrawerPropertyAttribute handleDrawer)
{
var prop = InternalCreateInstanceOf<HandlePropertyDrawer>(handleDrawer);
if (prop != null)
handleDrawers.Add(new ResultValue<HandleDrawerPropertyAttribute, HandlePropertyDrawer>(handleDrawer, prop));
}
else if (att is TooltipAttribute attTooltip)
{
tooltip = attTooltip.tooltip;
@ -139,9 +147,9 @@ namespace Module.Inspector.Editor.Utilities
if (string.IsNullOrEmpty(obsoleteText))
{
if (tooltip != null)
tooltip += $"\n[Obsolete]";
tooltip += "\n[Obsolete]";
else
tooltip = $"[Obsolete]";
tooltip = "[Obsolete]";
}
else
{
@ -152,9 +160,9 @@ namespace Module.Inspector.Editor.Utilities
}
}
return new Result(drawer, predrawerModifiers, valueModifiers, accessModifiers, validators, tooltip, isObsolete);
return new Result(drawer, predrawerModifiers, valueModifiers, accessModifiers, validators, handleDrawers, tooltip, isObsolete);
}
private static T InternalCreateInstanceOf<T>(AbstractPropertyAttribute att) where T : AbstractPropertyDrawer
{
if (CACHED_ATT_TO_DRAWER.TryGetValue(att.GetType(), out Type drawerType))
@ -181,6 +189,7 @@ namespace Module.Inspector.Editor.Utilities
public readonly List<ResultValue<ValueModifierPropertyAttribute, ValueModifierPropertyDrawer>> valueModifiers;
public readonly List<ResultValue<AccessModifierPropertyAttribute, AccessModifierPropertyDrawer>> accessModifiers;
public readonly List<ResultValue<ValidatePropertyAttribute, ValidatePropertyDrawer>> validators;
public readonly List<ResultValue<HandleDrawerPropertyAttribute, HandlePropertyDrawer>> handleDrawers;
public readonly string tooltip;
public readonly bool isObsolete;
@ -189,6 +198,7 @@ namespace Module.Inspector.Editor.Utilities
List<ResultValue<ValueModifierPropertyAttribute, ValueModifierPropertyDrawer>> valueModifiers,
List<ResultValue<AccessModifierPropertyAttribute, AccessModifierPropertyDrawer>> accessModifiers,
List<ResultValue<ValidatePropertyAttribute, ValidatePropertyDrawer>> validators,
List<ResultValue<HandleDrawerPropertyAttribute, HandlePropertyDrawer>> handleDrawers,
string tooltip,
bool isObsolete)
{
@ -197,6 +207,7 @@ namespace Module.Inspector.Editor.Utilities
this.valueModifiers = valueModifiers;
this.accessModifiers = accessModifiers;
this.validators = validators;
this.handleDrawers = handleDrawers;
this.tooltip = tooltip;
this.isObsolete = isObsolete;
}
@ -244,6 +255,17 @@ namespace Module.Inspector.Editor.Utilities
return null;
}
public T GetHandleDrawer<T>() where T : HandleDrawerPropertyAttribute
{
for (var i = 0; i < handleDrawers.Count; i++)
{
if (handleDrawers[i].attribute is T att)
return att;
}
return null;
}
}
/// <summary>