using System;
using UnityEngine;
namespace UnityEditor.U2D.Path.GUIFramework
{
///
/// Represents an Action to process when the user clicks a particular mouse button a certain number of times.
///
public class ClickAction : HoveredControlAction
{
private int m_Button;
private bool m_UseEvent;
///
/// The number of button clicks required to satisfy the trigger condition
///
public int clickCount = 1;
///
/// The Action to execute when the user satisfies the trigger condition.
///
public Action onClick;
private int m_ClickCounter = 0;
///
/// Initializes and returns an instance of ClickAction
///
/// Current control
/// The mouse button to check for.
/// Whether to Use the current event after the trigger condition has been met.
public ClickAction(Control control, int button, bool useEvent = true) : base(control)
{
m_Button = button;
m_UseEvent = useEvent;
}
///
/// 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.mouseButton == m_Button && guiState.eventType == EventType.MouseDown)
{
if (guiState.clickCount == 1)
m_ClickCounter = 0;
++m_ClickCounter;
if (m_ClickCounter == clickCount)
return true;
}
return false;
}
///
/// Calls the methods in its invocation list when the trigger conditions are met.
///
/// The current state of the custom editor.
protected override void OnTrigger(IGUIState guiState)
{
base.OnTrigger(guiState);
if (onClick != null)
onClick(guiState, hoveredControl);
if (m_UseEvent)
guiState.UseEvent();
}
///
/// Checks to see if the finish condition has been met or not. For a ClickAction, this is always `true`.
///
/// The current state of the custom editor.
/// Returns `true`.
protected override bool GetFinishContidtion(IGUIState guiState)
{
return true;
}
}
}