-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
UILineRenderer - issues with specifying point locations at runtime #123
Comments
On 2017.03.08 17:22, @SimonDarksideJ commented: As to coordinates it is a bit of a strange situation currently. The coordinates are relative coordinates to the bottom left position of the Rect Transform currently. Just the way the original author defined the control. I have been meaning to revisit this as there have been a few requests to use positional coordinates in SS and WS, but need to find the time to investigate. All that is needed is to transform the WS or SS coordinates relative to the control. So if you look at the demo videos, they all use 0,0 to 1,1 (bottom left to top right). higher or lower numbers project outside of the rect transform. (it gets a little more freaky if you also turn of the "relative" option (just zoom OUT). So best to play with what you can and if you can offer any code / updates suggestions I'll add them in (or wait until I got more time to dig in to it) Hope that helps. |
On 2017.03.08 18:41, Alastair Aitchison commented: I'll post back if I make any progress! |
On 2017.03.09 14:30, Alastair Aitchison commented: But I've certainly found a lot of other people having similar problems - unfortunately not with any concrete solutions! |
On 2017.03.09 16:14, @SimonDarksideJ commented: If I get some time this week, I'll try and look in to it. |
On 2017.03.13 11:25, Alastair Aitchison commented: Assumptions are:
using UnityEngine;
using System.Collections;
using UnityEngine.UI.Extensions;
[RequireComponent(typeof(UILineRenderer))]
[ExecuteInEditMode]
public class UILineConnector : MonoBehaviour {
// The elements between which line segments should be drawn
public RectTransform[] transforms;
// The canvas on which the elements lie
public RectTransform canvas;
// Update is called once per frame
void Update () {
// Get the pivot points
Vector2 thisPivot = GetComponent<RectTransform>().pivot;
Vector2 canvasPivot = canvas.pivot;
// Set up some arrays of coordinates in various reference systems
Vector3[] worldSpaces = new Vector3[transforms.Length];
Vector3[] canvasSpaces = new Vector3[transforms.Length];
Vector2[] points = new Vector2[transforms.Length];
// First, convert the pivot to worldspace
for (int i = 0; i < transforms.Length; i++) {
worldSpaces[i] = transforms[i].TransformPoint(thisPivot);
}
// Then, convert to canvas space
for (int i = 0; i < transforms.Length; i++) {
canvasSpaces[i] = canvas.InverseTransformPoint(worldSpaces[i]);
}
// Calculate delta from the canvas pivot point
for (int i = 0; i < transforms.Length; i++) {
points[i] = new Vector2(canvasSpaces[i].x - canvasPivot.x, canvasSpaces[i].y - canvasPivot.y);
}
// And assign the converted points to the line renderer
GetComponent<UILineRenderer>().Points = points;
}
} And here's what it looks like: |
On 2017.03.13 13:44, @SimonDarksideJ commented: |
On 2017.06.22 00:54, @SimonDarksideJ commented: Added new Extension method for discovering a parent canvas for a non-graphic Referenced by ec165a5 |
On 2017.06.22 00:54 @SimonDarksideJ modified issue: |
On 2017.06.22 00:57, @SimonDarksideJ commented: Only peculiarity, is that moving pivots on either the Canvas or Line Renderer affect the line drawn. Tried a few tweaks but couldn't resolve. A problem for another day and will just mention it in the documentation for the control. Thanks again for the submission ! |
On 2017.08.03 23:24, R Bryan Irwin commented: If you want to make it more performant, consider replacing the Update method with the event : void OnRectTransformDimensionsChange() Thanks for making this! |
On 2017.08.04 10:54, @SimonDarksideJ commented: |
On 2017.08.04 20:38, @SimonDarksideJ commented: |
On 2021.07.22 22:19, kobi malul commented: |
On 2021.07.22 23:49, @SimonDarksideJ commented: Can you log a new issue with the issues you are facing, the components and controls have been tested with 2020 and I’m not aware of any new issues. If there is an issue in the documentation regarding its use, I’ve love to hear your frustrations so we can better improve the guides. Just use a new issue rather than updating old, closed ones. |
Improved UI Highlightable Utility Approved-by: Simon Jackson
Issue created by Alastair Aitchison as Bitbucket Issue #123 on 2017.03.08 16:11.
Hi, thanks for all the effort that's gone into these extensions - it's much appreciated!
I'm trying to use the UILineRenderer to generate (at runtime) connections between "nodes" in a graph, where nodes are panels and the graph is on a screenspace overlay canvas that stretches with screen size.
However, I'm having problems specifying the coordinates for the Points array of the linerenderer correctly - I've tried various combinations of using position, anchorPosition, anchoredPosition before and after using SetParent(true or false) to parent the GO containing the UILineRenderer to either the canvas itself or to other items, but it seems that the LineRenderer always has an undesired offset or incorrect scaling.
Please could you clarify whether the coordinates are meant to be provided in worldspace, screenspace, or some other coordinate system? And, even better, could you provide a simple code example that takes, say, two RectTransform parameters of different elements on a canvas and programmatically draws a line between them? Because this doesn't seem to work:
May thanks!
The text was updated successfully, but these errors were encountered: