2025-09-25 19:04:05 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using Dreamteck.Splines;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Demo.Game
|
|
|
|
|
|
{
|
|
|
|
|
|
public class SplineNode : ScriptableObject
|
|
|
|
|
|
{
|
|
|
|
|
|
public static SplineNode Make()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new GameObject("", typeof(Node)).AddComponent<SplineNode>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-24 18:02:57 +08:00
|
|
|
|
private Node m_MyNode;
|
2025-09-25 19:04:05 +08:00
|
|
|
|
public float NodeSize = 1;
|
|
|
|
|
|
public Color NodeColor = Color.white;
|
|
|
|
|
|
public bool IsSetupNodeRotation = false;
|
|
|
|
|
|
public Vector3 NodeRotation = Vector3.zero;
|
|
|
|
|
|
public int MyNodeContent = 0;
|
|
|
|
|
|
|
2025-11-24 18:02:57 +08:00
|
|
|
|
|
|
|
|
|
|
public Node MyNode
|
2025-09-25 19:04:05 +08:00
|
|
|
|
{
|
2025-11-24 18:02:57 +08:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_MyNode == null)
|
|
|
|
|
|
m_MyNode = GetComponent<Node>();
|
|
|
|
|
|
return m_MyNode;
|
|
|
|
|
|
}
|
2025-09-25 19:04:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddTo(SplineCore core)
|
|
|
|
|
|
{
|
|
|
|
|
|
MyNodeContent = core.NodeContent;
|
|
|
|
|
|
core.MySplineComputer.SetPointColor(MyNodeContent, NodeColor);
|
2025-10-05 20:18:48 +08:00
|
|
|
|
core.MySplineComputer.SetPointSize(MyNodeContent, NodeSize);
|
2025-09-25 19:04:05 +08:00
|
|
|
|
core.MySplineComputer.SetPointNormal(MyNodeContent, IsSetupNodeRotation ? NodeRotation.normalized : transform.up);
|
2025-10-05 20:18:48 +08:00
|
|
|
|
MyNode.AddConnection(core.MySplineComputer, MyNodeContent);
|
2025-09-25 19:04:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置节点大小,默认为1
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="size"></param>
|
2025-10-27 20:24:15 +08:00
|
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-11-24 18:02:57 +08:00
|
|
|
|
public void SetNodeSize(float size)
|
2025-09-25 19:04:05 +08:00
|
|
|
|
{
|
2025-11-24 18:02:57 +08:00
|
|
|
|
NodeSize = size;
|
2025-09-25 19:04:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置节点颜色,默认为(1,1,1,1)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="r"></param>
|
|
|
|
|
|
/// <param name="g"></param>
|
|
|
|
|
|
/// <param name="b"></param>
|
|
|
|
|
|
/// <param name="a"></param>
|
2025-10-27 20:24:15 +08:00
|
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-11-24 18:02:57 +08:00
|
|
|
|
public void SetNodeColor(float r, float g, float b, float a)
|
2025-09-25 19:04:05 +08:00
|
|
|
|
{
|
2025-11-24 18:02:57 +08:00
|
|
|
|
NodeColor = new(r, g, b, a);
|
2025-09-25 19:04:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置节点旋转,节点正面forward向量为法线
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="x"></param>
|
|
|
|
|
|
/// <param name="y"></param>
|
|
|
|
|
|
/// <param name="z"></param>
|
2025-10-27 20:24:15 +08:00
|
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-11-24 18:02:57 +08:00
|
|
|
|
public void SetNodeRotation(float x, float y, float z)
|
2025-09-25 19:04:05 +08:00
|
|
|
|
{
|
|
|
|
|
|
IsSetupNodeRotation = true;
|
2025-11-24 18:02:57 +08:00
|
|
|
|
this.transform.localEulerAngles = NodeRotation = new(x, y, z);
|
2025-09-25 19:04:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|