Maze / Library /PackageCache /com.unity.visualscripting@1.8.0 /Runtime /VisualScripting.Flow /Framework /Events /CustomEvent.cs
| using System; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| namespace Unity.VisualScripting | |
| { | |
| /// <summary> | |
| /// A special named event with any amount of parameters called manually with the 'Trigger Custom Event' unit. | |
| /// </summary> | |
| [] | |
| [] | |
| public sealed class CustomEvent : GameObjectEventUnit<CustomEventArgs> | |
| { | |
| public override Type MessageListenerType => null; | |
| protected override string hookName => EventHooks.Custom; | |
| [] | |
| private int _argumentCount; | |
| [] | |
| [] | |
| public int argumentCount | |
| { | |
| get => _argumentCount; | |
| set => _argumentCount = Mathf.Clamp(value, 0, 10); | |
| } | |
| /// <summary> | |
| /// The name of the event. | |
| /// </summary> | |
| [] | |
| [] | |
| public ValueInput name { get; private set; } | |
| [] | |
| public List<ValueOutput> argumentPorts { get; } = new List<ValueOutput>(); | |
| protected override void Definition() | |
| { | |
| base.Definition(); | |
| name = ValueInput(nameof(name), string.Empty); | |
| argumentPorts.Clear(); | |
| for (var i = 0; i < argumentCount; i++) | |
| { | |
| argumentPorts.Add(ValueOutput<object>("argument_" + i)); | |
| } | |
| } | |
| protected override bool ShouldTrigger(Flow flow, CustomEventArgs args) | |
| { | |
| return CompareNames(flow, name, args.name); | |
| } | |
| protected override void AssignArguments(Flow flow, CustomEventArgs args) | |
| { | |
| for (var i = 0; i < argumentCount; i++) | |
| { | |
| flow.SetValue(argumentPorts[i], args.arguments[i]); | |
| } | |
| } | |
| public static void Trigger(GameObject target, string name, params object[] args) | |
| { | |
| EventBus.Trigger(EventHooks.Custom, target, new CustomEventArgs(name, args)); | |
| } | |
| } | |
| } | |