(Unity) Editor tool for SerializeReference
(Unity) Editor tool for SerializeReference
Why?
Serialization: Objects referenced from SerializeReference fields now have stable ids, which reduces risk of conflicts when multiple users collaborate on a scene file. This also improves support for undo and prefabs, especially when SerializeReference is used inside arrays and lists. There is a new format for references, with backward compatibility support for older assets.
Serialization: SerializeReference now allow more granular handling of missing types. SerializeReference instances for which the type is missing will be replaced by null. Other instances will be editable and if fields who were previously referring to the missing type are still null the missing type will be preserved.
https://github.com/AlexeyTaranov/SerializeReferenceDropdown.githttps://github.com/user-attachments/assets/43a6446d-1b4c-48d4-ab4b-de53dd3ba6ab
Code Example
public class TestShapesForSRD : MonoBehaviour
{
[SerializeReferenceDropdown]
[SerializeReference]
private IShape _singleShape;
[SerializeReferenceDropdown]
[SerializeReference]
private IShape[] _shapesArray;
}
public interface IShape
{
}
[Serializable]
public class Circle : IShape
{
[SerializeField]
private float _radius;
}
[Serializable]
public class Rectangle : IShape
{
[SerializeField]
private float _sideA;
[SerializeField]
private float _sideB;
}https://github.com/user-attachments/assets/96cb3d58-b9c1-4874-8048-fc55442b4446
You can use generics . Unspecified arguments need select in additional window.
Code Example
…https://github.com/user-attachments/assets/aa641d95-ae4a-4e6c-92a3-4ec6554833de
https://github.com/user-attachments/assets/196cc3fe-0866-490c-99eb-14108a57f50f
https://github.com/user-attachments/assets/e7a5fe26-6df1-4c03-8688-a07b8219c41d
WIP: ScriptableObject - OK, everything else - broken.
Bug - https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-129100
You can modify type inside file - avoid Unity API. Perfect for fix missing references.
https://github.com/user-attachments/assets/e0c60c15-8619-4d29-a5c2-551eecb3b67a
This class support references to Serialize References! You can assign RefTo with Drag and Drop or with context menu.
Inspector will help avoid not to assign wrong object types, runtime type checks - "as operator" cast.
https://github.com/user-attachments/assets/10aceba6-89c5-4582-8038-315307d0be6c
[SerializeField] private RefTo _refShape;
public void Execute()
{
var sampleString = _refShape.Get()?.ToString();
} https://github.com/user-attachments/assets/fbf5460c-5ef8-4fde-b888-7943ac12378e
Rider plugin available here - https://github.com/AlexeyTaranov/SerializeReferenceDropdownIntegration
No open issues yet, or sync has not completed.