diff --git a/Assets/NaughtyAttributes/Scripts/Core/MetaAttributes/VarLabelAttribute.cs b/Assets/NaughtyAttributes/Scripts/Core/MetaAttributes/VarLabelAttribute.cs new file mode 100644 index 00000000..92b64973 --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Core/MetaAttributes/VarLabelAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace NaughtyAttributes +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public class VarLabelAttribute : LabelAttribute + { + public VarLabelAttribute(string label) : base(label) + { + } + } +} \ No newline at end of file diff --git a/Assets/NaughtyAttributes/Scripts/Core/MetaAttributes/VarLabelAttribute.cs.meta b/Assets/NaughtyAttributes/Scripts/Core/MetaAttributes/VarLabelAttribute.cs.meta new file mode 100644 index 00000000..14b78208 --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Core/MetaAttributes/VarLabelAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 696e31e149d034914a4f52d7c70464c0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs b/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs index 2336eb66..02eb3a7f 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs @@ -29,9 +29,17 @@ public static T[] GetAttributes(SerializedProperty property) where T : class public static GUIContent GetLabel(SerializedProperty property) { LabelAttribute labelAttribute = GetAttribute(property); - string labelText = (labelAttribute == null) - ? property.displayName - : labelAttribute.Label; + string labelText = property.displayName; + + if(labelAttribute != null){ + labelText = labelAttribute.Label; + + if(labelAttribute is VarLabelAttribute) { + object target = GetTargetObjectWithProperty(property); + + labelText = GetVariableLabel(target, ((VarLabelAttribute)labelAttribute).Label); + } + } GUIContent label = new GUIContent(labelText); return label; @@ -224,6 +232,29 @@ internal static List GetConditionValues(object target, string[] conditions return conditionValues; } + internal static string GetVariableLabel(object target, string path) { + FieldInfo labelField = ReflectionUtility.GetField(target, path); + if(labelField != null && + labelField.FieldType == typeof(string)) { + return (string)labelField.GetValue(target); + } + + PropertyInfo labelProperty = ReflectionUtility.GetProperty(target, path); + if(labelProperty != null && + labelProperty.PropertyType == typeof(string)) { + return (string)labelProperty.GetValue(target); + } + + MethodInfo labelMethod = ReflectionUtility.GetMethod(target, path); + if(labelMethod != null && + labelMethod.ReturnType == typeof(string) && + labelMethod.GetParameters().Length == 0) { + return (string)labelMethod.Invoke(target, null); + } + + return "[label property not found]"; + } + internal static bool GetConditionsFlag(List conditionValues, EConditionOperator conditionOperator, bool invert) { bool flag;