(Unity) Editor dropdown for SerializeReference Attribute. RefTo (Reference to SerializeReference).
- Select type for Serialize Reference
- Copy/Paste context menu
- Generic Serialize References
- RefTo type: References to Serialize Reference
- Keep Data with new type
- Fix cross references (WIP)
- Open source file
- Search Tool (WIP)
- Rider Integration (WIP)
- Check\Fix missing type (TODO)
- Indirect rename types (TODO)
WIP Features - available in preferences.
- Unity 2019+
- Unity 2023+
- Default UI Toolkit Inpsector
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.
- Select in UPM "Add package from git URL..."
- Install package with link.
https://github.com/AlexeyTaranov/SerializeReferenceDropdown.git
SRD_SelectType.mov
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;
}
SRD_CopyPaste.mov
You can use generics . Unspecified arguments need select in additional window.
Code Example
public class TestShapesForSRD : MonoBehaviour
{
[SerializeReference, SerializeReferenceDropdown]
private ISimpleGenericData<int> _intData;
}
public interface ISimpleGenericData<TData> : IAbstractData
{
public TData Data { get; }
}
[Serializable]
public class GenericData<TData> : ISimpleGenericData<TData>
{
[SerializeField] private TData _data;
public TData Data => _data;
}
[Serializable]
public class GenericKeyValuePair<TKeyData, TValueData> : ISimpleGenericData<TKeyData>, IAbstractData
{
[SerializeField] private TKeyData _key;
[SerializeField] private TValueData _value;
public TKeyData Data => _key;
}
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.
SRD_RefTo.mov
[SerializeField] private RefTo<IShape,MonoBehaviour> _refShape;
public void Execute()
{
var sampleString = _refShape.Get()?.ToString();
}
SRD_KeepData.mov
SRD_CrossReferences.mov
SRD_OpenSourceFile.mov
SRD_SearchTool_trim.mov
Rider plugin available here - https://github.com/AlexeyTaranov/SerializeReferenceDropdownIntegration