Skip to content

Commit e7edb4d

Browse files
authored
Merge pull request #136 from brunomikoski/feature/item-indices
Feature/item indices
2 parents 1bbaad8 + 0e49ca9 commit e7edb4d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Scripts/Runtime/Core/ScriptableObjectCollectionItem.cs

+15
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ public ScriptableObjectCollection Collection
5151
return cachedCollection;
5252
}
5353
}
54+
55+
[NonSerialized] private bool didCacheIndex;
56+
[NonSerialized] private int cachedIndex;
57+
public int Index
58+
{
59+
get
60+
{
61+
if (!didCacheIndex)
62+
{
63+
didCacheIndex = true;
64+
cachedIndex = Collection.Items.IndexOf(this);
65+
}
66+
return cachedIndex;
67+
}
68+
}
5469

5570
public void SetCollection(ScriptableObjectCollection collection)
5671
{

0 commit comments

Comments
 (0)