61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using Pixelplacement.TweenSystem;
|
|
using Core.SaveLoad;
|
|
using Pixelplacement;
|
|
using UnityEngine.Serialization;
|
|
|
|
public class GardenerChaseBehavior : SaveableState
|
|
{
|
|
private static readonly int Property = Animator.StringToHash("IsIdle?");
|
|
public Spline chaseSpline;
|
|
public Transform runningGardenerTransform;
|
|
public float chaseDuration;
|
|
public float chaseDelay;
|
|
[SerializeField] private Animator animator;
|
|
[SerializeField] public GameObject lawnMowerRef;
|
|
private TweenBase tweenRef;
|
|
public GardenerAudioController audioController;
|
|
public GameObject lawnmowerAnchor;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
public override void OnEnterState()
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|