using System;
using UnityEngine;
namespace UnityEditor.U2D.Path.GUIFramework
{
///
/// SliderAction implementation of a ClickAction
///
public class SliderAction : ClickAction
{
private SliderData m_SliderData;
///
/// Action for OnSliderBegin
///
public Action onSliderBegin;
///
/// Action for OnSliderChanged
///
public Action onSliderChanged;
///
/// Action for OnSliderEnd
///
public Action onSliderEnd;
///
/// Initializes and returns an instance of SliderAction
///
/// The control to execcute an action for on slide.
public SliderAction(Control control) : base(control, 0, false)
{
}
///
/// Checks to see if the finish condition has been met or not.
///
/// The current state of the custom editor.
/// Returns `true` if the finish condition has been met. Otherwise, returns `false`.
protected override bool GetFinishContidtion(IGUIState guiState)
{
return guiState.eventType == EventType.MouseUp && guiState.mouseButton == 0;
}
///
/// Called when there is interaction with the slider. It updates the stored slider data with data post-interaction.
///
/// The current state of the custom editor.
protected override void OnTrigger(IGUIState guiState)
{
base.OnTrigger(guiState);
m_SliderData.position = hoveredControl.hotLayoutData.position;
m_SliderData.forward = hoveredControl.hotLayoutData.forward;
m_SliderData.right = hoveredControl.hotLayoutData.right;
m_SliderData.up = hoveredControl.hotLayoutData.up;
if (onSliderBegin != null)
onSliderBegin(guiState, hoveredControl, m_SliderData.position);
}
///
/// Post-processing for when the slider interaction finishes.
///
/// The current state of the custom editor.
protected override void OnFinish(IGUIState guiState)
{
if (onSliderEnd != null)
onSliderEnd(guiState, hoveredControl, m_SliderData.position);
guiState.UseEvent();
guiState.Repaint();
}
///
/// Moves the slider to the new permission and executes `onSliderChanged` using the new position.
///
/// The current state of the custom editor
protected override void OnPerform(IGUIState guiState)
{
Vector3 newPosition;
var changed = guiState.Slider(ID, m_SliderData, out newPosition);
if (changed)
{
m_SliderData.position = newPosition;
if (onSliderChanged != null)
onSliderChanged(guiState, hoveredControl, newPosition);
}
}
}
}