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

UILineConnector point array calculation #480

Merged

Conversation

hugoymh
Copy link

@hugoymh hugoymh commented Oct 2, 2024

Unity UI Extensions - Pull Request

Overview

This PR modifies the UILineConnector's implementation of calculating the point positions for UILineRenderer.

Changes

The new implementation directly converts RectTransform[] transforms's world positions from UILineConnector to would-be local positions relative to UILineRenderer's transform position.

Vector2[] points = new Vector2[transforms.Length];
for (int i = 0; i < transforms.Length; i++)
{
    if (transforms[i] == null)
    {
        continue;
    }
    var offsetPos = rt.InverseTransformPoint(transforms[i].position);
    points[i] = new Vector2(offsetPos.x, offsetPos.y);
}

This implementation also prevents UILineRenderer from using Relative Size:

if (lr.RelativeSize)
{
    Debug.LogWarning("While using UILineConnector, UILineRenderer should not use relative size, so that even if this RectTransform has a zero-size Rect, the positions of the points can still be calculated");
    lr.RelativeSize = false;
}

With this, when changing the pivot point of UILineRenderer's local RectTransform, the point array will be recalculated accordingly. The connector transforms will work regardless of placing them in a separate GO from the LineRenderer/Connector, or directly under as its children.

The new calculation thus fixes Issue#440, which also makes the warning in UILineRenderer become obsolete as well:

//(deleted in this PR)
if (transform.GetComponent<RectTransform>().position != Vector3.zero)
{
    Debug.LogWarning("A Line Renderer component should be on a RectTransform positioned at (0,0,0), do not use in child Objects.\nFor best results, create separate RectTransforms as children of the canvas positioned at (0,0) for a UILineRenderer and do not move.");
}

Breaking Changes

Related Submodule Changes

Testing status

  • No tests have been added.

Manual testing status

I've tested with different GameObject hierarchy and different pivot points/anchor points configurations:
image

My first PR ever, let me know if need further info.

@SimonDarksideJ SimonDarksideJ changed the base branch from release to development October 2, 2024 12:19
@SimonDarksideJ
Copy link
Contributor

As this is a significant change, will get it a test run asap @hugoymh , thanks for the contribution.

P.S, development work targets the development branch. Release is for the current release tag only

@SimonDarksideJ
Copy link
Contributor

Tested and working, thanks for the contributuon

@SimonDarksideJ SimonDarksideJ merged commit 2d5c46e into Unity-UI-Extensions:development Oct 4, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants