54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
|
using Godot;
|
||
|
using System;
|
||
|
|
||
|
[Tool]
|
||
|
public class Railway : Path
|
||
|
{
|
||
|
[Export]
|
||
|
private Color _color;
|
||
|
|
||
|
[Export]
|
||
|
private float _gauge = 1f;
|
||
|
|
||
|
private ImmediateGeometry _geo = null;
|
||
|
private Vector3[] _points = null;
|
||
|
|
||
|
public void OnPathCurveChanged()
|
||
|
{
|
||
|
Curve.Tessellate();
|
||
|
_points = Curve.GetBakedPoints();
|
||
|
}
|
||
|
|
||
|
// Called when the node enters the scene tree for the first time.
|
||
|
public override void _Ready()
|
||
|
{
|
||
|
base._Ready();
|
||
|
|
||
|
_geo = GetNode<ImmediateGeometry>("ImmediateGeometry");
|
||
|
|
||
|
var m = new SpatialMaterial();
|
||
|
m.VertexColorUseAsAlbedo = true;
|
||
|
m.FlagsUnshaded = true;
|
||
|
_geo.MaterialOverride = m;
|
||
|
|
||
|
OnPathCurveChanged();
|
||
|
}
|
||
|
|
||
|
public override void _Process(float delta)
|
||
|
{
|
||
|
base._Process(delta);
|
||
|
|
||
|
if (_geo == null) return;
|
||
|
if (_points == null || _points.Length == 0) return;
|
||
|
|
||
|
_geo.Clear();
|
||
|
_geo.Begin(Mesh.PrimitiveType.LineStrip);
|
||
|
_geo.SetColor(new Color(1, 0, 0));
|
||
|
for(int i = 0; i < _points.Length; i++)
|
||
|
{
|
||
|
_geo.AddVertex(_points[i]);
|
||
|
}
|
||
|
_geo.End();
|
||
|
}
|
||
|
}
|