Skip to content

Commit dad8b78

Browse files
RogPodgekeveleigh
authored andcommitted
Fixed cases where bounds control would aggressively remove other components (#10296)
* fixed cases where bounds control would aggressively remove other components * slight revision * removed bounds control's forced addition of the Near Interaction Grabbable, added editor scripts to support the new pattern where the bounds control does not own it's associated bounding box
1 parent 88de6f9 commit dad8b78

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

Assets/MRTK/SDK/Editor/Inspectors/UX/BoundsControl/BoundsControlInspector.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,33 @@ public override void OnInspectorGUI()
116116
{
117117
EditorGUI.BeginChangeCheck();
118118

119+
// Initializes the target object of the bounds control to itself
119120
EditorGUILayout.PropertyField(targetObject);
121+
if (targetObject.objectReferenceValue == null)
122+
{
123+
targetObject.objectReferenceValue = boundsControl.gameObject;
124+
}
125+
126+
// Checks that the targetObject has a box collider that this bounds control can manage if bounds override was not supplied, otherwise, raises a warning and prompts the user to add one
127+
if (boundsOverride.objectReferenceValue == null)
128+
{
129+
GameObject boundsTargetObject = targetObject.objectReferenceValue as GameObject;
130+
if (boundsTargetObject != null && boundsTargetObject.GetComponent<BoxCollider>() == null)
131+
{
132+
EditorGUILayout.HelpBox("No Box Collider assigned to the TargetObject and no Bounds Override assigned, add a Box Collider to enable proper interaction with the Bounds Control", MessageType.Warning);
133+
134+
if (GUILayout.Button("Add Box Collider to Target Object"))
135+
{
136+
boundsTargetObject.AddComponent<BoxCollider>();
137+
}
138+
}
139+
}
120140

121141
EditorGUILayout.Space();
122142
EditorGUILayout.LabelField(new GUIContent("Behavior"), EditorStyles.boldLabel);
123143
EditorGUILayout.PropertyField(activationType);
124144
EditorGUILayout.PropertyField(boundsOverride);
145+
125146
EditorGUILayout.PropertyField(boundsCalculationMethod);
126147
EditorGUILayout.PropertyField(controlPadding);
127148
EditorGUILayout.PropertyField(flattenAxis);

Assets/MRTK/SDK/Features/UX/Scripts/BoundsControl/BoundsControl.cs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -836,13 +836,7 @@ private void DetermineTargetBounds()
836836
}
837837
else
838838
{
839-
// first remove old collider if there is any so we don't accumulate any
840-
// box padding on consecutive calls of this method
841-
if (TargetBounds != null)
842-
{
843-
Destroy(TargetBounds);
844-
}
845-
TargetBounds = Target.AddComponent<BoxCollider>();
839+
TargetBounds = Target.EnsureComponent<BoxCollider>();
846840
Bounds bounds = GetTargetBounds();
847841

848842
TargetBounds.center = bounds.center;
@@ -862,8 +856,6 @@ private void DetermineTargetBounds()
862856
}
863857

864858
TargetBounds.size += Vector3.Scale(boxPadding, scale);
865-
866-
TargetBounds.EnsureComponent<NearInteractionGrabbable>();
867859
}
868860

869861
private readonly List<Transform> childTransforms = new List<Transform>();
@@ -1096,27 +1088,12 @@ private void DropController()
10961088

10971089
private void DestroyRig()
10981090
{
1099-
if (boundsOverride == null)
1091+
// If we have previously logged an initial bounds size,
1092+
// reset the boundsOverride BoxCollider to the initial size.
1093+
// This is because the CalculateBoxPadding
1094+
if (initialBoundsOverrideSize.HasValue)
11001095
{
1101-
Destroy(TargetBounds);
1102-
}
1103-
else
1104-
{
1105-
// If we have previously logged an initial bounds size,
1106-
// reset the boundsOverride BoxCollider to the initial size.
1107-
// This is because the CalculateBoxPadding
1108-
if (initialBoundsOverrideSize.HasValue)
1109-
{
1110-
boundsOverride.size = initialBoundsOverrideSize.Value;
1111-
}
1112-
1113-
if (TargetBounds != null)
1114-
{
1115-
if (TargetBounds.gameObject.GetComponent<NearInteractionGrabbable>())
1116-
{
1117-
Destroy(TargetBounds.gameObject.GetComponent<NearInteractionGrabbable>());
1118-
}
1119-
}
1096+
boundsOverride.size = initialBoundsOverrideSize.Value;
11201097
}
11211098

11221099
// todo: move this out?
@@ -1127,7 +1104,6 @@ private void DestroyRig()
11271104
Destroy(rigRoot.gameObject);
11281105
rigRoot = null;
11291106
}
1130-
11311107
}
11321108

11331109
private void UpdateRigVisibilityInInspector()

0 commit comments

Comments
 (0)