Files
Convention-Unity-Demo/Assets/Plugins/CW/LeanGUI/Required/Scripts/LeanSnapEvent.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2025-09-25 19:04:05 +08:00
using UnityEngine;
using UnityEngine.Events;
using CW.Common;
namespace Lean.Gui
{
/// <summary>This component allows you to fire an events when the <b>LeanSnap</b> component's <b>Position</b> is at specific values.</summary>
[ExecuteInEditMode]
[RequireComponent(typeof(LeanSnap))]
[HelpURL(LeanGui.HelpUrlPrefix + "LeanSnapEvent")]
[AddComponentMenu(LeanGui.ComponentMenuPrefix + "Snap Event")]
public class LeanSnapEvent : MonoBehaviour
{
/// <summary>The <b>LeanSnap.Position</b> you want to listen for.</summary>
public Vector2Int Position { set { position = value; } get { return position; } } [SerializeField] private Vector2Int position;
/// <summary>The action that will be invoked.</summary>
public UnityEvent OnAction { get { if (onAction == null) onAction = new UnityEvent(); return onAction; } } [SerializeField] private UnityEvent onAction;
}
}
#if UNITY_EDITOR
namespace Lean.Gui.Editor
{
using UnityEditor;
using TARGET = LeanSnapEvent;
[CanEditMultipleObjects]
[CustomEditor(typeof(TARGET))]
public class LeanSnapEvent_Editor : CwEditor
{
protected override void OnInspector()
{
TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);
Draw("position", "The LeanSnap.Position you want to listen for.");
Draw("onAction");
}
}
}
#endif