Skip to content

Commit

Permalink
fix: rect selections are broken by previews
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Oct 14, 2024
1 parent 3d04a63 commit 97e930e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
mode)
- [#441] Fixed an issue where the preview object pickable status could get out of sync with the original
- [#444] Fixed an issue where the preview system broke drag-and-drop of materials onto the scene view
- [#444] Fixed an issue where the preview system broke drag-to-select in the scene view

### Changed
- [#451] Changed preview system to apply to more cameras. Specifically, we now handle all cameras with no render
Expand Down
32 changes: 32 additions & 0 deletions Editor/Harmony/HandleUtilityPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ internal static void Patch_FilterInstanceIDs(Harmony h)
new HarmonyMethod(m_prefix_internal_getclosestpickingid),
new HarmonyMethod(m_postfix_internal_getclosestpickingid)
);

var m_internal_pickrectobjects = AccessTools.Method(t_HandleUtility, "Internal_PickRectObjects");
var m_postfix_internal_pickrectobjects = AccessTools.Method(typeof(HandleUtilityPatches),
nameof(Postfix_Internal_PickRectObjects));

h.Patch(
m_internal_pickrectobjects,
postfix: new HarmonyMethod(m_postfix_internal_pickrectobjects)
);
}

private static readonly Type ty_PickingObject = AccessTools.TypeByName("UnityEditor.PickingObject");
Expand Down Expand Up @@ -167,6 +176,29 @@ ref uint __result
}
}

[UsedImplicitly]
private static void Postfix_Internal_PickRectObjects(
Camera cam,
Rect rect,
bool selectPrefabRoots,
bool drawGizmos,
ref GameObject[] __result
)
{
if (__result == null) return;

var sess = PreviewSession.Current;
if (sess == null) return;

for (var i = 0; i < __result.Length; i++)
{
if (sess.ProxyToOriginalObject.TryGetValue(__result[i], out var original) && original != null)
{
__result[i] = original;
}
}
}

[UsedImplicitly]
private static bool Prefix_FilterInstanceIDs(
ref IEnumerable<GameObject> gameObjects,
Expand Down

0 comments on commit 97e930e

Please sign in to comment.