Files
AppleHillsProduction/Assets/Scripts/Animation/GardenerChaseBehavior.cs

61 lines
2.0 KiB
C#
Raw Normal View History

using System;
using System.Collections;
2025-09-10 22:17:51 +02:00
using UnityEngine;
using Pixelplacement.TweenSystem;
using Core.SaveLoad;
using Pixelplacement;
using UnityEngine.Serialization;
2025-09-10 22:17:51 +02:00
public class GardenerChaseBehavior : SaveableState
2025-09-10 22:17:51 +02:00
{
private static readonly int Property = Animator.StringToHash("IsIdle?");
public Spline chaseSpline;
public Transform runningGardenerTransform;
2025-09-10 22:17:51 +02:00
public float chaseDuration;
public float chaseDelay;
[SerializeField] private Animator animator;
[SerializeField] public GameObject lawnMowerRef;
private TweenBase tweenRef;
2025-10-20 16:21:32 +02:00
public GardenerAudioController audioController;
public GameObject lawnmowerAnchor;
2025-10-20 16:21:32 +02:00
2025-09-10 22:17:51 +02:00
// Start is called once before the first execution of Update after the MonoBehaviour is created
public override void OnEnterState()
2025-09-10 22:17:51 +02:00
{
tweenRef = Tween.Spline(chaseSpline, runningGardenerTransform, 0, 1, false, chaseDuration, chaseDelay, Tween.EaseLinear,
Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished);
}
public override void OnRestoreState(string data)
{
animator.SetBool("IsIdle?", false);
var gardenerSpriteRef = runningGardenerTransform.gameObject;
gardenerSpriteRef.transform.SetPositionAndRotation(lawnmowerAnchor.transform.position, gardenerSpriteRef.transform.rotation);
HandleTweenFinished();
}
void HandleTweenFinished ()
{
Debug.Log ("Tween finished!");
tweenRef?.Stop();
Destroy(chaseSpline);
var gardenerSpriteRef = runningGardenerTransform.gameObject;
gardenerSpriteRef.transform.SetParent(lawnMowerRef.transform, true);
animator.SetBool(Property, false);
StartCoroutine(UpdateAnimatorBoolAfterDelay(0.5f));
}
private IEnumerator UpdateAnimatorBoolAfterDelay(float delay)
{
yield return new WaitForSeconds(delay);
animator.SetBool(Property, false);
}
void HandleTweenStarted ()
{
//Debug.Log ("Tween started!");
animator.SetBool("IsIdle?", false);
2025-09-10 22:17:51 +02:00
}
}