Working gardener saveable behavior tree

This commit is contained in:
Michal Pikulski
2025-11-03 01:34:34 +01:00
parent 14416e141e
commit 3b7bc76757
23 changed files with 2373 additions and 61 deletions

View File

@@ -1,36 +1,55 @@
using System;
using System.Collections;
using UnityEngine;
using Pixelplacement;
using Pixelplacement.TweenSystem;
using Core.SaveLoad;
using Pixelplacement;
using UnityEngine.Serialization;
public class GardenerChaseBehavior : MonoBehaviour
public class GardenerChaseBehavior : SaveableState
{
public Spline ChaseSpline;
public Transform GardenerObject;
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
void Start()
public override void OnEnterState()
{
tweenRef = Tween.Spline (ChaseSpline, GardenerObject, 0, 1, false, chaseDuration, chaseDelay, Tween.EaseLinear, Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished);
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 = gameObject.transform.Find("GardenerRunningSprite");
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 ()
{
@@ -38,3 +57,4 @@ public class GardenerChaseBehavior : MonoBehaviour
animator.SetBool("IsIdle?", false);
}
}