dynamic lines
In Unity, what would be the best way to procedurally add dynamic lines to an xaml file? Some lines in the xaml file will be static (or just rotated), but others must be fully generated at runtime.
This is for aircraft display simulation:
https://www.youtube.com/watch?v=hlNAIt1NeO4
I suppose it is the same as this, but in C#:
http://www.noesisengine.com/docs/Gui.Core._Path.html
I have this code:
But it throws this error:
This is for aircraft display simulation:
https://www.youtube.com/watch?v=hlNAIt1NeO4
I suppose it is the same as this, but in C#:
http://www.noesisengine.com/docs/Gui.Core._Path.html
I have this code:
Code: Select all
using UnityEngine;
using System.Collections;
using Noesis;
public class ND : MonoBehaviour {
void Start (){
NoesisGUIPanel panel = GetComponent<NoesisGUIPanel>();
FrameworkElement root = panel.GetContent();
root.Parent.UseLayoutRounding = false;
UIElement lineRoot = (UIElement)root.FindName("path4137");
lineRoot.RenderTransformOrigin = new Point(0.5f, 0.5f);
TransformGroup group = new TransformGroup();
Line line = new Line();
Thickness thickness = new Thickness(101,-11,362,250);
line.Margin = thickness;
line.StrokeThickness = 4;
line.X1 = 10;
line.X2 = 40;
line.Y1 = 70;
line.Y2 = 70;
group.Children.Add(line);
lineRoot.RenderTransform = group;
}
}
ApplicationException: Non Freezable item added to FreezableCollection
Noesis.FreezableCollection.Add (System.Object item) (at Assets/Plugins/NoesisGUI/Scripts/Proxies/FreezableCollection.cs:94)
ND.Start () (at Assets/Scripts/ND.cs:29)
Re: dynamic lines
Ok, I got it to work:
Code: Select all
using UnityEngine;
using System.Collections;
using Noesis;
public class ND : MonoBehaviour {
Line line;
void Start (){
NoesisGUIPanel panel = GetComponent<NoesisGUIPanel>();
FrameworkElement root = panel.GetContent();
root.Parent.UseLayoutRounding = false;
Noesis.Canvas canvas = (Noesis.Canvas)root.FindName("layer1");
line = new Line();
line.StrokeThickness = 2f;
line.X1 = 10;
line.X2 = 40;
line.Y1 = 70;
line.Y2 = 5;
line.Stroke = new SolidColorBrush(Colors.Blue);
canvas.Children.Add(line);
}
void Update(){
line.Y2 ++;
}
}
-
sfernandez
Site Admin
- Posts: 3188
- Joined:
Re: dynamic lines
Hi,
If lines have different stroke styles, then adding different Line shape objects to a Canvas like you did is fine.
But when lines share the same stroke style, you can optimize the render by using a single Path object with a StreamGeometry you can update procedurally:
If lines have different stroke styles, then adding different Line shape objects to a Canvas like you did is fine.
But when lines share the same stroke style, you can optimize the render by using a single Path object with a StreamGeometry you can update procedurally:
Code: Select all
StreamGeometry _lines = new StreamGeometry();
Path path = new Path()
{
Data = _lines,
Stroke = Brushes.Blue,
StrokeThickness = 2.0f
};
//... then update lines when needed
using (var context = _lines.Open())
{
context.BeginFigure(new Point(0, 0), false);
context.LineTo(new Point(10, 10));
context.BeginFigure(new Point(0, 0), false);
context.LineTo(new Point(0, 20));
}
Re: dynamic lines
The strokes for all segments are the same, so I will go with the StreamGeometry.
Thanks for the suggestion
Thanks for the suggestion
Who is online
Users browsing this forum: No registered users and 3 guests