using System.Collections; using System.Linq; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; using KairoEngine.Core; namespace KairoEngine.Core.GameActions { [System.Serializable, HideReferenceObjectPicker] public class WaitGameAction : GameActionBase { #region DefaultVariables public override string name { get => $"Wait {time}s"; } public override GameActionsController controller { get => _controller; set { _controller = value; typeName = "WaitGameAction"; } } public override string GetTypeName() => "WaitGameAction"; public override string GetActionName() => "Core/Wait"; #endregion #region ActionVariables private string GetIconPath { get { if(_iconPath == "") _iconPath = Utilities.FindFileByName("WaitGameActionIcon.png"); return _iconPath; } } [SerializeField, HideInInspector] private string _iconPath = ""; [IconFoldoutGroup("@name", "@GetIconPath")] public float time = 1f; [IconFoldoutGroup("@name", "@GetIconPath")] public bool realtime = true; private float elapsedTime = 0f; #endregion public WaitGameAction(GameActionsController controller) : base(controller) { this.controller = controller; className = this.GetType().AssemblyQualifiedName; } #region Flow public override void Start() { elapsedTime = 0f; _done = false; _started = true; if(realtime) { Timer.ExecuteRealTime(time * 1000, () => { _done = true; }); // Timer.StartRealtime(time, () => { // _done = true; // }); } } public override void Update() { if(!realtime) { elapsedTime += Time.deltaTime; if(elapsedTime > time) _done = true; } } public override void Restart() { _done = false; _started = false; elapsedTime = 0; } #endregion #region Utilities private WaitGameAction Duplicate(GameActionsController controller = null) { WaitGameAction action = new WaitGameAction(controller == null ? this.controller : controller); action.controller = controller; action.time = time; return action; } #endregion #region Serialization public static WaitGameAction JSONToWaitGameAction(string data) { return JsonUtility.FromJson(data); } #endregion } }