Files cleanup, added summoner code
This commit is contained in:
125
Assets/AI/_Summoner/SA_SpawnMinions.cs
Normal file
125
Assets/AI/_Summoner/SA_SpawnMinions.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using Invector.vCharacterController.AI.FSMBehaviour;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DemonBoss.Summoner
|
||||
{
|
||||
/// <summary>
|
||||
/// FSM State Action that triggers minion spawning
|
||||
/// Calls SummonerAI.StartSpawning() on state enter
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Invector/FSM/Actions/Summoner/Spawn Minions")]
|
||||
public class SA_SpawnMinions : vStateAction
|
||||
{
|
||||
public override string categoryName => "Summoner";
|
||||
public override string defaultName => "Spawn Minions";
|
||||
|
||||
[Header("Animation")]
|
||||
[Tooltip("Animator trigger parameter for summoning animation")]
|
||||
public string summonTriggerName = "Summon";
|
||||
|
||||
[Tooltip("Animator bool for summoning state")]
|
||||
public string summoningBoolName = "IsSummoning";
|
||||
|
||||
[Header("Behavior")]
|
||||
[Tooltip("Wait for spawning to complete before allowing state exit")]
|
||||
public bool waitForCompletion = true;
|
||||
|
||||
[Header("Debug")]
|
||||
[Tooltip("Enable debug logging")]
|
||||
public bool enableDebug = false;
|
||||
|
||||
private SummonerAI summoner;
|
||||
private Animator animator;
|
||||
private bool hasStartedSpawning = false;
|
||||
|
||||
public override void DoAction(vIFSMBehaviourController fsmBehaviour, vFSMComponentExecutionType executionType = vFSMComponentExecutionType.OnStateUpdate)
|
||||
{
|
||||
if (executionType == vFSMComponentExecutionType.OnStateEnter)
|
||||
{
|
||||
OnEnter(fsmBehaviour);
|
||||
}
|
||||
else if (executionType == vFSMComponentExecutionType.OnStateUpdate)
|
||||
{
|
||||
OnUpdate(fsmBehaviour);
|
||||
}
|
||||
else if (executionType == vFSMComponentExecutionType.OnStateExit)
|
||||
{
|
||||
OnExit(fsmBehaviour);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnter(vIFSMBehaviourController fsmBehaviour)
|
||||
{
|
||||
summoner = fsmBehaviour.GetComponent<SummonerAI>();
|
||||
animator = fsmBehaviour.GetComponent<Animator>();
|
||||
|
||||
if (summoner == null)
|
||||
{
|
||||
Debug.LogError("[SA_SpawnMinions] No SummonerAI component found!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger animation
|
||||
if (animator != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(summonTriggerName))
|
||||
{
|
||||
animator.SetTrigger(summonTriggerName);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(summoningBoolName))
|
||||
{
|
||||
animator.SetBool(summoningBoolName, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Start spawning minions
|
||||
summoner.StartSpawning();
|
||||
hasStartedSpawning = true;
|
||||
|
||||
if (enableDebug) Debug.Log("[SA_SpawnMinions] Started spawning minions");
|
||||
}
|
||||
|
||||
private void OnUpdate(vIFSMBehaviourController fsmBehaviour)
|
||||
{
|
||||
// If waiting for completion, keep state active until spawning is done
|
||||
if (waitForCompletion && summoner != null && summoner.IsSpawning)
|
||||
{
|
||||
// State will continue until spawning is complete
|
||||
if (enableDebug && Time.frameCount % 60 == 0) // Log once per second
|
||||
{
|
||||
Debug.Log("[SA_SpawnMinions] Waiting for spawning to complete...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExit(vIFSMBehaviourController fsmBehaviour)
|
||||
{
|
||||
// Reset animation bool
|
||||
if (animator != null && !string.IsNullOrEmpty(summoningBoolName))
|
||||
{
|
||||
animator.SetBool(summoningBoolName, false);
|
||||
}
|
||||
|
||||
// If spawning was interrupted, stop it
|
||||
if (summoner != null && summoner.IsSpawning)
|
||||
{
|
||||
summoner.StopSpawning();
|
||||
if (enableDebug) Debug.Log("[SA_SpawnMinions] Spawning interrupted on state exit");
|
||||
}
|
||||
|
||||
hasStartedSpawning = false;
|
||||
|
||||
if (enableDebug) Debug.Log("[SA_SpawnMinions] State exited");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if spawning is complete (for FSM decision nodes)
|
||||
/// </summary>
|
||||
public bool IsSpawningComplete()
|
||||
{
|
||||
if (summoner == null) return true;
|
||||
return hasStartedSpawning && !summoner.IsSpawning;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user