45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
|
|
using Core.SaveLoad;
|
||
|
|
using UnityEngine;
|
||
|
|
using Pixelplacement;
|
||
|
|
using Pixelplacement.TweenSystem;
|
||
|
|
|
||
|
|
public class WorkerBeltRoamingBehaviour : AppleState
|
||
|
|
{
|
||
|
|
public Spline RoamingSpline;
|
||
|
|
public Transform workerObjectTransform;
|
||
|
|
public float roamDuration;
|
||
|
|
public float roamDelay;
|
||
|
|
|
||
|
|
//References to the Worker Gameobject
|
||
|
|
public GameObject workerBeltObject;
|
||
|
|
public Animator workerAnimator;
|
||
|
|
public Vector3 midRoamPosition;
|
||
|
|
|
||
|
|
// Reference to the active spline tween so we can pause/stop it
|
||
|
|
private TweenBase roamingTween;
|
||
|
|
|
||
|
|
|
||
|
|
void OnEnable()
|
||
|
|
{
|
||
|
|
workerAnimator.SetBool("isLifting?", false);
|
||
|
|
Debug.Log("Entered Worker Belt Roaming State");
|
||
|
|
|
||
|
|
if (RoamingSpline == null || workerObjectTransform == null)
|
||
|
|
{
|
||
|
|
Debug.LogWarning("WorkerBeltRoamingBehaviour: RoamingSpline or workerObjectTransform is not assigned.", this);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Store the returned TweenBase so we can control it later
|
||
|
|
roamingTween = Tween.Spline(RoamingSpline, workerObjectTransform, 0, 1, false, roamDuration, roamDelay, Tween.EaseLinear, Tween.LoopType.Loop);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Also stop the tween if the GameObject is disabled for any reason (covers StateMachine deactivation)
|
||
|
|
void OnDisable()
|
||
|
|
{
|
||
|
|
midRoamPosition = workerObjectTransform.position;
|
||
|
|
Debug.Log("WorkerBeltRoamingBehaviour: OnExitState - stopping roaming tween" + midRoamPosition);
|
||
|
|
roamingTween?.Stop();
|
||
|
|
}
|
||
|
|
}
|