I’m facing an issue with updating the selection status of items in my Odin Inspector drawer. Here’s the setup:
I have a class PrefabExplorerSlotListDrawer that extends TwoDimensionalArrayDrawer<TArray, PrefabExplorerSlot>, where TArray is a subclass of System.Collections.IList. Within this class, I’m managing a private variable selection of type PrefabExplorerSlot.
In the DrawElement method of this drawer class, I’m rendering a list of elements, each represented by a PrefabExplorerSlot. I aim to update the isSelected property of an item when it’s clicked. However, despite my attempts to update the isSelected property within the DrawElement method, the changes are not reflected outside of the drawer.
Here’s a snippet of the relevant code:
public class PrefabExplorerSlotListDrawer<TArray> : TwoDimensionalArrayDrawer<TArray, PrefabExplorerSlot> where TArray : System.Collections.IList
{
private PrefabExplorerSlot selection;
protected override TableMatrixAttribute GetDefaultTableMatrixAttributeSettings()
{
return new TableMatrixAttribute()
{
SquareCells = true,
HideColumnIndices = true,
HideRowIndices = true,
ResizableColumns = false
};
}
protected override PrefabExplorerSlot DrawElement(Rect rect, PrefabExplorerSlot item)
{
if (item.prefab != null)
{
var preview = AssetPreview.GetAssetPreview(item.prefab);
if (preview) GUI.DrawTexture(rect.Padding(2), AssetPreview.GetAssetPreview(item.prefab));
var editButtonRect = rect.Padding(2).AlignTop(16).AlignRight(16);
if (SirenixEditorGUI.IconButton(editButtonRect, EditorIcons.Crosshair, SirenixGUIStyles.MiniButton, "Open Inspector"))
{
Selection.activeGameObject = item.prefab;
}
if (selection.filePath == item.filePath)
{
Debug.Log(selection.name + "+/+" + item.name + "+/+" + item.isSelected);
item.isSelected = true;
SirenixEditorGUI.DrawBorders(rect, 1, Color.blue);
}
else
{
Debug.Log(selection.name + "-/-" + item.name + "-/-" + item.isSelected);
item.isSelected = false;
SirenixEditorGUI.DrawBorders(rect, 1);
}
if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
{
selection = item;
Event.current.Use();
}
}
return item;
}
protected override void DrawPropertyLayout(GUIContent label)
{
base.DrawPropertyLayout(label);
}
}
In another script, I’m trying to access the isSelected property of each item in the tableViewData array. However, the changes made in the drawer are not reflected here.
[ShowInInspector, NonSerialized][DisableContextMenu]
public PrefabExplorerSlot[,] tableViewData;
var a = tableViewData;
for (int k = 0; k < a.GetLength(0); k++)
{
for (int l = 0; l < a.GetLength(1); l++)
{
var val = a[k, l];
if (val.isSelected)
Debug.Log(val.name);
}
}
I’d appreciate any insights or suggestions on how to properly update the selection status of items in the Odin Inspector drawer and ensure that changes are propagated correctly.
Thank you in advance for your help!