public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        CustomLabelAttribute customLabel = (CustomLabelAttribute)attribute;

        label.text = customLabel.label;
        EditorGUI.PropertyField(position, property, label);
    }
Exemple #2
0
		private string GetText(SerializedProperty property, CustomLabelAttribute labelAttribute)
		{
			if (!string.IsNullOrEmpty(labelAttribute.Resolve))
			{
				var method = fieldInfo.DeclaringType.GetMethod(labelAttribute.Resolve, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				var field = fieldInfo.DeclaringType.GetField(labelAttribute.Resolve, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				var prop = fieldInfo.DeclaringType.GetProperty(labelAttribute.Resolve, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

				if (method != null)
				{
					var owner = method.IsStatic ? null : property.GetOwner<object>();

					if (method.ReturnType != typeof(string))
						Debug.LogWarningFormat(_invalidMethodReturnWarning, property.propertyPath, labelAttribute.Resolve);
					else if (method.HasSignature(null))
						Debug.LogWarningFormat(_invalidMethodParametersWarning, property.propertyPath, labelAttribute.Resolve);
					else
						return (string)method.Invoke(owner, null);
				}
				else if (field != null)
				{
					if (field.FieldType != typeof(string))
						Debug.LogWarningFormat(_invalidFieldReturnWarning, property.propertyPath, labelAttribute.Resolve, property.type);
					else
						return (string)field.GetValue(field.IsStatic ? null : property.GetOwner<object>());
				}
				else if (prop != null)
				{
					if (prop.PropertyType != typeof(string) || !prop.CanRead)
						Debug.LogWarningFormat(_invalidPropertyReturnWarning, property.propertyPath, labelAttribute.Resolve, property.type);
					else
						return (string)prop.GetValue(prop.GetGetMethod().IsStatic ? null : property.GetOwner<object>());
				}
				else
				{
					Debug.LogWarningFormat(_missingMethodWarning, property.propertyPath, labelAttribute.Resolve, fieldInfo.DeclaringType.Name);
				}
			}

			return labelAttribute.Label;
		}