A complete serializer for Unity3D based on Unity3D serializer.
T[][]
Dictionary
record
T?
Lazy
Guid
TimeSpan
DateTime
or your own type.
- OpenUPM: follow the instrustions on OpenUPM
- or Unity Package: download packages of both AnyProcessor and AnySerialize in release page and import them into Unity project.
Use AnySerializeAttribute
for any property need to be serialized and edit in inspector.
public class MyComponent : MonoBehaviour
{
[AnySerialize] public Dictionary<int, Lazy<Dictionary<Guid, TimeSpan>>> Value { get; }
}
// custom serializable value type
[Serializable]
public class AnyGuid :
IReadOnlyAny<Guid>, // IReadOnlyAny<T> for readonly property (get only)
IAny<Guid> // IAny<T> for read-write property (get and set)
{
[SerializeField] private string _guid; // unity serialize field
public Guid Value
{
get => Guid.Parse(_guid); // convert serialize field to output value
set => _guid = value.ToString(); // convert output value to serialize field
}
}
// custom serializable container type
[Serializable]
// use AnyConstraintTypeAttribute on generic parameter to automatically find type by its constraint
// e.g. T is int, then TAny will be replaced by AnyValue_Int32
public class ReadOnlyAnyList<T, [AnyConstraintType] TAny>
: IReadOnlyAny<List<T>>
where TAny : IReadOnlyAny<T>
{
[SerializeField] private List<TAny> _value = default!;
public List<T> Value => _value.Select(v => v.Value);
}