Skip to content

Commit

Permalink
Make skipping layout elements an option
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Jun 14, 2024
1 parent 3111ad6 commit 2148cdd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions BoundedUIX/SelectableUIXConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ namespace BoundedUIX
{
internal sealed class SelectableUIXConfig : ConfigSection
{
private readonly DefiningConfigKey<bool> _allowLayoutSelectionKey = new("AllowLayoutSelection", "Allow selecting UIX RectTransforms that don't have any visual elements on them. Helps when wanting to select layout parents using repeated selection.", () => true);
private readonly DefiningConfigKey<bool> _ignoreAlreadySelectedKey = new("IgnoreAlreadySelected", "Skip already selected elements in the targeting process. Helps with layered elements.", () => true);
private readonly DefiningConfigKey<bool> _prioritizeHierarchyDepthKey = new("PrioritizeHierarchyDepth", "Prioritize the hierarchy depth of a potentially hit RectTransform over the layout order. Can help instead of or in addition to skipping already selected elements.", () => false);
private readonly DefiningConfigKey<float> _repeatSelectionThresholdKey = new("RepeatSelectionThreshold", "The minimum local distance between targeting hits to consider it a 'new' selection attempt. Works in tandem with IgnoreAlreadySelected. Increase for more leniency. May need to be adjusted depending on the item.", () => 15, valueValidator: value => value >= 0);
public bool AllowLayoutSelection => _allowLayoutSelectionKey.GetValue();

public override string Description => "Options for selecting UIX Elements with the Developer Tool.";

public override string Id => "SelectableUIX";

public bool IgnoreAlreadySelected => _ignoreAlreadySelectedKey.GetValue();
Expand Down
3 changes: 2 additions & 1 deletion BoundedUIX/UIXSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private static Slot CheckCanvas(RaycastHit hit)
private static Slot FindBestRect(float2 hitPoint, Slot best)
{
var prioritizeDepth = ConfigSection.PrioritizeHierarchyDepth;
var allowLayoutSelection = ConfigSection.AllowLayoutSelection;

var ignoreSelected = ConfigSection.IgnoreAlreadySelected && _lastSlot == best
&& (MathX.Distance(_lastPosition, hitPoint) < ConfigSection.RepeatSelectionThreshold);
Expand All @@ -61,7 +62,7 @@ private static Slot FindBestRect(float2 hitPoint, Slot best)
var isHit = rectTransform.GetCanvasBounds().Contains(hitPoint);
var hasGraphic = rectTransform.Graphic != null;

if (isHit && hasGraphic && (!rectTransform.IsMask || rectTransform.IsMaskVisible) // Has anything possibly visible in the bounds
if (isHit && (allowLayoutSelection || (hasGraphic && (!rectTransform.IsMask || rectTransform.IsMaskVisible))) // Has anything possibly visible in the bounds
&& (!prioritizeDepth || best.HierachyDepth <= current.HierachyDepth)) // Hierarchy depth at least as deep when prioritizing
best = current;

Expand Down

0 comments on commit 2148cdd

Please sign in to comment.