OpenUrlGameAction.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 OpenUrlGameAction : GameActionBase
  11. {
  12. #region DefaultVariables
  13. public override string name { get => $"Open URL ({url}) "; }
  14. public override GameActionsController controller {
  15. get => _controller;
  16. set
  17. {
  18. _controller = value;
  19. typeName = "OpenUrlGameAction";
  20. }
  21. }
  22. public override string GetTypeName() => "OpenUrlGameAction";
  23. public override string GetActionName() => "Core/Open URL";
  24. #endregion
  25. #region ActionVariables
  26. [FoldoutGroup("@name")] public string url = "https://www.example.com";
  27. #endregion
  28. public OpenUrlGameAction(GameActionsController controller) : base(controller)
  29. {
  30. this.controller = controller;
  31. className = this.GetType().AssemblyQualifiedName;
  32. }
  33. #region Flow
  34. public override void Start()
  35. {
  36. Application.OpenURL(url);
  37. _done = true;
  38. _started = true;
  39. }
  40. public override void Update()
  41. {
  42. }
  43. public override void Restart()
  44. {
  45. _done = false;
  46. _started = false;
  47. }
  48. #endregion
  49. #region Utilities
  50. private OpenUrlGameAction Duplicate(GameActionsController controller = null)
  51. {
  52. OpenUrlGameAction action = new OpenUrlGameAction(controller == null ? this.controller : controller);
  53. action.controller = controller;
  54. action.url = url;
  55. return action;
  56. }
  57. #endregion
  58. #region Serialization
  59. public static OpenUrlGameAction JSONToOpenUrlGameAction(string data)
  60. {
  61. return JsonUtility.FromJson<OpenUrlGameAction>(data);
  62. }
  63. #endregion
  64. }
  65. }