Awesome
ChoiceReferenceAttribute
This package allows you to use the [ChoiceReference] attribute to make a popup interaction to select a subclass from which the base class that you specified as the field type inherits. Lists and arrays are also supported, as is the fact that this attribute will be used again in subclasses.
Add to project
To add this package to the project, follow these steps:
- Open PackageManager;
- Select "Add package from get URL";
- Insert links to packages that are dependencies of this package:
https://github.com/Paulsams/MiscUtilities.git
- Insert this link
https://github.com/Paulsams/ChoiceReferenceAttribute.git
Related Packages
- RepairerSerializeReferences (so far only from 2021.2) - an editor window that allows you to fix links that flew due to a change in the name of the class, namespace, or assembly: https://github.com/Paulsams/RepairerSerializeReferences
Dependencies
- Is using:
- MicsUtilities: https://github.com/Paulsams/MiscUtilities.git
Known Issues
- When editing objects multiple times and pressing the
-
button on a sheet/array (and only if this is not an SR array, but they are nested through other classes), errors may appear. There are no ideas yet, since the messages don’t even have a stack trace, but otherwise multiple editing works correctly.
Opportunities
- Works for lists/array and for any nesting of this attribute;
IMPORTANT: In order for the attribute to work for lists/array, it is necessary to add [System.Serializable]
to the base class. Don't ask me why - that's life:
[SerializeReference, ChoiceReference] private BaseClass _singleChoiceReference;
[SerializeReference, ChoiceReference] private List<BaseClass> _listChoiceReferences;
![image](Documentation~/Single and Lists.gif)
- You can specify the nullable flag in the parameters attribute, which allows you to remove the "null" state from the selection for the object. If it is "false" (and this is the default value), then you will still need to select the type for the first time, otherwise there would be recursion if there is a field with the same attribute in the object.
[SerializeReference, ChoiceReference(true)] private BaseClass _singleChoiceReferenceNullable;
[SerializeReference, ChoiceReference] private BaseClass _singleChoiceReferenceNotNullable;
- ISerializeReferenceChangeValidate - an interface that you can implement at the heir in order to make some kind of check that the Type change is valid at the moment.
- When you click on
+
for lists, serialize references (nested through an additional class) are not copied (I have not yet seen this in any implementation of field attributes); - Multiple object editing available.
Constructors
ChoiceReferenceAttribute(bool nullable)
Samples
To download the examples for this package:
- Select this package in PackageManager;
- Expand the "Samples" tab on the right;
- And click the "Import" button on the example you are interested in.