Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Variable Bounding Box Handle Sizes #598

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
Loading