first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76aa07459e97e401d8d9fb266cb41ff9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.ComponentModel;
|
||||
using UnityEngine;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
#if MODULE_ANIMATION_EXISTS
|
||||
/// <summary>
|
||||
/// Called when an animation event points to TriggerAnimationEvent.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Animation")]
|
||||
[UnitShortTitle("Animation Event")]
|
||||
[UnitTitle("Animation Event")]
|
||||
[TypeIcon(typeof(AnimationClip))]
|
||||
[DisplayName("Visual Scripting Animation Event")]
|
||||
public sealed class BoltAnimationEvent : MachineEventUnit<AnimationEvent>
|
||||
{
|
||||
protected override string hookName => EventHooks.AnimationEvent;
|
||||
|
||||
/// <summary>
|
||||
/// The string parameter passed to the event.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("String")]
|
||||
public ValueOutput stringParameter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The float parameter passed to the event.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Float")]
|
||||
public ValueOutput floatParameter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The integer parameter passed to the function.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Integer")]
|
||||
public ValueOutput intParameter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Unity object parameter passed to the function.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Object")]
|
||||
public ValueOutput objectReferenceParameter { get; private set; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
base.Definition();
|
||||
|
||||
stringParameter = ValueOutput<string>(nameof(stringParameter));
|
||||
floatParameter = ValueOutput<float>(nameof(floatParameter));
|
||||
intParameter = ValueOutput<int>(nameof(intParameter));
|
||||
objectReferenceParameter = ValueOutput<UnityObject>(nameof(objectReferenceParameter));
|
||||
}
|
||||
|
||||
protected override void AssignArguments(Flow flow, AnimationEvent args)
|
||||
{
|
||||
flow.SetValue(stringParameter, args.stringParameter);
|
||||
flow.SetValue(floatParameter, args.floatParameter);
|
||||
flow.SetValue(intParameter, args.intParameter);
|
||||
flow.SetValue(objectReferenceParameter, args.objectReferenceParameter);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7f8ec277ae294bb78e0034461acc14f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.ComponentModel;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
#if MODULE_ANIMATION_EXISTS
|
||||
/// <summary>
|
||||
/// Called when an animation event points to TriggerAnimationEvent.
|
||||
/// This version allows you to use the string parameter as the event name.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Animation")]
|
||||
[UnitShortTitle("Animation Event")]
|
||||
[UnitTitle("Named Animation Event")]
|
||||
[TypeIcon(typeof(AnimationClip))]
|
||||
[DisplayName("Visual Scripting Named Animation Event")]
|
||||
public sealed class BoltNamedAnimationEvent : MachineEventUnit<AnimationEvent>
|
||||
{
|
||||
protected override string hookName => EventHooks.AnimationEvent;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the event. The event will only trigger if this value
|
||||
/// is equal to the string parameter passed in the animation event.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ValueInput name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The float parameter passed to the event.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Float")]
|
||||
public ValueOutput floatParameter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The integer parameter passed to the function.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Integer")]
|
||||
public ValueOutput intParameter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Unity object parameter passed to the function.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Object")]
|
||||
public ValueOutput objectReferenceParameter { get; private set; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
base.Definition();
|
||||
|
||||
name = ValueInput(nameof(name), string.Empty);
|
||||
|
||||
floatParameter = ValueOutput<float>(nameof(floatParameter));
|
||||
intParameter = ValueOutput<int>(nameof(intParameter));
|
||||
objectReferenceParameter = ValueOutput<GameObject>(nameof(objectReferenceParameter));
|
||||
}
|
||||
|
||||
protected override bool ShouldTrigger(Flow flow, AnimationEvent animationEvent)
|
||||
{
|
||||
return CompareNames(flow, name, animationEvent.stringParameter);
|
||||
}
|
||||
|
||||
protected override void AssignArguments(Flow flow, AnimationEvent animationEvent)
|
||||
{
|
||||
flow.SetValue(floatParameter, animationEvent.floatParameter);
|
||||
flow.SetValue(intParameter, animationEvent.intParameter);
|
||||
flow.SetValue(objectReferenceParameter, animationEvent.objectReferenceParameter);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c614a03f84d54443f9265b20f2065128
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called by the Animator Component immediately before it updates its internal IK system.
|
||||
/// This callback can be used to set the positions of the IK goals and their respective weights.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Animation")]
|
||||
public sealed class OnAnimatorIK : GameObjectEventUnit<int>
|
||||
{
|
||||
public override Type MessageListenerType => typeof(AnimatorMessageListener);
|
||||
protected override string hookName => EventHooks.OnAnimatorIK;
|
||||
|
||||
/// <summary>
|
||||
/// The index of the layer on which the IK solver is called.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
public ValueOutput layerIndex { get; private set; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
base.Definition();
|
||||
|
||||
layerIndex = ValueOutput<int>(nameof(layerIndex));
|
||||
}
|
||||
|
||||
protected override void AssignArguments(Flow flow, int layerIndex)
|
||||
{
|
||||
flow.SetValue(this.layerIndex, layerIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cd0cea553003493886d72e9be8e23dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called at each frame after the state machines and the animations have been evaluated, but before On Animator IK.
|
||||
/// This callback can be used for processing animation movements for modifying root motion.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Animation")]
|
||||
public sealed class OnAnimatorMove : GameObjectEventUnit<EmptyEventArgs>
|
||||
{
|
||||
public override Type MessageListenerType => typeof(AnimatorMessageListener);
|
||||
protected override string hookName => EventHooks.OnAnimatorMove;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a614d65cdef1498eb33e5312e5b8672
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd8236ae45f864b36b81fcc375c82fd6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the application gains focus.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Application")]
|
||||
public sealed class OnApplicationFocus : GlobalEventUnit<EmptyEventArgs>
|
||||
{
|
||||
protected override string hookName => EventHooks.OnApplicationFocus;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0274e2d9504747689564e43b42b2525
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the application loses focus.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Application")]
|
||||
public sealed class OnApplicationLostFocus : GlobalEventUnit<EmptyEventArgs>
|
||||
{
|
||||
protected override string hookName => EventHooks.OnApplicationLostFocus;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c820b13261c044f2b847e5f8f454400
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the application pauses.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Application")]
|
||||
public sealed class OnApplicationPause : GlobalEventUnit<EmptyEventArgs>
|
||||
{
|
||||
protected override string hookName => EventHooks.OnApplicationPause;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 845c21f63a3264ef1b3405aa9ab7ca34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the application quits.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Application")]
|
||||
public sealed class OnApplicationQuit : GlobalEventUnit<EmptyEventArgs>
|
||||
{
|
||||
protected override string hookName => EventHooks.OnApplicationQuit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f959286f2d624a08b56b6d290871b33
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the application resumes.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Application")]
|
||||
public sealed class OnApplicationResume : GlobalEventUnit<EmptyEventArgs>
|
||||
{
|
||||
protected override string hookName => EventHooks.OnApplicationResume;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a13da87eb3ffd4da1abc9b68445b4905
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when a UnityEvent points to TriggerUnityEvent.
|
||||
/// </summary>
|
||||
[UnitCategory("Events")]
|
||||
[UnitTitle("UnityEvent")]
|
||||
[UnitOrder(2)]
|
||||
[DisplayName("Visual Scripting Unity Event")]
|
||||
public sealed class BoltUnityEvent : MachineEventUnit<string>
|
||||
{
|
||||
protected override string hookName => EventHooks.UnityEvent;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the event. The event will only trigger if this value
|
||||
/// is equal to the string parameter passed in the UnityEvent.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ValueInput name { get; private set; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
base.Definition();
|
||||
|
||||
name = ValueInput(nameof(name), string.Empty);
|
||||
}
|
||||
|
||||
protected override bool ShouldTrigger(Flow flow, string name)
|
||||
{
|
||||
return CompareNames(flow, this.name, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1f5cc0ec16bb47f8bca4d860c0c1339
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
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>
|
||||
[UnitCategory("Events")]
|
||||
[UnitOrder(0)]
|
||||
public sealed class CustomEvent : GameObjectEventUnit<CustomEventArgs>
|
||||
{
|
||||
public override Type MessageListenerType => null;
|
||||
protected override string hookName => EventHooks.Custom;
|
||||
|
||||
[SerializeAs(nameof(argumentCount))]
|
||||
private int _argumentCount;
|
||||
|
||||
[DoNotSerialize]
|
||||
[Inspectable, UnitHeaderInspectable("Arguments")]
|
||||
public int argumentCount
|
||||
{
|
||||
get => _argumentCount;
|
||||
set => _argumentCount = Mathf.Clamp(value, 0, 10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of the event.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ValueInput name { get; private set; }
|
||||
|
||||
[DoNotSerialize]
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea642e809385d4bd8951566868e7f534
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public struct CustomEventArgs
|
||||
{
|
||||
public readonly string name;
|
||||
|
||||
public readonly object[] arguments;
|
||||
|
||||
public CustomEventArgs(string name, params object[] arguments)
|
||||
{
|
||||
this.name = name;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c1ba3d93ef674e0791b3de1b1c1e556
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38164072c56204142abecaf906e1fad4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Use to draw gizmos that are always drawn in the editor.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Editor")]
|
||||
public sealed class OnDrawGizmos : ManualEventUnit<EmptyEventArgs>
|
||||
{
|
||||
protected override string hookName => EventHooks.OnDrawGizmos;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 055ce80827fbe4f2db3b492b9e29c156
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Use to draw gizmos that are drawn in the editor when the object is selected.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/Editor")]
|
||||
public sealed class OnDrawGizmosSelected : ManualEventUnit<EmptyEventArgs>
|
||||
{
|
||||
protected override string hookName => EventHooks.OnDrawGizmosSelected;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04fe7c6c4902d4254b658c04af933870
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
[SerializationVersion("A")]
|
||||
[SpecialUnit]
|
||||
public abstract class EventUnit<TArgs> : Unit, IEventUnit, IGraphElementWithData, IGraphEventHandler<TArgs>
|
||||
{
|
||||
public class Data : IGraphElementData
|
||||
{
|
||||
public EventHook hook;
|
||||
|
||||
public Delegate handler;
|
||||
|
||||
public bool isListening;
|
||||
|
||||
public HashSet<Flow> activeCoroutines = new HashSet<Flow>();
|
||||
}
|
||||
|
||||
public virtual IGraphElementData CreateData()
|
||||
{
|
||||
return new Data();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run this event in a coroutine, enabling asynchronous flow like wait nodes.
|
||||
/// </summary>
|
||||
[Serialize]
|
||||
[Inspectable]
|
||||
[InspectorExpandTooltip]
|
||||
public bool coroutine { get; set; } = false;
|
||||
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ControlOutput trigger { get; private set; }
|
||||
|
||||
[DoNotSerialize]
|
||||
protected abstract bool register { get; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
isControlRoot = true;
|
||||
|
||||
trigger = ControlOutput(nameof(trigger));
|
||||
}
|
||||
|
||||
public virtual EventHook GetHook(GraphReference reference)
|
||||
{
|
||||
throw new InvalidImplementationException($"Missing event hook for '{this}'.");
|
||||
}
|
||||
|
||||
public virtual void StartListening(GraphStack stack)
|
||||
{
|
||||
var data = stack.GetElementData<Data>(this);
|
||||
|
||||
if (data.isListening)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (register)
|
||||
{
|
||||
var reference = stack.ToReference();
|
||||
var hook = GetHook(reference);
|
||||
Action<TArgs> handler = args => Trigger(reference, args);
|
||||
EventBus.Register(hook, handler);
|
||||
|
||||
data.hook = hook;
|
||||
data.handler = handler;
|
||||
}
|
||||
|
||||
data.isListening = true;
|
||||
}
|
||||
|
||||
public virtual void StopListening(GraphStack stack)
|
||||
{
|
||||
var data = stack.GetElementData<Data>(this);
|
||||
|
||||
if (!data.isListening)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// The coroutine's flow will dispose at the next frame, letting us
|
||||
// keep the current flow for clean up operations if needed
|
||||
foreach (var activeCoroutine in data.activeCoroutines)
|
||||
{
|
||||
activeCoroutine.StopCoroutine(false);
|
||||
}
|
||||
|
||||
if (register)
|
||||
{
|
||||
EventBus.Unregister(data.hook, data.handler);
|
||||
|
||||
stack.ClearReference();
|
||||
|
||||
data.handler = null;
|
||||
}
|
||||
|
||||
data.isListening = false;
|
||||
}
|
||||
|
||||
public override void Uninstantiate(GraphReference instance)
|
||||
{
|
||||
// Here, we're relying on the fact that OnDestroy calls Uninstantiate.
|
||||
// We need to force-dispose any remaining coroutine to avoid
|
||||
// memory leaks, because OnDestroy on the runner will not keep
|
||||
// executing MoveNext() until our soft-destroy call at the end of Flow.Coroutine
|
||||
// or even dispose the coroutine's enumerator (!).
|
||||
var data = instance.GetElementData<Data>(this);
|
||||
var coroutines = data.activeCoroutines.ToHashSetPooled();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
new FrameDelayedCallback(() => StopAllCoroutines(coroutines), 1);
|
||||
#else
|
||||
StopAllCoroutines(coroutines);
|
||||
#endif
|
||||
|
||||
base.Uninstantiate(instance);
|
||||
}
|
||||
|
||||
static void StopAllCoroutines(HashSet<Flow> activeCoroutines)
|
||||
{
|
||||
// The coroutine's flow will dispose instantly, thus modifying
|
||||
// the activeCoroutines registry while we enumerate over it
|
||||
foreach (var activeCoroutine in activeCoroutines)
|
||||
{
|
||||
activeCoroutine.StopCoroutineImmediate();
|
||||
}
|
||||
activeCoroutines.Free();
|
||||
}
|
||||
|
||||
public bool IsListening(GraphPointer pointer)
|
||||
{
|
||||
if (!pointer.hasData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return pointer.GetElementData<Data>(this).isListening;
|
||||
}
|
||||
|
||||
public void Trigger(GraphReference reference, TArgs args)
|
||||
{
|
||||
InternalTrigger(reference, args);
|
||||
}
|
||||
|
||||
private protected virtual void InternalTrigger(GraphReference reference, TArgs args)
|
||||
{
|
||||
var flow = Flow.New(reference);
|
||||
|
||||
if (!ShouldTrigger(flow, args))
|
||||
{
|
||||
flow.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
AssignArguments(flow, args);
|
||||
|
||||
Run(flow);
|
||||
}
|
||||
|
||||
protected virtual bool ShouldTrigger(Flow flow, TArgs args)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void AssignArguments(Flow flow, TArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
private void Run(Flow flow)
|
||||
{
|
||||
if (flow.enableDebug)
|
||||
{
|
||||
var editorData = flow.stack.GetElementDebugData<IUnitDebugData>(this);
|
||||
|
||||
editorData.lastInvokeFrame = EditorTimeBinding.frame;
|
||||
editorData.lastInvokeTime = EditorTimeBinding.time;
|
||||
}
|
||||
|
||||
if (coroutine)
|
||||
{
|
||||
flow.StartCoroutine(trigger, flow.stack.GetElementData<Data>(this).activeCoroutines);
|
||||
}
|
||||
else
|
||||
{
|
||||
flow.Run(trigger);
|
||||
}
|
||||
}
|
||||
|
||||
protected static bool CompareNames(Flow flow, ValueInput namePort, string calledName)
|
||||
{
|
||||
Ensure.That(nameof(calledName)).IsNotNull(calledName);
|
||||
|
||||
return calledName.Trim().Equals(flow.GetValue<string>(namePort)?.Trim(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd7208df7e06b49e19424ccc0a6cc140
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 651dc128fc72346d9b1cfedd6996f3ac
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public abstract class GenericGuiEventUnit : GameObjectEventUnit<BaseEventData>
|
||||
{
|
||||
/// <summary>
|
||||
/// The event data.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ValueOutput data { get; private set; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
base.Definition();
|
||||
|
||||
data = ValueOutput<BaseEventData>(nameof(data));
|
||||
}
|
||||
|
||||
protected override void AssignArguments(Flow flow, BaseEventData data)
|
||||
{
|
||||
flow.SetValue(this.data, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de829102290134cd8bb7d6f030a0246c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called on the drag object when dragging is about to begin.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/GUI")]
|
||||
[TypeIcon(typeof(OnDrag))]
|
||||
[UnitOrder(16)]
|
||||
public sealed class OnBeginDrag : PointerEventUnit
|
||||
{
|
||||
public override Type MessageListenerType => typeof(UnityOnBeginDragMessageListener);
|
||||
protected override string hookName => EventHooks.OnBeginDrag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e09778b917d645b09bbd1aa93fb2ee0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when a user clicks the button and releases it.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/GUI")]
|
||||
[TypeIcon(typeof(Button))]
|
||||
[UnitOrder(1)]
|
||||
public sealed class OnButtonClick : GameObjectEventUnit<EmptyEventArgs>
|
||||
{
|
||||
protected override string hookName => EventHooks.OnButtonClick;
|
||||
public override Type MessageListenerType => typeof(UnityOnButtonClickMessageListener);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 219c0a220106e41bb9cbcaaa43f28129
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the cancel button is pressed.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/GUI")]
|
||||
[UnitOrder(25)]
|
||||
public sealed class OnCancel : GenericGuiEventUnit
|
||||
{
|
||||
public override Type MessageListenerType => typeof(UnityOnCancelMessageListener);
|
||||
protected override string hookName => EventHooks.OnCancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66c7e0517c5f640cc9b62e077ca8dcbc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the pointer deselects the GUI element.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/GUI")]
|
||||
[UnitOrder(23)]
|
||||
public sealed class OnDeselect : GenericGuiEventUnit
|
||||
{
|
||||
public override Type MessageListenerType => typeof(UnityOnDeselectMessageListener);
|
||||
protected override string hookName => EventHooks.OnDeselect;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e80cd73486524a5fa8f4ebc514915c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// When draging is occuring this will be called every time the cursor is moved.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/GUI")]
|
||||
[UnitOrder(17)]
|
||||
public sealed class OnDrag : PointerEventUnit
|
||||
{
|
||||
protected override string hookName => EventHooks.OnDrag;
|
||||
public override Type MessageListenerType => typeof(UnityOnDragMessageListener);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37c4fa51049d34219bcc2cc1ec7bea50
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called on a target that can accept a drop.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/GUI")]
|
||||
[TypeIcon(typeof(OnDrag))]
|
||||
[UnitOrder(19)]
|
||||
public sealed class OnDrop : PointerEventUnit
|
||||
{
|
||||
public override Type MessageListenerType => typeof(UnityOnDropMessageListener);
|
||||
protected override string hookName => EventHooks.OnDrop;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cb32bdd74a974edca6f484948550496
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the current value of the dropdown has changed.
|
||||
/// </summary>
|
||||
[UnitCategory("Events/GUI")]
|
||||
[TypeIcon(typeof(Dropdown))]
|
||||
[UnitOrder(4)]
|
||||
public sealed class OnDropdownValueChanged : GameObjectEventUnit<int>
|
||||
{
|
||||
public override Type MessageListenerType => typeof(UnityOnDropdownValueChangedMessageListener);
|
||||
protected override string hookName => EventHooks.OnDropdownValueChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The index of the newly selected option.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
public ValueOutput index { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The text of the newly selected option.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
public ValueOutput text { get; private set; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
base.Definition();
|
||||
|
||||
index = ValueOutput<int>(nameof(index));
|
||||
text = ValueOutput<string>(nameof(text));
|
||||
}
|
||||
|
||||
protected override void AssignArguments(Flow flow, int index)
|
||||
{
|
||||
flow.SetValue(this.index, index);
|
||||
flow.SetValue(text, flow.GetValue<Dropdown>(target).options[index].text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78f803e994d6c4bbe8124c6fe6af6832
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user