A game about forced loneliness, made by TACStudios
1using System; 2using System.Collections.Generic; 3using UnityEngine; 4 5namespace Unity.VisualScripting 6{ 7 /// <summary> 8 /// A special named event with any amount of parameters called manually with the 'Trigger Custom Event' unit. 9 /// </summary> 10 [UnitCategory("Events")] 11 [UnitOrder(0)] 12 public sealed class CustomEvent : GameObjectEventUnit<CustomEventArgs> 13 { 14 public override Type MessageListenerType => null; 15 protected override string hookName => EventHooks.Custom; 16 17 [SerializeAs(nameof(argumentCount))] 18 private int _argumentCount; 19 20 [DoNotSerialize] 21 [Inspectable, UnitHeaderInspectable("Arguments")] 22 public int argumentCount 23 { 24 get => _argumentCount; 25 set => _argumentCount = Mathf.Clamp(value, 0, 10); 26 } 27 28 /// <summary> 29 /// The name of the event. 30 /// </summary> 31 [DoNotSerialize] 32 [PortLabelHidden] 33 public ValueInput name { get; private set; } 34 35 [DoNotSerialize] 36 public List<ValueOutput> argumentPorts { get; } = new List<ValueOutput>(); 37 38 protected override void Definition() 39 { 40 base.Definition(); 41 42 name = ValueInput(nameof(name), string.Empty); 43 44 argumentPorts.Clear(); 45 46 for (var i = 0; i < argumentCount; i++) 47 { 48 argumentPorts.Add(ValueOutput<object>("argument_" + i)); 49 } 50 } 51 52 protected override bool ShouldTrigger(Flow flow, CustomEventArgs args) 53 { 54 return CompareNames(flow, name, args.name); 55 } 56 57 protected override void AssignArguments(Flow flow, CustomEventArgs args) 58 { 59 for (var i = 0; i < argumentCount; i++) 60 { 61 flow.SetValue(argumentPorts[i], args.arguments[i]); 62 } 63 } 64 65 public static void Trigger(GameObject target, string name, params object[] args) 66 { 67 EventBus.Trigger(EventHooks.Custom, target, new CustomEventArgs(name, args)); 68 } 69 } 70}