123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- namespace KairoEngine.Core
- {
- public class ActionController : MonoBehaviour
- {
- [ShowInInspector]
- private List<IAction> actionList;
-
- void Start()
- {
- actionList = new List<IAction>();
- }
- 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<IAction>();
- }
- }
- }
|