yasirkula / UnityRuntimeInspector

Runtime Inspector and Hierarchy solution for Unity for debugging and runtime editing purposes
MIT License
1.76k stars 139 forks source link

Selecting a Transform any other way than clicking it in the hierarchy, leads to wrong results when range selecting afterwards #49

Closed i-xt closed 3 months ago

i-xt commented 2 years ago

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

yasirkula commented 2 years ago

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.

ReDarkTechnology commented 4 months ago

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....

yasirkula commented 4 months ago

It's this one: https://github.com/yasirkula/UnityRuntimeInspector/blob/52ff3168983d48f012119f6c013d7b495c9f44a4/Plugins/RuntimeInspector/Scripts/RuntimeHierarchy.cs#L824

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