TransitionGameAction.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. using KairoEngine.Core.GameActions;
  8. namespace KairoEngine.UI.GameActions
  9. {
  10. [System.Serializable, HideReferenceObjectPicker]
  11. public class TransitionGameAction : GameActionBase
  12. {
  13. public enum ActionType
  14. {
  15. FadeIn,
  16. FadeOut
  17. }
  18. public override string name
  19. {
  20. get
  21. {
  22. if(actionType == ActionType.FadeIn) return "Fade In";
  23. else if(actionType == ActionType.FadeOut) return "Fade Out";
  24. else return "Transition";
  25. }
  26. }
  27. public override GameActionsController controller {
  28. get => _controller;
  29. set
  30. {
  31. _controller = value;
  32. typeName = "TransitionGameAction";
  33. className = this.GetType().AssemblyQualifiedName;
  34. }
  35. }
  36. public override string GetTypeName() => "TransitionGameAction";
  37. public override string GetActionName() => "UI/Transition";
  38. [FoldoutGroup("@name")] public ActionType actionType = ActionType.FadeIn;
  39. [FoldoutGroup("@name")] public float fadeTime = 0.7f;
  40. public TransitionGameAction(GameActionsController controller) : base(controller)
  41. {
  42. this.controller = controller;
  43. className = this.GetType().AssemblyQualifiedName;
  44. }
  45. public override void Start()
  46. {
  47. if (actionType == ActionType.FadeIn) TransitionController.FadeIn(fadeTime);
  48. else if (actionType == ActionType.FadeOut) TransitionController.FadeOut(fadeTime);
  49. _done = true;
  50. _started = true;
  51. }
  52. public override void Update() { }
  53. public override void Restart()
  54. {
  55. _done = false;
  56. _started = false;
  57. }
  58. public static TransitionGameAction JSONToTransitionGameAction(string data)
  59. {
  60. return JsonUtility.FromJson<TransitionGameAction>(data);
  61. }
  62. private TransitionGameAction Duplicate(GameActionsController controller = null)
  63. {
  64. TransitionGameAction action = new TransitionGameAction(controller == null ? this.controller : controller);
  65. action.controller = controller;
  66. action.actionType = actionType;
  67. return action;
  68. }
  69. }
  70. }