Skip to content

[Feature Request] Support for Object wrappers #124

@LucasOCastro

Description

@LucasOCastro

Sometimes I want to use an attribute, but I wish to apply it onto a field of the serialized field's type, instead of the serialized field itself. Here's an example:

public interface IObjectWrapper
{
    Object WrappedObject { get; }
}

public class SerializedInterface<TInterface> : IObjectWrapper
{
    [SerializeField] privare Object _underlyingValue;
    Object IObjectWrapper.WrappedObject => _underlyingValue;
    //...
}

public class MyScript : MonoBehaviour
{
    [SerializeField, NotNull]
    private SerializedInterface<MyInterface> _requiredInterface;
    [SerializeField]
    private SerializedInterface<MyInterface> _nonRequiredInterface;
    // _requiredInterface's drawer will be annotated with the "Variable has to be assigned" message when it's _underlyingValue is not set.
}

From my understanding, something like this is not achievable with the current structure, unless applying the NotNull attribute directly to the _underlyingValue inside SerializedInterface.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions