Selecting a Transform any other way than clicking it in the hierarchy, leads to wrong results when range selecting afterwards
i-xt opened this issue · 3 comments
Description of the bug
When a Transform is selected without clicking it's field in the hierarchy (either by calling RuntimeHierarchy.Select()
or by enabling RuntimeHierarchy.syncSelectionWithEditorHierarchy
and clicking the GameObject in Unity's hierarchy) RuntimeHierarchy.multiSelectionPivotTransform
and RuntimeHierarchy.multiSelectionPivotSceneData
are not set. As a result, the wrong items are selected when range selecting afterwards, without clicking another item in the hierarchy first.
Reproduction steps
The easiest way to reproduce this is to use the syncSelectionWithEditorHierarchy option.
- Set
RuntimeHierarchy.syncSelectionWithEditorHierarchy
andRuntimeHierarchy.m_allowMultiSelection
to true - Start play mode
- Select an item in the runtime hierarchy
- Select an item in Unity's hierarchy
- Range select another item in the runtime hierarchy
Result: The items between the one that was selected in step 3 and the one that was selected in step 5 get selected.
Expected result: The items between the one that was selected in step 4 and the one that was selected in step 5 get selected.
Platform specs
- Unity version: 2020.3.19f1
- Platform: Windows
- How did you download the plugin: Package Manager (GitHub)
Thank you for the detailed Issue. I've been working hard on other plugins for a long while (hopefully not for long now) so I couldn't take a look at most other Issues (including this). Will see what can be done about it. It won't be trivial because objects can appear in pseudo-scenes as well and they can also be filtered in RuntimeHierarchy.
What is the field/property that lets the hierarchy know which one is the last selected by clicking it in the hierarchy?
public List<HierarchyField> GetDrawers(Transform transform) =>
drawers.FindAll(val => val.Data.BoundTransform == transform);
public void TreatAsLastSelected(HierarchyField drawer)
{
lastClickTime = Time.realtimeSinceStartup;
lastClickedDrawer = drawer;
}
I tried adding this on RuntimeHierarchy.cs and then call it like this
var items = hierarchy.GetDrawers(list[list.Count - 1]);
if (items.Count > 0)
hierarchy.TreatAsLastSelected(items[items.Count - 1]);
but it seems like I got the wrong lastClickedDrawer? Still has the same behavior as the issue....
It's this one:
However, the hierarchy uses a recycled list view, meaning that only the visible Transforms' HierarchyFields are generated.
Here's how I had resolved this issue on another project. Note that line numbers may not match exactly: