SetEditorStateCommand.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using JetBrains.Annotations;
  2. using LLM.Editor.Helper;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace LLM.Editor.Commands
  6. {
  7. public enum EditorTargetState
  8. {
  9. Play,
  10. Pause,
  11. Stop
  12. }
  13. [System.Serializable]
  14. public class SetEditorStateParams
  15. {
  16. public EditorTargetState state;
  17. }
  18. [UsedImplicitly]
  19. public class SetEditorStateCommand : ICommand
  20. {
  21. private readonly SetEditorStateParams _params;
  22. public SetEditorStateCommand(string jsonParams)
  23. {
  24. _params = jsonParams?.FromJson<SetEditorStateParams>();
  25. }
  26. public CommandOutcome Execute(Data.CommandContext context)
  27. {
  28. if (_params == null)
  29. {
  30. Debug.LogError("[SetEditorStateCommand] Invalid parameters.");
  31. return CommandOutcome.Error;
  32. }
  33. switch (_params.state)
  34. {
  35. case EditorTargetState.Play:
  36. EditorApplication.EnterPlaymode();
  37. break;
  38. case EditorTargetState.Pause:
  39. EditorApplication.isPaused = true;
  40. break;
  41. case EditorTargetState.Stop:
  42. EditorApplication.ExitPlaymode();
  43. break;
  44. }
  45. Debug.Log($"[SetEditorStateCommand] Set editor state to: {_params.state}");
  46. return CommandOutcome.Success;
  47. }
  48. }
  49. }