1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
using System; using UnityEngine; using System.Collections; public enum ScriptedAction { None, Attack, Special, Charge } [Serializable] public struct ScriptedEvent { public ScriptedAction AttackType; } public abstract class ScriptedEnemy : Enemy { [SerializeField] ScriptedEvent[] _attackSequence; private int _eventIndex; public override void Engage() { base.Engage(); _eventIndex = 0; } protected override void AttackCaller(CombatManager combatManager) { Action<CombatManager>[] actions = { NoneAction, AttackAction, SpecialAction, ChargeAction }; actions[(int)_attackSequence[_eventIndex].AttackType](combatManager); _eventIndex = (_eventIndex + 1) % _attackSequence.Length; } protected override IEnumerator DoHandleAttack(CombatManager combatManager) { yield return Yielders.Wait(.3f); AttackCaller(combatManager); } protected IEnumerator DoAttack(Action action, float delay) { while (IsEngaged == false) { yield return null; } float waitTime = delay; while (waitTime > 0) { if (IsEngaged) { waitTime -= Time.deltaTime; } yield return null; } action(); } protected virtual void NoneAction(CombatManager combatManager) { // This space intentionally left blank. } protected virtual void AttackAction(CombatManager combatManager) { StartCoroutine(DoAttack(() => { combatManager.Attack(this, Element.Type.None, Attack, combatManager.ActiveHero); }, 0.3f)); Animator.SetTrigger("Attack"); } protected virtual void SpecialAction(CombatManager combatManager) { // This space intentionally left blank. } protected virtual void ChargeAction(CombatManager combatManager) { // This space intentionally left blank. } } |