using System; using UnityEngine; namespace UnityEditor.U2D.Path.GUIFramework { /// /// Represents an Action to process when the custom editor validates a command. /// public class CommandAction : GUIAction { private string m_CommandName; /// /// The Action to execute. /// public Action onCommand; /// /// Initializes and returns an instance of CommandAction /// /// The name of the command. When the custom editor validates a command with this name, it triggers the action. public CommandAction(string commandName) { m_CommandName = commandName; } /// /// Checks to see if the trigger condition has been met or not. /// /// The current state of the custom editor. /// Returns `true` if the trigger condition has been met. Otherwise, returns `false`. protected override bool GetTriggerContidtion(IGUIState guiState) { if (guiState.eventType == EventType.ValidateCommand && guiState.commandName == m_CommandName) { guiState.UseEvent(); return true; } return false; } /// /// Checks to see if the finish condition has been met or not. /// /// The current state of the custom editor. /// Returns `true` if the trigger condition is finished. Otherwise, returns `false`. protected override bool GetFinishContidtion(IGUIState guiState) { if (guiState.eventType == EventType.ExecuteCommand && guiState.commandName == m_CommandName) { guiState.UseEvent(); return true; } return false; } /// /// Calls the methods in its invocation list when the finish condition is met. /// /// The current state of the custom editor. protected override void OnFinish(IGUIState guiState) { if (onCommand != null) onCommand(guiState); } } }