1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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<ExitApplicationGameAction>(data);
- }
- #endregion
- }
- }
|