Files
Convention-Unity-Demo/Assets/Scripts/MoreSpline/SplineNode.cs
2025-12-12 15:19:10 +08:00

77 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Convention;
using Demo.Attr;
using Dreamteck.Splines;
using System.Collections;
using UnityEngine;
namespace Demo.Game
{
[Scriptable]
public class SplineNode : ScriptableObject
{
protected override bool IsSelfEnableUpdate => false;
public static SplineNode Make()
{
var node = new GameObject("", typeof(Node)).AddComponent<SplineNode>();
node.m_MyNode = node.GetOrAddComponent<Node>();
return node;
}
private Node m_MyNode;
public float NodeSize = 1;
public Color NodeColor = Color.white;
public bool IsSetupNodeRotation = false;
public Vector3 NodeRotation = Vector3.zero;
public int MyNodeContent = 0;
public Node MyNode => m_MyNode;
public void AddTo(SplineCore core)
{
MyNodeContent = core.NodeContent;
core.MySplineComputer.SetPointColor(MyNodeContent, NodeColor);
core.MySplineComputer.SetPointSize(MyNodeContent, NodeSize);
core.MySplineComputer.SetPointNormal(MyNodeContent, IsSetupNodeRotation ? NodeRotation.normalized : transform.up);
MyNode.AddConnection(core.MySplineComputer, MyNodeContent);
}
/// <summary>
/// 设置节点大小默认为1
/// </summary>
/// <param name="size"></param>
[Convention.RScript.Variable.Attr.Method]
public void SetNodeSize(float size)
{
NodeSize = size;
}
/// <summary>
/// 设置节点颜色,默认为(1,1,1,1)
/// </summary>
/// <param name="r"></param>
/// <param name="g"></param>
/// <param name="b"></param>
/// <param name="a"></param>
[Convention.RScript.Variable.Attr.Method]
public void SetNodeColor(float r, float g, float b, float a)
{
NodeColor = new(r, g, b, a);
}
/// <summary>
/// 设置节点旋转节点正面forward向量为法线
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
[Convention.RScript.Variable.Attr.Method]
public void SetNodeRotation(float x, float y, float z)
{
IsSetupNodeRotation = true;
this.transform.localEulerAngles = NodeRotation = new(x, y, z);
}
}
}