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 ExitApplicationGameAction : GameActionBase { #region DefaultVariables public override string name { get => $"Exit application in {time}s"; } public override GameActionsController controller { get => _controller; set { _controller = value; typeName = "ExitApplicationGameAction"; } } public override string GetTypeName() => "ExitApplicationGameAction"; public override string GetActionName() => "Core/Exit Application"; #endregion #region ActionVariables [FoldoutGroup("@name")] public float time = 1f; private float elapsedTime = 0f; #endregion public ExitApplicationGameAction(GameActionsController controller) : base(controller) { this.controller = controller; className = this.GetType().AssemblyQualifiedName; } #region Flow public override void Start() { elapsedTime = 0f; _done = false; _started = true; } public override void Update() { elapsedTime += Time.deltaTime; if(elapsedTime > time) { _done = true; #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } } public override void Restart() { _done = false; _started = false; elapsedTime = 0; } #endregion #region Utilities private ExitApplicationGameAction Duplicate(GameActionsController controller = null) { ExitApplicationGameAction action = new ExitApplicationGameAction(controller == null ? this.controller : controller); action.controller = controller; action.time = time; return action; } #endregion #region Serialization public static ExitApplicationGameAction JSONToExitApplicationGameAction(string data) { return JsonUtility.FromJson(data); } #endregion } }