94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using Dreamteck.Splines;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace Demo.Game
|
|||
|
|
{
|
|||
|
|
public class SplineNode : ScriptableObject
|
|||
|
|
{
|
|||
|
|
public static SplineNode Make()
|
|||
|
|
{
|
|||
|
|
return new GameObject("", typeof(Node)).AddComponent<SplineNode>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public Node MyNode;
|
|||
|
|
public float NodeSize = 1;
|
|||
|
|
public Color NodeColor = Color.white;
|
|||
|
|
public bool IsSetupNodeRotation = false;
|
|||
|
|
public Vector3 NodeRotation = Vector3.zero;
|
|||
|
|
public int MyNodeContent = 0;
|
|||
|
|
|
|||
|
|
public override IEnumerator LoadScript(string script)
|
|||
|
|
{
|
|||
|
|
MyNode = GetComponent<Node>();
|
|||
|
|
yield return base.LoadScript(script);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void AddTo(SplineCore core)
|
|||
|
|
{
|
|||
|
|
MyNodeContent = core.NodeContent;
|
|||
|
|
MyNode.AddConnection(core.MySplineComputer, MyNodeContent);
|
|||
|
|
core.MySplineComputer.SetPointSize(MyNodeContent, NodeSize);
|
|||
|
|
core.MySplineComputer.SetPointColor(MyNodeContent, NodeColor);
|
|||
|
|
core.MySplineComputer.SetPointNormal(MyNodeContent, IsSetupNodeRotation ? NodeRotation.normalized : transform.up);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 设置节点大小,默认为1
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="size"></param>
|
|||
|
|
[ScriptableCall(@"
|
|||
|
|
<summary>
|
|||
|
|
设置节点大小,默认为1
|
|||
|
|
</summary>
|
|||
|
|
<param name=""size""></param>
|
|||
|
|
")]
|
|||
|
|
public void SetNoteSize(string size)
|
|||
|
|
{
|
|||
|
|
NodeSize = float.Parse(size);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 设置节点颜色,默认为(1,1,1,1)
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="r"></param>
|
|||
|
|
/// <param name="g"></param>
|
|||
|
|
/// <param name="b"></param>
|
|||
|
|
/// <param name="a"></param>
|
|||
|
|
[ScriptableCall(@"
|
|||
|
|
<summary>
|
|||
|
|
设置节点颜色,默认为(1,1,1,1)
|
|||
|
|
</summary>
|
|||
|
|
<param name=""r""></param>
|
|||
|
|
<param name=""g""></param>
|
|||
|
|
<param name=""b""></param>
|
|||
|
|
<param name=""a""></param>
|
|||
|
|
")]
|
|||
|
|
public void SetNoteColor(string r, string g, string b, string a)
|
|||
|
|
{
|
|||
|
|
NodeColor = new(float.Parse(r), float.Parse(g), float.Parse(b), float.Parse(a));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 设置节点旋转,节点正面forward向量为法线
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="x"></param>
|
|||
|
|
/// <param name="y"></param>
|
|||
|
|
/// <param name="z"></param>
|
|||
|
|
[ScriptableCall(@"
|
|||
|
|
<summary>
|
|||
|
|
设置节点旋转,节点正面forward向量为法线
|
|||
|
|
</summary>
|
|||
|
|
<param name=""x""></param>
|
|||
|
|
<param name=""y""></param>
|
|||
|
|
<param name=""z""></param>
|
|||
|
|
")]
|
|||
|
|
public void SetNoteRotation(string x, string y, string z)
|
|||
|
|
{
|
|||
|
|
IsSetupNodeRotation = true;
|
|||
|
|
this.transform.localEulerAngles = NodeRotation = new(float.Parse(x), float.Parse(y), float.Parse(z));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|