Files
Convention-Unity-Demo/Assets/Scripts/MoreSpline/SplineAnchor.cs

63 lines
2.1 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 System.Collections;
using System.Collections.Generic;
using Demo.Game;
using UnityEngine;
namespace Demo.Game
{
public class SplineAnchor : ScriptableObject,IDependOnSplineCore, IDependOnSplineRenderer
{
public static SplineAnchor Make()
{
return new GameObject().AddComponent<SplineAnchor>();
}
public SplineCore MySplineCore { get; set; }
public BasicSplineRenderer MySplineRenderer { get; set; }
/// <summary>
/// 加载并绑定到新样条线
/// </summary>
/// <param name="path">对象路径, 不存在时则立刻加载</param>
[ScriptableCall(DependOnSplineCoreUtility.LoadSplineDescription)]
public IEnumerator LoadSpline(string path)
{
yield return this.LoadSplineTool(path);
}
/// <summary>
/// 必须先执行LoadSpline加载样条线
/// </summary>
/// <param name="value">百分比所在位置,取值范围是[01]</param>
[ScriptableCall(@"
<summary>
必须先执行LoadSpline加载样条线
</summary>
<param name=""value"">百分比所在位置,取值范围是[01]</param>
")]
public void EvaluatePosition(string value)
{
transform.position = MySplineCore.MySplineComputer.EvaluatePosition(Parse(value));
}
/// <summary>
/// 绑定到样条线渲染器上(必须已经加载),
/// 并设置位置为指定时间的时刻渲染器所生成的头部位置
/// </summary>
/// <param name="path">对象路径, 不存在时则立刻加载</param>
/// <param name="time">时刻</param>
[ScriptableCall(@"
<summary>
绑定到样条线渲染器上(必须已经加载),
并设置位置为指定时间的时刻渲染器所生成的头部位置
</summary>
<param name=""path"">对象路径, 不存在时则立刻加载</param>
<param name=""time"">时刻</param>
")]
public void LoadSplineRenderer(string path, string time)
{
transform.position = this.LoadSplineRendererTool(path).EvaluateClipToPosition(Parse(time));
}
}
}