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