1.修复一些错误2.准备专门提供基于距离的spline3.tracydll存在崩溃问题

This commit is contained in:
2025-11-28 17:35:24 +08:00
parent 2a6bc6edf8
commit ee7bd2d800
22 changed files with 1376 additions and 507 deletions

View File

@@ -0,0 +1,199 @@
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; }
[Content] private MeshFilter m_MeshFilter;
[Content] private MeshRenderer m_MyMeshRenderer;
[Header("LineRenderer.Material")]
[Content] public string LinesAssetBundlePath;
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;
public override void ResetEnterGameStatus()
{
base.ResetEnterGameStatus();
MyMeshRenderer.material = MyDefaultMaterial;
}
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;
}
}
public abstract Vector3 EvaluateClipFromPosition(float time);
public abstract Vector3 EvaluateClipToPosition(float time);
public abstract SplineSample EvaluateClipFrom(float time);
public abstract SplineSample EvaluateClipTo(float time);
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>
[Convention.RScript.Variable.Attr.Method]
public void Add(float time, float from, float to, MathExtension.EaseCurveType curveType)
{
ManualAddEntry(time, new(from, to), curveType);
}
[Convention.RScript.Variable.Attr.Method]
public void LoadSpline(string path)
{
this.LoadSplineTool(path);
}
[Convention.RScript.Variable.Attr.Method]
public void LoadSpline(SplineCore spline)
{
this.MySplineCore = spline;
}
/// <summary>
/// 加载对应ab包并加载指定材质
/// </summary>
/// <param name="ab"></param>
/// <param name="material"></param>
[Convention.RScript.Variable.Attr.Method]
public void LoadMaterial(string ab, string material)
{
MyMeshRenderer.enabled = true;
LinesAssetBundlePath = ab;
this.LoadAssetBundle(ab, x =>
{
MyDefaultMaterial = x.LoadAsset<Material>(material);
});
}
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;
protected override IEnumerator DoSomethingDuringApplyScript()
{
yield return base.DoSomethingDuringApplyScript();
MyMeshGenerator = this.GetOrAddComponent<TMeshGenerator>();
MyMeshGenerator.spline = MySplineCore.MySplineComputer;
SetupMeshGenerator(MyMeshGenerator);
MyMeshGenerator.RebuildImmediate();
}
#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>
[Convention.RScript.Variable.Attr.Method]
public void SetUVMode(MeshGenerator.UVMode mode)
{
MyUVMode = mode;
}
#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);
}
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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5b165645a314a234981c068a78d57c4e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using Dreamteck.Splines;
using System.Collections;
using UnityEngine;
namespace Demo.Game
{
public class SplineRenderer : BasicSplineRenderer<Dreamteck.Splines.SplineRenderer>
{
public static SplineRenderer Make()
{
return new GameObject().AddComponent<SplineRenderer>();
}
protected override IEnumerator DoSomethingDuringApplyScript()
{
if (MyDefaultMaterial == null)
MyDefaultMaterial = StaticCacheDefaultMaterial;
yield return base.DoSomethingDuringApplyScript();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9f011726bf166a94bae2be796e120b8b

View File

@@ -0,0 +1,21 @@
using Dreamteck.Splines;
using System.Collections;
using UnityEngine;
namespace Demo.Game
{
public class SplineSurfaceRenderer : BasicSplineRenderer<SurfaceGenerator>
{
public static SplineSurfaceRenderer Make()
{
return new GameObject().AddComponent<SplineSurfaceRenderer>();
}
protected override IEnumerator DoSomethingDuringApplyScript()
{
if (MyDefaultMaterial == null)
MyDefaultMaterial = StaticCacheDefaultMaterial;
yield return base.DoSomethingDuringApplyScript();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: acff355a0ae693443abc68f727f6d0ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections;
using Convention;
using Dreamteck.Splines;
using UnityEngine;
namespace Demo.Game
{
public class SplineTrackRenderer : BasicSplineRenderer<PathGenerator>
{
public static SplineTrackRenderer Make()
{
return new GameObject().AddComponent<SplineTrackRenderer>();
}
protected override IEnumerator DoSomethingDuringApplyScript()
{
if (MyDefaultMaterial == null)
MyDefaultMaterial = StaticCacheDefaultMaterial;
yield return base.DoSomethingDuringApplyScript();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 036f75bed33e5354f9e9eeca96f312f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
using System;
using System.Collections;
using Convention;
using Dreamteck.Splines;
using UnityEngine;
namespace Demo.Game
{
public class SplineTubeRenderer : BasicSplineRenderer<TubeGenerator>
{
public static SplineTubeRenderer Make()
{
return new GameObject().AddComponent<SplineTubeRenderer>();
}
public const bool DefaultIsDoubleSide = true;
public const int DefaultSidesCount = 12;
[Content] public bool IsDoubleSide = DefaultIsDoubleSide;
[Content] public int SidesCount = DefaultSidesCount;
protected override IEnumerator DoSomethingDuringApplyScript()
{
if (MyDefaultMaterial == null)
MyDefaultMaterial = Resources.Load<Material>("Tube/Default");
yield return base.DoSomethingDuringApplyScript();
}
public override void SetupMeshGenerator(TubeGenerator meshGenerater)
{
base.SetupMeshGenerator(meshGenerater);
meshGenerater.doubleSided = IsDoubleSide;
meshGenerater.sides = SidesCount;
}
public override IEnumerator UnloadScript()
{
yield return base.UnloadScript();
// Reset
{
IsDoubleSide = DefaultIsDoubleSide;
SidesCount = DefaultSidesCount;
}
}
/// <summary>
/// 禁用双面渲染,用于优化性能
/// </summary>
[Convention.RScript.Variable.Attr.Method]
public void DisableDoubleSide()
{
IsDoubleSide = false;
}
/// <summary>
/// 设置面数,越高越圆润
/// </summary>
/// <param name="sides"></param>
[Convention.RScript.Variable.Attr.Method]
public void SetSides(int sides)
{
SidesCount = Mathf.Min(3, sides);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 492b17eb6a13c234ca1d8b0df3970e01
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: