using System.Collections; using Convention; using Convention.WindowsUI.Variant; using Dreamteck.Splines; using UnityEngine; namespace Demo.Game { public class SplineMovement : BasicSplineJustFollow { public static SplineMovement Make() { return new GameObject().AddComponent(); } private SplineRenderer MySplineRenderer; /// /// 设置为仅跟随,将会被动的跟随spline运动, /// 这在多个脚本都绑定在同一个spline计算核心上时非常有用 /// [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(); yield return base.LoadScript(script); if (GetRoot().RootGameController.IsHideTrackRender == false) { if (MySplineCore == null) yield break; var splineGameObject = MySplineCore.gameObject; splineGameObject.GetOrAddComponent(); var meshRenderer = splineGameObject.GetOrAddComponent(); meshRenderer.enabled = true; meshRenderer.material = Resources.Load("Line/Dash"); MySplineRenderer = splineGameObject.AddComponent(); 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().enabled = true; MySplineCore.gameObject.GetComponent().Rebuild(); } else if (tickType == TickType.Start) { MySplineCore.gameObject.GetComponent().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()); Destroy(splineGameObject.GetComponent()); Destroy(splineGameObject.GetComponent()); MySplineCore = null; MySplineRenderer = null; } yield return base.UnloadScript(); } /// /// 设置为仅跟随,将会被动的跟随spline运动, /// 这在多个脚本都绑定在同一个spline计算核心上时非常有用 /// [ScriptableCall(@" 设置为仅跟随,将会被动的跟随spline运动, 这在多个脚本都绑定在同一个spline计算核心上时非常有用 ")] public void JustFollow() { IsJustFollow = true; } } }