namespace Sandbox;
public abstract partial class SerializedProperty : IValid
{
///
/// Return a version of this property that can be customized for editor UI. You'll be able to change
/// things like display name and tooltip, and add extra attributes that control how editor controls interact with it.
///
public CustomizableSerializedProperty GetCustomizable()
{
return new CustomizableSerializedProperty( this );
}
///
/// A proxy around a SerializedProperty that allows overriding any property for UI customization.
/// Unset values fall through to the underlying property.
///
public class CustomizableSerializedProperty : Proxy
{
SerializedProperty _target;
protected override SerializedProperty ProxyTarget => _target;
public CustomizableSerializedProperty( SerializedProperty property )
{
_target = property;
}
// String properties
string _name;
public override string Name => _name ?? base.Name;
/// Override the property's internal name.
public void SetName( string value ) => _name = value;
string _displayName;
public override string DisplayName => _displayName ?? base.DisplayName;
/// Override the label shown in the inspector.
public void SetDisplayName( string value ) => _displayName = value;
string _description;
public override string Description => _description ?? base.Description;
/// Override the tooltip / description text.
public void SetDescription( string value ) => _description = value;
string _groupName;
public override string GroupName => _groupName ?? base.GroupName;
/// Override which inspector group this property appears in.
public void SetGroupName( string value ) => _groupName = value;
string _sourceFile;
public override string SourceFile => _sourceFile ?? base.SourceFile;
/// Override the reported source file path.
public void SetSourceFile( string value ) => _sourceFile = value;
// Nullable value types
int? _order;
public override int Order => _order ?? base.Order;
/// Override the sort order within the inspector.
public void SetOrder( int value ) => _order = value;
int? _sourceLine;
public override int SourceLine => _sourceLine ?? base.SourceLine;
/// Override the reported source line number.
public void SetSourceLine( int value ) => _sourceLine = value;
bool? _isEditable;
public override bool IsEditable => _isEditable ?? base.IsEditable;
/// Force the property to be editable or read-only.
public void SetIsEditable( bool value ) => _isEditable = value;
bool? _isPublic;
public override bool IsPublic => _isPublic ?? base.IsPublic;
/// Override the public visibility flag.
public void SetIsPublic( bool value ) => _isPublic = value;
bool? _isProperty;
public override bool IsProperty => _isProperty ?? base.IsProperty;
/// Override whether this appears as a property.
public void SetIsProperty( bool value ) => _isProperty = value;
bool? _isField;
public override bool IsField => _isField ?? base.IsField;
/// Override whether this appears as a field.
public void SetIsField( bool value ) => _isField = value;
bool? _isMethod;
public override bool IsMethod => _isMethod ?? base.IsMethod;
/// Override whether this appears as a method.
public void SetIsMethod( bool value ) => _isMethod = value;
bool? _hasChanges;
public override bool HasChanges => _hasChanges ?? base.HasChanges;
/// Override the dirty/changed flag.
public void SetHasChanges( bool value ) => _hasChanges = value;
bool? _isValid;
public override bool IsValid => _isValid ?? base.IsValid;
/// Override the validity flag.
public void SetIsValid( bool value ) => _isValid = value;
// Reference types
SerializedObject _parent;
public override SerializedObject Parent => _parent ?? base.Parent;
/// Override the parent SerializedObject.
public void SetParent( SerializedObject value ) => _parent = value;
Type _propertyType;
public override Type PropertyType => _propertyType ?? base.PropertyType;
/// Override the reported property type.
public void SetPropertyType( Type value ) => _propertyType = value;
// Attributes
List _extraAttributes;
/// Returns the underlying attributes merged with any added via .
public override IEnumerable GetAttributes()
{
var attrs = base.GetAttributes();
if ( _extraAttributes != null )
attrs = attrs.Concat( _extraAttributes );
return attrs;
}
/// Append an extra attribute visible to the editor and control widgets.
public void AddAttribute( Attribute attribute )
{
_extraAttributes ??= new();
_extraAttributes.Add( attribute );
}
}
}