Added PredrawerModifier to help modify either SerializedProperty or GUIContent before drawing
This commit is contained in:
parent
6321fcc107
commit
e0fc2c1e05
7 changed files with 62 additions and 3 deletions
|
|
@ -37,7 +37,12 @@ namespace Module.Inspector.Editor.Utilities
|
|||
|
||||
for (var k = 0; k < arguments.Count; k++)
|
||||
{
|
||||
if (arguments[k].Value is Type argType)
|
||||
if (!(arguments[k].Value is Type argType))
|
||||
continue;
|
||||
|
||||
if (CACHED_ATT_TO_DRAWER.ContainsKey(argType))
|
||||
Debug.LogWarningFormat("Already contained {0}, but tried to add with {1} and already had {2}.", argType, type, CACHED_ATT_TO_DRAWER[argType]);
|
||||
else
|
||||
CACHED_ATT_TO_DRAWER.Add(argType, type);
|
||||
}
|
||||
}
|
||||
|
|
@ -67,6 +72,7 @@ namespace Module.Inspector.Editor.Utilities
|
|||
if (typeDrawer != null)
|
||||
drawer = new ResultValue<DrawerPropertyAttribute, DrawerPropertyDrawer>(null, typeDrawer);
|
||||
|
||||
var predrawerModifiers = new List<ResultValue<PredrawerModifierPropertyAttribute, PredrawerModifierPropertyDrawer>>(2);
|
||||
var valueModifiers = new List<ResultValue<ValueModifierPropertyAttribute, ValueModifierPropertyDrawer>>(2);
|
||||
var accessModifiers = new List<ResultValue<AccessModifierPropertyAttribute, AccessModifierPropertyDrawer>>(2);
|
||||
object[] attributes = fieldInfo.GetCustomAttributes(false);
|
||||
|
|
@ -88,6 +94,13 @@ namespace Module.Inspector.Editor.Utilities
|
|||
if (prop != null)
|
||||
drawer = new ResultValue<DrawerPropertyAttribute, DrawerPropertyDrawer>(attDrawer, prop);
|
||||
}
|
||||
else if (att is PredrawerModifierPropertyAttribute predawerModifier)
|
||||
{
|
||||
var prop = InternalCreateInstanceOf<PredrawerModifierPropertyDrawer>(predawerModifier);
|
||||
|
||||
if (prop != null)
|
||||
predrawerModifiers.Add(new ResultValue<PredrawerModifierPropertyAttribute, PredrawerModifierPropertyDrawer>(predawerModifier, prop));
|
||||
}
|
||||
else if (att is ValueModifierPropertyAttribute valueModifier)
|
||||
{
|
||||
var prop = InternalCreateInstanceOf<ValueModifierPropertyDrawer>(valueModifier);
|
||||
|
|
@ -121,7 +134,7 @@ namespace Module.Inspector.Editor.Utilities
|
|||
tooltip = $"Obsolete: {obsoleteText}";
|
||||
}
|
||||
|
||||
return new Result(drawer, valueModifiers, accessModifiers, tooltip, isObsolete);
|
||||
return new Result(drawer, predrawerModifiers, valueModifiers, accessModifiers, tooltip, isObsolete);
|
||||
}
|
||||
|
||||
private static T InternalCreateInstanceOf<T>(AbstractPropertyAttribute att) where T : AbstractPropertyDrawer
|
||||
|
|
@ -146,23 +159,37 @@ namespace Module.Inspector.Editor.Utilities
|
|||
public sealed class Result
|
||||
{
|
||||
public readonly ResultValue<DrawerPropertyAttribute, DrawerPropertyDrawer> draw;
|
||||
public readonly List<ResultValue<PredrawerModifierPropertyAttribute, PredrawerModifierPropertyDrawer>> predrawerModifiers;
|
||||
public readonly List<ResultValue<ValueModifierPropertyAttribute, ValueModifierPropertyDrawer>> valueModifiers;
|
||||
public readonly List<ResultValue<AccessModifierPropertyAttribute, AccessModifierPropertyDrawer>> accessModifiers;
|
||||
public readonly string tooltip;
|
||||
public readonly bool isObsolete;
|
||||
|
||||
public Result(ResultValue<DrawerPropertyAttribute, DrawerPropertyDrawer> draw,
|
||||
List<ResultValue<PredrawerModifierPropertyAttribute, PredrawerModifierPropertyDrawer>> predrawerModifiers,
|
||||
List<ResultValue<ValueModifierPropertyAttribute, ValueModifierPropertyDrawer>> valueModifiers,
|
||||
List<ResultValue<AccessModifierPropertyAttribute, AccessModifierPropertyDrawer>> accessModifiers,
|
||||
string tooltip,
|
||||
bool isObsolete)
|
||||
{
|
||||
this.draw = draw;
|
||||
this.predrawerModifiers = predrawerModifiers;
|
||||
this.valueModifiers = valueModifiers;
|
||||
this.accessModifiers = accessModifiers;
|
||||
this.tooltip = tooltip;
|
||||
this.isObsolete = isObsolete;
|
||||
}
|
||||
|
||||
public T GetPredrawerModifier<T>() where T : PredrawerModifierPropertyAttribute
|
||||
{
|
||||
for (var i = 0; i < predrawerModifiers.Count; i++)
|
||||
{
|
||||
if (predrawerModifiers[i].attribute is T att)
|
||||
return att;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public T GetValueModifier<T>() where T : ValueModifierPropertyAttribute
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue