Set Data of path in code
How do I do this in Unity C#?
The Data part has to be changed dynamically. Parse is not supported.
Edit:
This works, but it crashes NoesisGUI, and then the Editor:
Code: Select all
Path arcPath = new Path();
arcPath.Stroke = new SolidColorBrush(Colors.Blue);
arcPath.StrokeThickness = 1;
arcPath.Data = Geometry.Parse("M 80,200 A 100,50 45 1 0 100,50 Z");
Edit:
This works, but it crashes NoesisGUI, and then the Editor:
Code: Select all
using UnityEngine;
using System.Collections;
using Noesis;
public class ND : MonoBehaviour {
Path path;
float point0 = 0;
void Start (){
NoesisGUIPanel panel = GetComponent<NoesisGUIPanel>();
FrameworkElement root = panel.GetContent();
root.Parent.UseLayoutRounding = false;
Noesis.Canvas canvas = (Noesis.Canvas)root.FindName("layer1");
path = new Path();
path.Stroke = new SolidColorBrush(Colors.Green);
path.StrokeThickness = 1;
canvas.Children.Add(path);
}
void Update(){
point0 = (Mathf.Sin(Time.time * 0.5f) * 30f) + 30;
string pathString = "M 17.57812541,76.56250172 62.22098358,83.25893044 81.75223403,68.47098367 80.35714471," + point0;
path.SetBinding(Path.DataProperty, new Binding(){Source=pathString});
}
}
Re: Set Data of path in code
I managed to do this with StreamGeometry instead. There still might be a bug though, as I don't think it should crash.
Here is the new working code:
Note that instead of using SetData() and a path string, you can also construct the shape step by step:
Here is the new working code:
Code: Select all
using UnityEngine;
using System.Collections;
using Noesis;
public class ND : MonoBehaviour {
StreamGeometry streamGeometry;
float point0 = 0;
void Start (){
NoesisGUIPanel panel = GetComponent<NoesisGUIPanel>();
FrameworkElement root = panel.GetContent();
root.Parent.UseLayoutRounding = false;
Noesis.Canvas canvas = (Noesis.Canvas)root.FindName("layer1");
// Create a path to draw a geometry with.
Path path = new Path();
path.Stroke = new SolidColorBrush(Colors.Green);
path.StrokeThickness = 1;
// Create a StreamGeometry to use to specify myPath.
streamGeometry = new StreamGeometry();
streamGeometry.FillRule = FillRule.EvenOdd;
path.Data = streamGeometry;
canvas.Children.Add(path);
}
void Update(){
point0 = (Mathf.Sin(Time.time * 0.5f) * 30f) + 30;
string pathString = "M 17.57812541,76.56250172 62.22098358,83.25893044 81.75223403,68.47098367 80.35714471," + point0;
streamGeometry.SetData(pathString);
}
}
Code: Select all
float dynamic = (Mathf.Sin(Time.time * 0.5f) * 30f) + 30;
using(StreamGeometryContext ctx = streamGeometry.Open()){
ctx.BeginFigure(new Point(10, 90), true);
ctx.LineTo(new Point(dynamic, 90));
ctx.ArcTo(new Point(60, 60), new Size(new Point(10, 10)), 0, false, SweepDirection.Counterclockwise);
}
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: Set Data of path in code
Although it is a slow method to generate a procedural geometry, we can add this in a future release.Geometry.Parse() is not supported.
Could you please create a ticket in our bugtracker to track this issue? Thanks.I managed to do this with StreamGeometry instead. There still might be a bug though, as I don't think it should crash.
Using the StreamGeomtryContext is the recommended way to update a StreamGeometry, because using SetData() involves parsing a string which is significantly slower than using the context method.Note that instead of using SetData() and a path string, you can also construct the shape step by step:
Re: Set Data of path in code
Thanks. Will file a bug report for the crash.
Edit:
Can not reproduce now... Strange.
Edit:
Can not reproduce now... Strange.
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: Set Data of path in code
In case you can reproduce the crash again, please file a report in our bugtracker.
Meanwhile I marked this post regarding how to set Path.Data in code as solved.
Meanwhile I marked this post regarding how to set Path.Data in code as solved.
Who is online
Users browsing this forum: Google [Bot] and 1 guest