2025-09-25 19:04:05 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using Convention;
|
|
|
|
|
using Dreamteck.Splines;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Demo.Game
|
|
|
|
|
{
|
|
|
|
|
public interface IDependOnSplineRenderer
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class DependOnSplineRendererUtility
|
|
|
|
|
{
|
|
|
|
|
public static BasicSplineRenderer LoadSplineRendererTool(this IDependOnSplineCore self, string path)
|
|
|
|
|
{
|
|
|
|
|
return self.SharedInterfaceScriptObject.FindWithPath(path, true) as BasicSplineRenderer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class BasicSplineRenderer : Updatement<SplineClipDuration>, IAssetBundleLoader, IDependOnSplineCore
|
|
|
|
|
{
|
|
|
|
|
[Content] public SplineCore MySplineCore { get; set; }
|
2025-11-24 18:02:57 +08:00
|
|
|
[Content] private MeshFilter m_MeshFilter;
|
|
|
|
|
[Content] private MeshRenderer m_MyMeshRenderer;
|
2025-09-25 19:04:05 +08:00
|
|
|
[Header("LineRenderer.Material")]
|
|
|
|
|
[Content] public string LinesAssetBundlePath;
|
2025-11-25 10:52:39 +08:00
|
|
|
|
|
|
|
|
private static Material m_StaticCacheDefaultMaterial;
|
|
|
|
|
protected static Material StaticCacheDefaultMaterial
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (m_StaticCacheDefaultMaterial == null)
|
|
|
|
|
m_StaticCacheDefaultMaterial = Resources.Load<Material>("Line/Default");
|
|
|
|
|
return m_StaticCacheDefaultMaterial;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Content] public Material MyDefaultMaterial;
|
2025-11-24 18:02:57 +08:00
|
|
|
|
|
|
|
|
public override void ResetEnterGameStatus()
|
|
|
|
|
{
|
|
|
|
|
base.ResetEnterGameStatus();
|
2025-11-25 10:52:39 +08:00
|
|
|
MyMeshRenderer.material = MyDefaultMaterial;
|
2025-11-24 18:02:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MeshFilter MyMeshFilter
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (m_MeshFilter == null)
|
|
|
|
|
m_MeshFilter = this.GetOrAddComponent<MeshFilter>();
|
|
|
|
|
return m_MeshFilter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public MeshRenderer MyMeshRenderer
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (m_MyMeshRenderer == null)
|
|
|
|
|
m_MyMeshRenderer = this.GetOrAddComponent<MeshRenderer>();
|
|
|
|
|
return m_MyMeshRenderer;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-25 19:04:05 +08:00
|
|
|
|
|
|
|
|
public abstract Vector3 EvaluateClipFromPosition(float time);
|
|
|
|
|
|
|
|
|
|
public abstract Vector3 EvaluateClipToPosition(float time);
|
|
|
|
|
|
2025-10-08 21:47:18 +08:00
|
|
|
public abstract SplineSample EvaluateClipFrom(float time);
|
|
|
|
|
|
|
|
|
|
public abstract SplineSample EvaluateClipTo(float time);
|
|
|
|
|
|
2025-09-25 19:04:05 +08:00
|
|
|
public override IEnumerator UnloadScript()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(LinesAssetBundlePath) == false)
|
|
|
|
|
yield return this.UnloadAssetBundle(LinesAssetBundlePath);
|
|
|
|
|
LinesAssetBundlePath = "";
|
|
|
|
|
yield return base.UnloadScript();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="time">插值时间</param>
|
|
|
|
|
/// <param name="from"></param>
|
|
|
|
|
/// <param name="to"></param>
|
|
|
|
|
/// <param name="curveType">可取值为30种缓动曲线</param>
|
2025-10-27 20:24:15 +08:00
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-11-26 17:59:18 +08:00
|
|
|
public void Add(float time, float from, float to, MathExtension.EaseCurveType curveType)
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-11-26 17:59:18 +08:00
|
|
|
ManualAddEntry(time, new(from, to), curveType);
|
2025-09-25 19:04:05 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-27 20:24:15 +08:00
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-11-24 18:02:57 +08:00
|
|
|
public void LoadSpline(string path)
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-11-24 18:02:57 +08:00
|
|
|
this.LoadSplineTool(path);
|
2025-09-25 19:04:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-11-12 16:12:01 +08:00
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
|
|
|
public void LoadSpline(SplineCore spline)
|
|
|
|
|
{
|
|
|
|
|
this.MySplineCore = spline;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-25 19:04:05 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 加载对应ab包并加载指定材质
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ab"></param>
|
|
|
|
|
/// <param name="material"></param>
|
2025-10-27 20:24:15 +08:00
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-11-24 18:02:57 +08:00
|
|
|
public void LoadMaterial(string ab, string material)
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-11-24 18:02:57 +08:00
|
|
|
MyMeshRenderer.enabled = true;
|
|
|
|
|
LinesAssetBundlePath = ab;
|
|
|
|
|
this.LoadAssetBundle(ab, x =>
|
2025-11-25 10:52:39 +08:00
|
|
|
{
|
|
|
|
|
MyDefaultMaterial = x.LoadAsset<Material>(material);
|
|
|
|
|
});
|
2025-09-25 19:04:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SplineClipDuration Lerp(SplineClipDuration begin, SplineClipDuration end, float t)
|
|
|
|
|
{
|
|
|
|
|
return new(Mathf.Lerp(begin.ClipFrom, end.ClipFrom, t), Mathf.Lerp(begin.ClipTo, end.ClipTo, t));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class BasicSplineRenderer<TMeshGenerator>: BasicSplineRenderer where TMeshGenerator : MeshGenerator
|
|
|
|
|
{
|
|
|
|
|
[Content] public TMeshGenerator MyMeshGenerator;
|
|
|
|
|
|
2025-11-24 18:02:57 +08:00
|
|
|
protected override IEnumerator DoSomethingDuringApplyScript()
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-11-24 18:02:57 +08:00
|
|
|
yield return base.DoSomethingDuringApplyScript();
|
2025-09-25 19:04:05 +08:00
|
|
|
MyMeshGenerator = this.GetOrAddComponent<TMeshGenerator>();
|
|
|
|
|
MyMeshGenerator.spline = MySplineCore.MySplineComputer;
|
|
|
|
|
SetupMeshGenerator(MyMeshGenerator);
|
2025-10-06 17:43:21 +08:00
|
|
|
MyMeshGenerator.RebuildImmediate();
|
2025-09-25 19:04:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region SetupMeshGenerator
|
|
|
|
|
|
|
|
|
|
[Content] public MeshGenerator.UVMode MyUVMode = default;
|
|
|
|
|
|
|
|
|
|
public virtual void SetupMeshGenerator(TMeshGenerator meshGenerater)
|
|
|
|
|
{
|
|
|
|
|
meshGenerater.uvMode = MyUVMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置材质UV映射
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mode">Clip, UniformClip, Clamp, UniformClamp</param>
|
2025-10-27 20:24:15 +08:00
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-11-24 18:02:57 +08:00
|
|
|
public void SetUVMode(MeshGenerator.UVMode mode)
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-11-24 18:02:57 +08:00
|
|
|
MyUVMode = mode;
|
2025-09-25 19:04:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
protected override void UpdateData(SplineClipDuration data)
|
|
|
|
|
{
|
|
|
|
|
MyMeshGenerator.SetClipRange(data.ClipFrom, data.ClipTo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
|
|
|
|
{
|
|
|
|
|
//保护措施
|
|
|
|
|
if (MyMeshGenerator == null)
|
|
|
|
|
return;
|
|
|
|
|
base.UpdateTicks(currentTime, deltaTime, tickType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Vector3 EvaluateClipFromPosition(float time)
|
|
|
|
|
{
|
|
|
|
|
return MySplineCore.MySplineComputer.EvaluatePosition(Evaluate(time).ClipFrom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Vector3 EvaluateClipToPosition(float time)
|
|
|
|
|
{
|
|
|
|
|
return MySplineCore.MySplineComputer.EvaluatePosition(Evaluate(time).ClipTo);
|
|
|
|
|
}
|
2025-10-08 21:47:18 +08:00
|
|
|
|
|
|
|
|
public override SplineSample EvaluateClipFrom(float time)
|
|
|
|
|
{
|
|
|
|
|
return MySplineCore.MySplineComputer.Evaluate(Evaluate(time).ClipFrom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override SplineSample EvaluateClipTo(float time)
|
|
|
|
|
{
|
|
|
|
|
return MySplineCore.MySplineComputer.Evaluate(Evaluate(time).ClipTo);
|
|
|
|
|
}
|
2025-09-25 19:04:05 +08:00
|
|
|
}
|
|
|
|
|
}
|