Added FieldLabelFrom attribute
This commit is contained in:
parent
52ee51c61c
commit
81bac32538
3
Editor/Predrawers.meta
Normal file
3
Editor/Predrawers.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b11bc545d74c48e4aaac5cd734c534a9
|
||||
timeCreated: 1638612721
|
||||
25
Editor/Predrawers/FieldLabelFromAttributeDrawer.cs
Normal file
25
Editor/Predrawers/FieldLabelFromAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(FieldLabelFromAttribute))]
|
||||
internal sealed class FieldLabelFromAttributeDrawer : PredrawerModifierPropertyDrawer
|
||||
{
|
||||
public override void Modify(PredrawerModifierPropertyAttribute attribute, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var att = (FieldLabelFromAttribute)attribute;
|
||||
SerializedProperty sp = property.GetRelativeProperty(att.fieldName);
|
||||
|
||||
if (sp == null)
|
||||
return;
|
||||
|
||||
string str = sp.GetValueAsString();
|
||||
|
||||
if (att.nicify)
|
||||
str = ObjectNames.NicifyVariableName(str);
|
||||
|
||||
label.text = str;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Predrawers/FieldLabelFromAttributeDrawer.cs.meta
Normal file
3
Editor/Predrawers/FieldLabelFromAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 30eda277627d4bca8ddce716ef21b657
|
||||
timeCreated: 1638612733
|
||||
3
Runtime/Predrawers.meta
Normal file
3
Runtime/Predrawers.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 968b630d4caa4605886ae1c1d7f3bdd8
|
||||
timeCreated: 1638612567
|
||||
23
Runtime/Predrawers/FieldLabelFromAttribute.cs
Normal file
23
Runtime/Predrawers/FieldLabelFromAttribute.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
|
||||
namespace Module.Inspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
public sealed class FieldLabelFromAttribute : PredrawerModifierPropertyAttribute
|
||||
{
|
||||
public readonly string fieldName;
|
||||
public readonly bool nicify;
|
||||
|
||||
public FieldLabelFromAttribute(string fieldName)
|
||||
{
|
||||
this.fieldName = fieldName;
|
||||
nicify = true;
|
||||
}
|
||||
|
||||
public FieldLabelFromAttribute(string fieldName, bool nicify)
|
||||
{
|
||||
this.fieldName = fieldName;
|
||||
this.nicify = nicify;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Runtime/Predrawers/FieldLabelFromAttribute.cs.meta
Normal file
3
Runtime/Predrawers/FieldLabelFromAttribute.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b3ebd4bca514492f87bc5660d98a1a6c
|
||||
timeCreated: 1638612604
|
||||
Loading…
Reference in a new issue