yasirkula/UnityRuntimeInspector

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

i-xt commented

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.

  1. Set RuntimeHierarchy.syncSelectionWithEditorHierarchy and RuntimeHierarchy.m_allowMultiSelection to true
  2. Start play mode
  3. Select an item in the runtime hierarchy
  4. Select an item in Unity's hierarchy
  5. 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.

2021-12-20-13-45-05

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:

void IListViewAdapter.OnItemClicked( RecycledListItem item )

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:

image