WaitGameAction.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System.Collections;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Sirenix.OdinInspector;
  6. using KairoEngine.Core;
  7. namespace KairoEngine.Core.GameActions
  8. {
  9. [System.Serializable, HideReferenceObjectPicker]
  10. public class WaitGameAction : GameActionBase
  11. {
  12. #region DefaultVariables
  13. public override string name { get => $"Wait {time}s"; }
  14. public override GameActionsController controller {
  15. get => _controller;
  16. set
  17. {
  18. _controller = value;
  19. typeName = "WaitGameAction";
  20. }
  21. }
  22. public override string GetTypeName() => "WaitGameAction";
  23. public override string GetActionName() => "Core/Wait";
  24. #endregion
  25. #region ActionVariables
  26. [IconFoldoutGroup("@name", "Assets/Plugins/KairoEngine/Core/Editor/Icons/WaitGameActionIcon.png")] public float time = 1f;
  27. private float elapsedTime = 0f;
  28. #endregion
  29. public WaitGameAction(GameActionsController controller) : base(controller)
  30. {
  31. this.controller = controller;
  32. className = this.GetType().AssemblyQualifiedName;
  33. }
  34. #region Flow
  35. public override void Start()
  36. {
  37. elapsedTime = 0f;
  38. _done = false;
  39. _started = true;
  40. }
  41. public override void Update()
  42. {
  43. elapsedTime += Time.deltaTime;
  44. if(elapsedTime > time) _done = true;
  45. }
  46. public override void Restart()
  47. {
  48. _done = false;
  49. _started = false;
  50. elapsedTime = 0;
  51. }
  52. #endregion
  53. #region Utilities
  54. private WaitGameAction Duplicate(GameActionsController controller = null)
  55. {
  56. WaitGameAction action = new WaitGameAction(controller == null ? this.controller : controller);
  57. action.controller = controller;
  58. action.time = time;
  59. return action;
  60. }
  61. #endregion
  62. #region Serialization
  63. public static WaitGameAction JSONToWaitGameAction(string data)
  64. {
  65. return JsonUtility.FromJson<WaitGameAction>(data);
  66. }
  67. #endregion
  68. }
  69. }