51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class BaseEnemyTurn : MonoBehaviour
|
|
{
|
|
public static BaseEnemyTurn basic;
|
|
public List<EnemyLoopTurn> enemyLoopTurns;
|
|
public GameObject currentEnemy;
|
|
|
|
private void Awake()
|
|
{
|
|
if (basic != null && basic != this)
|
|
{
|
|
Debug.LogWarning("2 base enemy turn on the scene");
|
|
Destroy(this);
|
|
return;
|
|
}
|
|
|
|
basic = this;
|
|
}
|
|
public void FindLoopTurn(GameObject _enemy, int _phaseAttack)
|
|
{
|
|
for(int i = 0; i < enemyLoopTurns.Count; i++)
|
|
{
|
|
if(enemyLoopTurns[i].config == _enemy.GetComponent<Enemy>().enemyConfig)
|
|
{
|
|
currentEnemy = _enemy;
|
|
int _phase = _phaseAttack % enemyLoopTurns[i].attackLoop.Count;
|
|
Debug.Log(_phase + " " + _enemy.name);
|
|
enemyLoopTurns[i].attackLoop[_phase]?.Invoke();
|
|
return;
|
|
}
|
|
}
|
|
Debug.LogError("Loop not found");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
[Serializable]
|
|
public class EnemyLoopTurn
|
|
{
|
|
[Tooltip("the config is necessary to find the right chain of actions")]
|
|
public EnemyConfig config;
|
|
public List<UnityEvent> attackLoop = new List<UnityEvent>();
|
|
}
|
|
|