unity-atoms/Packages/FSM/Runtime/FiniteStateMachine/FiniteStateMachineInstancer.cs

33 lines
1.2 KiB
C#
Raw Normal View History

2020-03-08 08:24:46 -04:00
using UnityEngine;
using UnityAtoms.BaseAtoms;
namespace UnityAtoms.FSM
{
2020-03-21 17:45:39 -04:00
/// <summary>
/// Takes a base FSM and creates an in memory copy of it on OnEnable. Removes the FSM on OnDestroy.
/// </summary>
2020-03-08 08:24:46 -04:00
[EditorIcon("atom-icon-hotpink")]
2020-03-08 19:16:40 -04:00
[AddComponentMenu("Unity Atoms/FSM/Finite State Machine Instancer")]
2020-03-11 16:11:27 -04:00
public class FiniteStateMachineInstancer : StringVariableInstancer
2020-03-08 08:24:46 -04:00
{
2020-03-11 16:11:27 -04:00
public override StringVariable Base { get => (StringVariable)_fsmBase; }
/// <summary>
/// The variable that the in memory copy will be based on when created at runtime.
/// </summary>
[SerializeField]
private FiniteStateMachine _fsmBase = null;
2020-03-08 08:24:46 -04:00
protected override void ImplSpecificSetup()
{
2020-03-11 16:11:27 -04:00
if (((FiniteStateMachine)Base).TransitionStarted != null)
2020-03-08 08:24:46 -04:00
{
2020-03-11 16:11:27 -04:00
((FiniteStateMachine)_inMemoryCopy).TransitionStarted = Instantiate(((FiniteStateMachine)Base).TransitionStarted);
2020-03-08 08:24:46 -04:00
}
2020-03-11 16:11:27 -04:00
if (((FiniteStateMachine)Base).CompleteCurrentTransition != null)
2020-03-08 08:24:46 -04:00
{
2020-03-11 16:11:27 -04:00
((FiniteStateMachine)_inMemoryCopy).CompleteCurrentTransition = Instantiate(((FiniteStateMachine)Base).CompleteCurrentTransition);
2020-03-08 08:24:46 -04:00
}
}
}
}