using System.Collections; using System.Collections.Generic; using UnityEngine; using BansheeGz.BGSpline.Components; using BansheeGz.BGSpline.Curve; public class Lighthouse : MonoBehaviour { public BGCurve splineCurve; public List splineDistantPoints = new List(); public float speed = 200f; public float timePadding = 0.5f; public float timeBetweenPoints = 3f; public AnimationCurve animationCurve; private BGCcCursor splineCursor; private BGCcCursorObjectTranslate splineObjectTranslate; private int targetPoint = 0; private bool reverseDirection = false; private bool midpoint = false; void Start() { splineCursor = splineCurve.GetComponent(); splineObjectTranslate = splineCurve.GetComponent(); if (splineDistantPoints == null || splineDistantPoints.Count == 0) { splineDistantPoints.Add(0f); for (int i=1; i{ if (reverseDirection) targetPoint--; else targetPoint++; if (targetPoint >= splineDistantPoints.Count) { if (splineCurve.Closed) { targetPoint = 1; splineCursor.Distance = 0f; } else { targetPoint = splineDistantPoints.Count - 2; reverseDirection = !reverseDirection; } } midpoint = true; float start = splineCursor.Distance; float end = splineDistantPoints[targetPoint]; float distance = Mathf.Abs(end - start); LeanTween.value(gameObject, start, end, distance / speed + timePadding).setOnUpdate((float val)=>{ splineCursor.Distance = val; }).setEase(animationCurve).setOnComplete(()=>{ midpoint = false; moveToNextPoint(); }); }); } public void searchlightStateChanged() { LeanTween.cancel(gameObject, false); if (Searchlight.state == Searchlight.SearchState.Chasing) { splineObjectTranslate.enabled = false; } else if (Searchlight.state == Searchlight.SearchState.Returning) { splineObjectTranslate.enabled = false; Vector3 start = splineObjectTranslate.ObjectToManipulate.position; Vector3 end = splineCursor.CalculatePosition(); float distance = (end - start).magnitude; LeanTween.move(splineObjectTranslate.ObjectToManipulate.gameObject, end, distance / speed + timePadding).setEase(animationCurve).setOnComplete(()=>{ splineObjectTranslate.enabled = true; if (midpoint) { if (reverseDirection) targetPoint++; else targetPoint--; } moveToNextPoint(); NotificationServer.notify("statechange Searchlight safe"); }); } } }