更新至unity6并且更改Scriptable完成
This commit is contained in:
@@ -26,13 +26,24 @@ namespace Demo.Game
|
||||
[Content] private MeshRenderer m_MyMeshRenderer;
|
||||
[Header("LineRenderer.Material")]
|
||||
[Content] public string LinesAssetBundlePath;
|
||||
[Content] public AssetBundle LinesAssetBundle;
|
||||
[Content] public Material LineDefaultMaterial;
|
||||
|
||||
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 = LineDefaultMaterial;
|
||||
MyMeshRenderer.material = MyDefaultMaterial;
|
||||
}
|
||||
|
||||
public MeshFilter MyMeshFilter
|
||||
@@ -107,10 +118,9 @@ namespace Demo.Game
|
||||
MyMeshRenderer.enabled = true;
|
||||
LinesAssetBundlePath = ab;
|
||||
this.LoadAssetBundle(ab, x =>
|
||||
{
|
||||
LinesAssetBundle = x;
|
||||
LineDefaultMaterial = LinesAssetBundle.LoadAsset<Material>(material);
|
||||
});
|
||||
{
|
||||
MyDefaultMaterial = x.LoadAsset<Material>(material);
|
||||
});
|
||||
}
|
||||
|
||||
protected override SplineClipDuration Lerp(SplineClipDuration begin, SplineClipDuration end, float t)
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<SplineTrackRenderer>();
|
||||
}
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
MyLineMaterial = Resources.Load<Material>("Line/Default");
|
||||
yield return base.LoadScript(script);
|
||||
if (MyDefaultMaterial == null)
|
||||
MyDefaultMaterial = StaticCacheDefaultMaterial;
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<SplineTrackRenderer>();
|
||||
}
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
MyLineMaterial = Resources.Load<Material>("Line/Default");
|
||||
yield return base.LoadScript(script);
|
||||
if (MyDefaultMaterial == null)
|
||||
MyDefaultMaterial = StaticCacheDefaultMaterial;
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ namespace Demo.Game
|
||||
[Content] public bool IsDoubleSide = DefaultIsDoubleSide;
|
||||
[Content] public int SidesCount = DefaultSidesCount;
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
MyLineMaterial = Resources.Load<Material>("Tube/Default");
|
||||
yield return base.LoadScript(script);
|
||||
if (MyDefaultMaterial == null)
|
||||
MyDefaultMaterial = Resources.Load<Material>("Tube/Default");
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
}
|
||||
|
||||
public override void SetupMeshGenerator(TubeGenerator meshGenerater)
|
||||
|
||||
@@ -16,11 +16,6 @@ namespace Demo.Game
|
||||
|
||||
protected override abstract void UpdateData(float data);
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
{
|
||||
yield return base.LoadScript(script);
|
||||
}
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
{
|
||||
MySplineCore = null;
|
||||
@@ -34,26 +29,19 @@ namespace Demo.Game
|
||||
/// <param name="value"></param>
|
||||
/// <param name="curveType">可取值为30种缓动曲线</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void Add(string time, string value, string curveType)
|
||||
public void Add(float time, float value, MathExtension.EaseCurveType curveType)
|
||||
{
|
||||
ManualAddEntry(time, float.Parse(value), Enum.Parse<MathExtension.EaseCurveType>(curveType));
|
||||
ManualAddEntry(time, value, curveType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如未加载则加载,然后绑定到样条线
|
||||
/// 绑定到样条线
|
||||
/// </summary>
|
||||
/// <param name="path">脚本位置</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public IEnumerator Load(string path)
|
||||
public void Load(SplineCore splineCore)
|
||||
{
|
||||
MySplineCore = FindWithPath(path, false) as SplineCore;
|
||||
if (MySplineCore == null)
|
||||
{
|
||||
yield return DoLoadSubScriptAsync(nameof(SplineCore), path, x =>
|
||||
{
|
||||
MySplineCore = x as SplineCore;
|
||||
});
|
||||
}
|
||||
MySplineCore = splineCore;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Convention;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Dreamteck.Splines;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
public class SplineHeadObject : BasicSplineJustFollow
|
||||
{
|
||||
public static SplineHeadObject Make()
|
||||
{
|
||||
return new GameObject().AddComponent<SplineHeadObject>();
|
||||
}
|
||||
|
||||
private SplineRenderer MySplineRenderer;
|
||||
|
||||
/// <summary>
|
||||
/// 设置为仅跟随,将会被动的跟随spline运动,
|
||||
/// 这在多个脚本都绑定在同一个spline计算核心上时非常有用
|
||||
/// </summary>
|
||||
[Content, SerializeField] private bool IsJustFollow = false;
|
||||
[Content, SerializeField] private double Cache = 0;
|
||||
|
||||
protected override void UpdateData(float data)
|
||||
{
|
||||
var sample = MySplineCore.MySplineComputer.Evaluate(data);
|
||||
Cache = sample.percent;
|
||||
UpdateTarget.transform.SetPositionAndRotation(sample.position, sample.rotation);
|
||||
//UpdateTarget.transform.localScale = Vector3.one * sample.size;
|
||||
}
|
||||
|
||||
private SceneGameWindow SceneStats;
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
{
|
||||
SceneStats = FindObjectOfType<SceneGameWindow>();
|
||||
yield return base.LoadScript(script);
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
if (MySplineCore == null)
|
||||
yield break;
|
||||
var splineGameObject = MySplineCore.gameObject;
|
||||
splineGameObject.GetOrAddComponent<MeshFilter>();
|
||||
var meshRenderer = splineGameObject.GetOrAddComponent<MeshRenderer>();
|
||||
meshRenderer.enabled = true;
|
||||
meshRenderer.material = Resources.Load<Material>("Line/Dash");
|
||||
MySplineRenderer = splineGameObject.AddComponent<SplineRenderer>();
|
||||
MySplineRenderer.spline = MySplineCore.MySplineComputer;
|
||||
MySplineRenderer.uvMode = MeshGenerator.UVMode.UniformClip;
|
||||
MySplineRenderer.Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||
{
|
||||
base.UpdateTicks(currentTime, deltaTime, tickType);
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
if (IsJustFollow == false)
|
||||
{
|
||||
if (SceneStats.IsSelectSceneCamera || tickType == TickType.Pause || tickType == TickType.Reset)
|
||||
{
|
||||
MySplineCore.gameObject.GetComponent<MeshRenderer>().enabled = true;
|
||||
MySplineCore.gameObject.GetComponent<SplineRenderer>().Rebuild();
|
||||
}
|
||||
else if (tickType == TickType.Start)
|
||||
{
|
||||
MySplineCore.gameObject.GetComponent<MeshRenderer>().enabled = false;
|
||||
}
|
||||
//不为跟随模式时,需要自己更新clip
|
||||
if (tickType == TickType.Update || tickType == TickType.Reset)
|
||||
{
|
||||
MySplineRenderer.clipFrom = Cache;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
{
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
var splineGameObject = MySplineCore.gameObject;
|
||||
Destroy(splineGameObject.GetComponent<SplineRenderer>());
|
||||
Destroy(splineGameObject.GetComponent<MeshRenderer>());
|
||||
Destroy(splineGameObject.GetComponent<MeshFilter>());
|
||||
MySplineCore = null;
|
||||
MySplineRenderer = null;
|
||||
}
|
||||
yield return base.UnloadScript();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置为仅跟随,将会被动的跟随spline运动,
|
||||
/// 这在多个脚本都绑定在同一个spline计算核心上时非常有用
|
||||
/// </summary>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void JustFollow()
|
||||
{
|
||||
IsJustFollow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,94 +13,9 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<SplineMovement>();
|
||||
}
|
||||
|
||||
private SplineRenderer MySplineRenderer;
|
||||
|
||||
/// <summary>
|
||||
/// 设置为仅跟随,将会被动的跟随spline运动,
|
||||
/// 这在多个脚本都绑定在同一个spline计算核心上时非常有用
|
||||
/// </summary>
|
||||
[Content, SerializeField] private bool IsJustFollow = false;
|
||||
[Content, SerializeField] private double Cache = 0;
|
||||
|
||||
protected override void UpdateData(float data)
|
||||
{
|
||||
Cache = MySplineCore.MySplineComputer.Evaluate(data).percent;
|
||||
UpdateTarget.transform.position = MySplineCore.MySplineComputer.EvaluatePosition(data);
|
||||
}
|
||||
|
||||
private SceneGameWindow SceneStats;
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
{
|
||||
SceneStats = FindObjectOfType<SceneGameWindow>();
|
||||
yield return base.LoadScript(script);
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
if (MySplineCore == null)
|
||||
yield break;
|
||||
var splineGameObject = MySplineCore.gameObject;
|
||||
splineGameObject.GetOrAddComponent<MeshFilter>();
|
||||
var meshRenderer = splineGameObject.GetOrAddComponent<MeshRenderer>();
|
||||
meshRenderer.enabled = true;
|
||||
meshRenderer.material = Resources.Load<Material>("Line/Dash");
|
||||
MySplineRenderer = splineGameObject.AddComponent<SplineRenderer>();
|
||||
MySplineRenderer.spline = MySplineCore.MySplineComputer;
|
||||
MySplineRenderer.uvMode = MeshGenerator.UVMode.UniformClip;
|
||||
MySplineRenderer.Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||
{
|
||||
base.UpdateTicks(currentTime, deltaTime, tickType);
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
if (IsJustFollow == false)
|
||||
{
|
||||
if (SceneStats.IsSelectSceneCamera || tickType == TickType.Pause || tickType == TickType.Reset)
|
||||
{
|
||||
MySplineCore.gameObject.GetComponent<MeshRenderer>().enabled = true;
|
||||
MySplineCore.gameObject.GetComponent<SplineRenderer>().Rebuild();
|
||||
}
|
||||
else if (tickType == TickType.Start)
|
||||
{
|
||||
MySplineCore.gameObject.GetComponent<MeshRenderer>().enabled = false;
|
||||
}
|
||||
//不为跟随模式时,需要自己更新clip
|
||||
if (tickType == TickType.Update || tickType == TickType.Reset)
|
||||
{
|
||||
MySplineRenderer.clipFrom = Cache;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
{
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
var splineGameObject = MySplineCore.gameObject;
|
||||
Destroy(splineGameObject.GetComponent<SplineRenderer>());
|
||||
Destroy(splineGameObject.GetComponent<MeshRenderer>());
|
||||
Destroy(splineGameObject.GetComponent<MeshFilter>());
|
||||
MySplineCore = null;
|
||||
MySplineRenderer = null;
|
||||
}
|
||||
yield return base.UnloadScript();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置为仅跟随,将会被动的跟随spline运动,
|
||||
/// 这在多个脚本都绑定在同一个spline计算核心上时非常有用
|
||||
/// </summary>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void JustFollow()
|
||||
{
|
||||
IsJustFollow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
Assets/Scripts/MoreSpline/Updatement/SplinePointerObject.cs
Normal file
23
Assets/Scripts/MoreSpline/Updatement/SplinePointerObject.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Convention;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Dreamteck.Splines;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
public class SplinePointerObject : BasicSplineJustFollow
|
||||
{
|
||||
public static SplinePointerObject Make()
|
||||
{
|
||||
return new GameObject().AddComponent<SplinePointerObject>();
|
||||
}
|
||||
|
||||
protected override void UpdateData(float data)
|
||||
{
|
||||
var sample = MySplineCore.MySplineComputer.Evaluate(data);
|
||||
UpdateTarget.transform.SetPositionAndRotation(sample.position, sample.rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user