No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandAction.cs 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Path.GUIFramework
  4. {
  5. /// <summary>
  6. /// Represents an Action to process when the custom editor validates a command.
  7. /// </summary>
  8. public class CommandAction : GUIAction
  9. {
  10. private string m_CommandName;
  11. /// <summary>
  12. /// The Action to execute.
  13. /// </summary>
  14. public Action<IGUIState> onCommand;
  15. /// <summary>
  16. /// Initializes and returns an instance of CommandAction
  17. /// </summary>
  18. /// <param name="commandName">The name of the command. When the custom editor validates a command with this name, it triggers the action.</param>
  19. public CommandAction(string commandName)
  20. {
  21. m_CommandName = commandName;
  22. }
  23. /// <summary>
  24. /// Checks to see if the trigger condition has been met or not.
  25. /// </summary>
  26. /// <param name="guiState">The current state of the custom editor.</param>
  27. /// <returns>Returns `true` if the trigger condition has been met. Otherwise, returns `false`.</returns>
  28. protected override bool GetTriggerContidtion(IGUIState guiState)
  29. {
  30. if (guiState.eventType == EventType.ValidateCommand && guiState.commandName == m_CommandName)
  31. {
  32. guiState.UseEvent();
  33. return true;
  34. }
  35. return false;
  36. }
  37. /// <summary>
  38. /// Checks to see if the finish condition has been met or not.
  39. /// </summary>
  40. /// <param name="guiState">The current state of the custom editor.</param>
  41. /// <returns>Returns `true` if the trigger condition is finished. Otherwise, returns `false`.</returns>
  42. protected override bool GetFinishContidtion(IGUIState guiState)
  43. {
  44. if (guiState.eventType == EventType.ExecuteCommand && guiState.commandName == m_CommandName)
  45. {
  46. guiState.UseEvent();
  47. return true;
  48. }
  49. return false;
  50. }
  51. /// <summary>
  52. /// Calls the methods in its invocation list when the finish condition is met.
  53. /// </summary>
  54. /// <param name="guiState">The current state of the custom editor.</param>
  55. protected override void OnFinish(IGUIState guiState)
  56. {
  57. if (onCommand != null)
  58. onCommand(guiState);
  59. }
  60. }
  61. }