Files
.vs
Assets
Library
APIUpdater
Artifacts
Bee
BuildPlayerData
PackageCache
com.unity.collab-proxy@2.5.2
com.unity.editorcoroutines@1.0.0
com.unity.ext.nunit@1.0.6
com.unity.feature.development@1.0.1
com.unity.ide.rider@3.0.31
com.unity.ide.visualstudio@2.0.22
com.unity.ide.vscode@1.2.5
com.unity.modules.ai@1.0.0
com.unity.modules.androidjni@1.0.0
com.unity.modules.animation@1.0.0
com.unity.modules.assetbundle@1.0.0
com.unity.modules.audio@1.0.0
com.unity.modules.cloth@1.0.0
com.unity.modules.director@1.0.0
com.unity.modules.imageconversion@1.0.0
com.unity.modules.imgui@1.0.0
com.unity.modules.jsonserialize@1.0.0
com.unity.modules.particlesystem@1.0.0
com.unity.modules.physics2d@1.0.0
com.unity.modules.physics@1.0.0
com.unity.modules.screencapture@1.0.0
com.unity.modules.subsystems@1.0.0
com.unity.modules.terrain@1.0.0
com.unity.modules.terrainphysics@1.0.0
com.unity.modules.tilemap@1.0.0
com.unity.modules.ui@1.0.0
com.unity.modules.uielements@1.0.0
com.unity.modules.umbra@1.0.0
com.unity.modules.unityanalytics@1.0.0
com.unity.modules.unitywebrequest@1.0.0
com.unity.modules.unitywebrequestassetbundle@1.0.0
com.unity.modules.unitywebrequestaudio@1.0.0
com.unity.modules.unitywebrequesttexture@1.0.0
com.unity.modules.unitywebrequestwww@1.0.0
com.unity.modules.vehicles@1.0.0
com.unity.modules.video@1.0.0
com.unity.modules.vr@1.0.0
com.unity.modules.wind@1.0.0
com.unity.modules.xr@1.0.0
com.unity.performance.profile-analyzer@1.2.2
com.unity.settings-manager@2.0.1
com.unity.test-framework@1.1.33
com.unity.testtools.codecoverage@1.2.6
com.unity.textmeshpro@3.0.6
com.unity.timeline@1.7.6
com.unity.ugui@1.0.0
Documentation~
Editor
Runtime
EventSystem
EventData
InputModules
Raycasters
UIElements
EventData.meta
EventHandle.cs
EventHandle.cs.meta
EventInterfaces.cs
EventInterfaces.cs.meta
EventSystem.cs
EventSystem.cs.meta
EventTrigger.cs
EventTrigger.cs.meta
EventTriggerType.cs
EventTriggerType.cs.meta
ExecuteEvents.cs
ExecuteEvents.cs.meta
InputModules.meta
MoveDirection.cs
MoveDirection.cs.meta
RaycastResult.cs
RaycastResult.cs.meta
RaycasterManager.cs
RaycasterManager.cs.meta
Raycasters.meta
UIBehaviour.cs
UIBehaviour.cs.meta
UIElements.meta
Properties
UI
EventSystem.meta
Properties.meta
UI.meta
UnityEngine.UI.asmdef
UnityEngine.UI.asmdef.meta
Tests
CHANGELOG.md
CHANGELOG.md.meta
Editor.meta
LICENSE.md
LICENSE.md.meta
README.md
README.md.meta
Runtime.meta
Tests.meta
package.json
package.json.meta
com.unity.visualscripting@1.9.4
PackageManager
PlayModeViewStates
PlayerDataCache
ScriptAssemblies
Search
ShaderCache
SplashScreenCache
StateCache
UIElements
AnnotationManager
ArtifactDB
ArtifactDB-lock
BuildPlayer.prefs
BuildSettings.asset
EditorOnlyScriptingSettings.json
EditorOnlyVirtualTextureState.json
EditorSnapSettings.asset
EditorUserBuildSettings.asset
InspectorExpandedItems.asset
LastBuild.buildreport
LastSceneManagerSetup.txt
LibraryFormatVersion.txt
MonoManager.asset
SceneVisibilityState.asset
ScriptMapper
ShaderCache.db
SourceAssetDB
SourceAssetDB-lock
SpriteAtlasDatabase.asset
Style.catalog
expandedItems
ilpp.pid
Logs
Packages
ProjectSettings
UserSettings
obj
.vsconfig
Assembly-CSharp.Player.csproj
Assembly-CSharp.csproj
TM1.sln
Unity.CollabProxy.Editor.csproj
Unity.EditorCoroutines.Editor.csproj
Unity.Performance.Profile-Analyzer.Editor.csproj
Unity.PlasticSCM.Editor.csproj
Unity.Rider.Editor.csproj
Unity.Settings.Editor.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Model.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Mono.Reflection.csproj
Unity.TestTools.CodeCoverage.Editor.csproj
Unity.TextMeshPro.Editor.csproj
Unity.TextMeshPro.Player.csproj
Unity.TextMeshPro.csproj
Unity.Timeline.Editor.csproj
Unity.Timeline.Player.csproj
Unity.Timeline.csproj
Unity.VSCode.Editor.csproj
Unity.VisualScripting.Core.Editor.csproj
Unity.VisualScripting.Core.Player.csproj
Unity.VisualScripting.Core.csproj
Unity.VisualScripting.Flow.Editor.csproj
Unity.VisualScripting.Flow.Player.csproj
Unity.VisualScripting.Flow.csproj
Unity.VisualScripting.SettingsProvider.Editor.csproj
Unity.VisualScripting.Shared.Editor.csproj
Unity.VisualScripting.State.Editor.csproj
Unity.VisualScripting.State.Player.csproj
Unity.VisualScripting.State.csproj
Unity.VisualStudio.Editor.csproj
UnityEditor.TestRunner.csproj
UnityEditor.UI.csproj
UnityEngine.TestRunner.Player.csproj
UnityEngine.TestRunner.csproj
UnityEngine.UI.Player.csproj
UnityEngine.UI.csproj

359 lines
12 KiB
C#
Raw Permalink Normal View History

2025-01-17 13:10:20 +01:00
using System;
using System.Collections.Generic;
using UnityEngine.Events;
using UnityEngine.Serialization;
namespace UnityEngine.EventSystems
{
[AddComponentMenu("Event/Event Trigger")]
/// <summary>
/// Receives events from the EventSystem and calls registered functions for each event.
/// </summary>
/// <remarks>
/// The EventTrigger can be used to specify functions you wish to be called for each EventSystem event.
/// You can assign multiple functions to a single event and whenever the EventTrigger receives that event it will call those functions in the order they were provided.
///
/// NOTE: Attaching this component to a GameObject will make that object intercept ALL events, and no events will propagate to parent objects.
/// </remarks>
/// <example>
/// There are two ways to intercept events: You could extend EventTrigger, and override the functions for the events you are interested in intercepting; as shown in this example:
/// <code>
/// <![CDATA[
/// using UnityEngine;
/// using UnityEngine.EventSystems;
///
/// public class EventTriggerExample : EventTrigger
/// {
/// public override void OnBeginDrag(PointerEventData data)
/// {
/// Debug.Log("OnBeginDrag called.");
/// }
///
/// public override void OnCancel(BaseEventData data)
/// {
/// Debug.Log("OnCancel called.");
/// }
///
/// public override void OnDeselect(BaseEventData data)
/// {
/// Debug.Log("OnDeselect called.");
/// }
///
/// public override void OnDrag(PointerEventData data)
/// {
/// Debug.Log("OnDrag called.");
/// }
///
/// public override void OnDrop(PointerEventData data)
/// {
/// Debug.Log("OnDrop called.");
/// }
///
/// public override void OnEndDrag(PointerEventData data)
/// {
/// Debug.Log("OnEndDrag called.");
/// }
///
/// public override void OnInitializePotentialDrag(PointerEventData data)
/// {
/// Debug.Log("OnInitializePotentialDrag called.");
/// }
///
/// public override void OnMove(AxisEventData data)
/// {
/// Debug.Log("OnMove called.");
/// }
///
/// public override void OnPointerClick(PointerEventData data)
/// {
/// Debug.Log("OnPointerClick called.");
/// }
///
/// public override void OnPointerDown(PointerEventData data)
/// {
/// Debug.Log("OnPointerDown called.");
/// }
///
/// public override void OnPointerEnter(PointerEventData data)
/// {
/// Debug.Log("OnPointerEnter called.");
/// }
///
/// public override void OnPointerExit(PointerEventData data)
/// {
/// Debug.Log("OnPointerExit called.");
/// }
///
/// public override void OnPointerUp(PointerEventData data)
/// {
/// Debug.Log("OnPointerUp called.");
/// }
///
/// public override void OnScroll(PointerEventData data)
/// {
/// Debug.Log("OnScroll called.");
/// }
///
/// public override void OnSelect(BaseEventData data)
/// {
/// Debug.Log("OnSelect called.");
/// }
///
/// public override void OnSubmit(BaseEventData data)
/// {
/// Debug.Log("OnSubmit called.");
/// }
///
/// public override void OnUpdateSelected(BaseEventData data)
/// {
/// Debug.Log("OnUpdateSelected called.");
/// }
/// }
/// ]]>
///</code>
/// or you can specify individual delegates:
/// <code>
/// <![CDATA[
/// using UnityEngine;
/// using UnityEngine.EventSystems;
///
///
/// public class EventTriggerDelegateExample : MonoBehaviour
/// {
/// void Start()
/// {
/// EventTrigger trigger = GetComponent<EventTrigger>();
/// EventTrigger.Entry entry = new EventTrigger.Entry();
/// entry.eventID = EventTriggerType.PointerDown;
/// entry.callback.AddListener((data) => { OnPointerDownDelegate((PointerEventData)data); });
/// trigger.triggers.Add(entry);
/// }
///
/// public void OnPointerDownDelegate(PointerEventData data)
/// {
/// Debug.Log("OnPointerDownDelegate called.");
/// }
/// }
/// ]]>
///</code>
/// </example>
public class EventTrigger :
MonoBehaviour,
IPointerEnterHandler,
IPointerExitHandler,
IPointerDownHandler,
IPointerUpHandler,
IPointerClickHandler,
IInitializePotentialDragHandler,
IBeginDragHandler,
IDragHandler,
IEndDragHandler,
IDropHandler,
IScrollHandler,
IUpdateSelectedHandler,
ISelectHandler,
IDeselectHandler,
IMoveHandler,
ISubmitHandler,
ICancelHandler
{
[Serializable]
/// <summary>
/// UnityEvent class for Triggers.
/// </summary>
public class TriggerEvent : UnityEvent<BaseEventData>
{}
[Serializable]
/// <summary>
/// An Entry in the EventSystem delegates list.
/// </summary>
/// <remarks>
/// It stores the callback and which event type should this callback be fired.
/// </remarks>
public class Entry
{
/// <summary>
/// What type of event is the associated callback listening for.
/// </summary>
public EventTriggerType eventID = EventTriggerType.PointerClick;
/// <summary>
/// The desired TriggerEvent to be Invoked.
/// </summary>
public TriggerEvent callback = new TriggerEvent();
}
[FormerlySerializedAs("delegates")]
[SerializeField]
private List<Entry> m_Delegates;
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[Obsolete("Please use triggers instead (UnityUpgradable) -> triggers", true)]
public List<Entry> delegates { get { return triggers; } set { triggers = value; } }
protected EventTrigger()
{}
/// <summary>
/// All the functions registered in this EventTrigger
/// </summary>
public List<Entry> triggers
{
get
{
if (m_Delegates == null)
m_Delegates = new List<Entry>();
return m_Delegates;
}
set { m_Delegates = value; }
}
private void Execute(EventTriggerType id, BaseEventData eventData)
{
for (int i = 0; i < triggers.Count; ++i)
{
var ent = triggers[i];
if (ent.eventID == id && ent.callback != null)
ent.callback.Invoke(eventData);
}
}
/// <summary>
/// Called by the EventSystem when the pointer enters the object associated with this EventTrigger.
/// </summary>
public virtual void OnPointerEnter(PointerEventData eventData)
{
Execute(EventTriggerType.PointerEnter, eventData);
}
/// <summary>
/// Called by the EventSystem when the pointer exits the object associated with this EventTrigger.
/// </summary>
public virtual void OnPointerExit(PointerEventData eventData)
{
Execute(EventTriggerType.PointerExit, eventData);
}
/// <summary>
/// Called by the EventSystem every time the pointer is moved during dragging.
/// </summary>
public virtual void OnDrag(PointerEventData eventData)
{
Execute(EventTriggerType.Drag, eventData);
}
/// <summary>
/// Called by the EventSystem when an object accepts a drop.
/// </summary>
public virtual void OnDrop(PointerEventData eventData)
{
Execute(EventTriggerType.Drop, eventData);
}
/// <summary>
/// Called by the EventSystem when a PointerDown event occurs.
/// </summary>
public virtual void OnPointerDown(PointerEventData eventData)
{
Execute(EventTriggerType.PointerDown, eventData);
}
/// <summary>
/// Called by the EventSystem when a PointerUp event occurs.
/// </summary>
public virtual void OnPointerUp(PointerEventData eventData)
{
Execute(EventTriggerType.PointerUp, eventData);
}
/// <summary>
/// Called by the EventSystem when a Click event occurs.
/// </summary>
public virtual void OnPointerClick(PointerEventData eventData)
{
Execute(EventTriggerType.PointerClick, eventData);
}
/// <summary>
/// Called by the EventSystem when a Select event occurs.
/// </summary>
public virtual void OnSelect(BaseEventData eventData)
{
Execute(EventTriggerType.Select, eventData);
}
/// <summary>
/// Called by the EventSystem when a new object is being selected.
/// </summary>
public virtual void OnDeselect(BaseEventData eventData)
{
Execute(EventTriggerType.Deselect, eventData);
}
/// <summary>
/// Called by the EventSystem when a new Scroll event occurs.
/// </summary>
public virtual void OnScroll(PointerEventData eventData)
{
Execute(EventTriggerType.Scroll, eventData);
}
/// <summary>
/// Called by the EventSystem when a Move event occurs.
/// </summary>
public virtual void OnMove(AxisEventData eventData)
{
Execute(EventTriggerType.Move, eventData);
}
/// <summary>
/// Called by the EventSystem when the object associated with this EventTrigger is updated.
/// </summary>
public virtual void OnUpdateSelected(BaseEventData eventData)
{
Execute(EventTriggerType.UpdateSelected, eventData);
}
/// <summary>
/// Called by the EventSystem when a drag has been found, but before it is valid to begin the drag.
/// </summary>
public virtual void OnInitializePotentialDrag(PointerEventData eventData)
{
Execute(EventTriggerType.InitializePotentialDrag, eventData);
}
/// <summary>
/// Called before a drag is started.
/// </summary>
public virtual void OnBeginDrag(PointerEventData eventData)
{
Execute(EventTriggerType.BeginDrag, eventData);
}
/// <summary>
/// Called by the EventSystem once dragging ends.
/// </summary>
public virtual void OnEndDrag(PointerEventData eventData)
{
Execute(EventTriggerType.EndDrag, eventData);
}
/// <summary>
/// Called by the EventSystem when a Submit event occurs.
/// </summary>
public virtual void OnSubmit(BaseEventData eventData)
{
Execute(EventTriggerType.Submit, eventData);
}
/// <summary>
/// Called by the EventSystem when a Cancel event occurs.
/// </summary>
public virtual void OnCancel(BaseEventData eventData)
{
Execute(EventTriggerType.Cancel, eventData);
}
}
}