using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; namespace KairoEngine.Core { public class ActionController : MonoBehaviour { [ShowInInspector] private List actionList; void Start() { actionList = new List(); } void Update() { // Remove actions that are done for (int i = 0; i < actionList.Count; i++) { if(actionList[i].IsDone()) { actionList.RemoveAt(i); i -= 1; } } // Run Update on all actions for (int i = 0; i < actionList.Count; i++) { actionList[i].Update(); } } public void AddAction(IAction action) { if(actionList == null || action == null) return; action.Start(); actionList.Add(action); } public bool HasAction(IAction action) { if(actionList == null) return false; for (int i = 0; i < actionList.Count; i++) { if(actionList[i].GetType().ToString() == action.GetType().ToString()) { return true; } } return false; } public bool IsActionDone(IAction action) { for (int i = 0; i < actionList.Count; i++) { if(actionList[i] == action) { return actionList[i].IsDone(); } } return false; } public void ChangeAction(IAction action) { for (int i = 0; i < actionList.Count; i++) { if(actionList[i].GetType() == action.GetType()) { actionList[i] = action; //actionList[i].Start(); } } } public void CancelAction(string actionType) { for (int i = 0; i < actionList.Count; i++) { if(actionList[i].GetType().ToString() == "kairoEngine." + actionType) { actionList[i].End(); } } } public void CancelActions() { if(actionList == null) return; for (int i = 0; i < actionList.Count; i++) { actionList[i].End(); } actionList = new List(); } } }