1.修复一些错误2.准备专门提供基于距离的spline3.tracydll存在崩溃问题
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user