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 user clicks a particular mouse button a certain number of times.
8 /// </summary>
9 internal class ClickAction : HoveredControlAction
10 {
11 private int m_Button;
12 private bool m_UseEvent;
13 /// <summary>
14 /// The number of button clicks required to satisfy the trigger condition
15 /// </summary>
16 public int clickCount = 1;
17 /// <summary>
18 /// The Action to execute when the user satisfies the trigger condition.
19 /// </summary>
20 public Action<IGUIState, Control> onClick;
21 private int m_ClickCounter = 0;
22
23 /// <summary>
24 /// Initializes and returns an instance of ClickAction
25 /// </summary>
26 /// <param name="control">Current control</param>
27 /// <param name="button">The mouse button to check for.</param>
28 /// <param name="useEvent">Whether to Use the current event after the trigger condition has been met.</param>
29 public ClickAction(Control control, int button, bool useEvent = true) : base(control)
30 {
31 m_Button = button;
32 m_UseEvent = useEvent;
33 }
34
35 /// <summary>
36 /// Checks to see if the trigger condition has been met or not.
37 /// </summary>
38 /// <param name="guiState">The current state of the custom editor.</param>
39 /// <returns>Returns `true` if the trigger condition has been met. Otherwise, returns false.</returns>
40 protected override bool GetTriggerContidtion(IGUIState guiState)
41 {
42 if (guiState.mouseButton == m_Button && guiState.eventType == EventType.MouseDown)
43 {
44 if (guiState.clickCount == 1)
45 m_ClickCounter = 0;
46
47 ++m_ClickCounter;
48
49 if (m_ClickCounter == clickCount)
50 return true;
51 }
52
53 return false;
54 }
55
56 /// <summary>
57 /// Calls the methods in its invocation list when the trigger conditions are met.
58 /// </summary>
59 /// <param name="guiState">The current state of the custom editor.</param>
60 protected override void OnTrigger(IGUIState guiState)
61 {
62 base.OnTrigger(guiState);
63
64 if (onClick != null)
65 onClick(guiState, hoveredControl);
66
67 if (m_UseEvent)
68 guiState.UseEvent();
69 }
70
71 /// <summary>
72 /// Checks to see if the finish condition has been met or not. For a ClickAction, this is always `true`.
73 /// </summary>
74 /// <param name="guiState">The current state of the custom editor.</param>
75 /// <returns>Returns `true`.</returns>
76 protected override bool GetFinishContidtion(IGUIState guiState)
77 {
78 return true;
79 }
80 }
81}