Skip to content

Commit

Permalink
Allow Variable Bounding Box Handle Sizes (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
marlenaklein-msft authored Jan 2, 2024
1 parent ec5c141 commit 44440e0
Show file tree
Hide file tree
Showing 7 changed files with 514 additions and 132 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1485,9 +1485,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
statusText: {fileID: 414943981}
darkGrayMaterial: {fileID: 2100000, guid: 4b78d3a2e1ab7c0499ce81ca8d18e7b5, type: 2}
redMaterial: {fileID: 2100000, guid: db61b94b23e5fb444b86c231d13e46ef, type: 2}
cyanMaterial: {fileID: 2100000, guid: 0c3570eeff29ef44e9fed596a4cc3ffd, type: 2}
boundsVisualsPrefab: {fileID: 5671351296789090341, guid: ecbf05ce2121a744cb893e82377ba3cd, type: 3}
boundsVisualsPrefab: {fileID: 4749112585544339608, guid: 728f720d1417fae41a8c8a820e4523fa, type: 3}
cubeParent: {fileID: 1321897323}
--- !u!4 &1886794917
Transform:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ public class BoundsControlRuntimeExample : MonoBehaviour
[SerializeField]
private Material darkGrayMaterial;

[SerializeField]
private Material redMaterial;

[SerializeField]
private Material cyanMaterial;

[SerializeField]
private GameObject boundsVisualsPrefab;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public BoundsControl BoundsControlRoot

private float initialParentScale;

private float initialLocalScale;

/// <inheritdoc/>
protected override void Awake()
{
Expand All @@ -110,6 +112,7 @@ public void Start()
// Record initial values at Start(), so that we
// capture the bounds sizing, etc.
initialParentScale = MaxComponent(transform.parent.lossyScale);
initialLocalScale = MaxComponent(transform.localScale);
}

/// <summary>
Expand All @@ -129,11 +132,12 @@ protected virtual void LateUpdate()
}

// Maintain the aspect ratio/proportion of the handles, globally.
// Setting localScale to ensure that lossyScale remains equal to initialLocalScale across all axes.
transform.localScale = Vector3.one;
transform.localScale = new Vector3(
transform.lossyScale.x == 0 ? transform.localScale.x : (1.0f / transform.lossyScale.x),
transform.lossyScale.y == 0 ? transform.localScale.y : (1.0f / transform.lossyScale.y),
transform.lossyScale.z == 0 ? transform.localScale.z : (1.0f / transform.lossyScale.z));
transform.lossyScale.x == 0 ? transform.localScale.x : (initialLocalScale / transform.lossyScale.x),
transform.lossyScale.y == 0 ? transform.localScale.y : (initialLocalScale / transform.lossyScale.y),
transform.lossyScale.z == 0 ? transform.localScale.z : (initialLocalScale / transform.lossyScale.z));

// If we don't want to maintain the overall *size*, we scale
// by the maximum component of the box so that the handles grow/shrink
Expand Down
Loading

0 comments on commit 44440e0

Please sign in to comment.