-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default Values not used #175
Labels
bug
Something isn't working
Comments
Fixed it with the following:
[ListDrawerSettings(DefaultValueType = typeof(Config.Sound))]
public List<Config.Sound> Sounds = new List<Config.Sound>();
public class ListDrawerSettingsAttribute : Attribute
{
public bool Draggable { get; set; } = true;
public bool HideAddButton { get; set; }
public bool HideRemoveButton { get; set; }
public bool AlwaysExpanded { get; set; }
public bool ShowElementLabels { get; set; }
public Type DefaultValueType { get; set; } = null;
}
public class TriListElement : TriElement
{
//...
private Type _fixDefaultValueType = null;
//...
public TriListElement(TriProperty property)
{
// ...
_fixDefaultValueType = settings?.DefaultValueType ?? null;
}
//...
private void AddElementCallback(ReorderableList reorderableList, Object addedReferenceValue)
{
if (_property.TryGetSerializedProperty(out _))
{
ReorderableListProxy.DoAddButton(reorderableList, addedReferenceValue);
if (_fixDefaultValueType != null)
{
reorderableList.serializedProperty.GetArrayElementAtIndex(reorderableList.index).boxedValue = Activator.CreateInstance(_fixDefaultValueType);
}
_property.NotifyValueChanged();
return;
}
//...
} |
Found out that the Type is in _property.ArrayElementType, so I changed it to a boolean in the List settings if (_fixDefaultValue)
{
reorderableList.serializedProperty.GetArrayElementAtIndex(reorderableList.index).boxedValue = Activator.CreateInstance(_property.ArrayElementType);
} [ListDrawerSettings(FixDefaultValue = true)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I have a List and TableList of classes in a scriptable object and the default values of the class (ex.
public float Volume = 1f;
) is not being used. All values are 0.Expected behavior
When I add a new item to the list, it should have the default values as defined in the C# file.
Code Sample
Screenshots
Desktop: Windows 11
Unity version: 6000.0.22f1
Tri Inspector version: 1.14.1
The text was updated successfully, but these errors were encountered: