private IEnumerator Coroutine(ControlOutput startPort) { try { foreach (var instruction in InvokeCoroutine(startPort)) { if (coroutineStopRequested) { yield break; } yield return(instruction); if (coroutineStopRequested) { yield break; } } } finally { // Manual disposal might have already occurred from StopCoroutine, // so we have to avoid double disposal, which would throw. if (!disposed) { Dispose(); } } }
public void Invoke(ControlOutput output) { Ensure.That(nameof(output)).IsNotNull(output); var connection = output.connection; if (connection == null) { return; } var input = connection.destination; var recursionNode = new RecursionNode(output, stack); BeforeInvoke(output, recursionNode); try { var nextPort = InvokeDelegate(input); if (nextPort != null) { Invoke(nextPort); } } finally { AfterInvoke(output, recursionNode); } }
private RecursionNode BeforeInvoke(ControlOutput output, RecursionNode recursionNode) { try { recursion?.Enter(recursionNode); } catch (StackOverflowException ex) { output.unit.HandleException(stack, ex); throw; } var connection = output.connection; var input = connection.destination; if (enableDebug) { var connectionEditorData = stack.GetElementDebugData <IUnitConnectionDebugData>(connection); var inputUnitEditorData = stack.GetElementDebugData <IUnitDebugData>(input.unit); connectionEditorData.lastInvokeFrame = EditorTimeBinding.frame; connectionEditorData.lastInvokeTime = EditorTimeBinding.time; inputUnitEditorData.lastInvokeFrame = EditorTimeBinding.frame; inputUnitEditorData.lastInvokeTime = EditorTimeBinding.time; } return(recursionNode); }
protected override void Definition() { enter = ControlInput(nameof(enter), Enter); selector = ValueInput <T>(nameof(selector)); Requirement(selector, enter); branches = new List <KeyValuePair <T, ControlOutput> >(); foreach (var option in options) { var key = "%" + option; if (!controlOutputs.Contains(key)) { var branch = ControlOutput(key); branches.Add(new KeyValuePair <T, ControlOutput>(option, branch)); Succession(enter, branch); } } @default = ControlOutput(nameof(@default)); Succession(enter, @default); }
protected ControlOutput ControlOutput(string key) { EnsureUniqueOutput(key); var port = new ControlOutput(key); controlOutputs.Add(port); return(port); }
protected override void Definition() { enter = ControlInputCoroutine(nameof(enter), Loop, LoopCoroutine); exit = ControlOutput(nameof(exit)); body = ControlOutput(nameof(body)); Succession(enter, body); Succession(enter, exit); }
protected void Connect(ControlOutput source, ControlInput destination) { Undo.IncrementCurrentGroup(); LudiqEditorUtility.editedObject.BeginOverride(m_Reference.serializedObject); var widget = new ControlOutputWidget(m_Canvas, source); var connectMethodInfo = GetConnectionMethodInfo(widget.GetType()); connectMethodInfo?.Invoke(widget, new object[] { widget.port, destination }); LudiqEditorUtility.editedObject.EndOverride(); }
protected override void Definition() { enter = ControlInput(nameof(enter), Clear); dictionaryInput = ValueInput <IDictionary>(nameof(dictionaryInput)); dictionaryOutput = ValueOutput <IDictionary>(nameof(dictionaryOutput)); exit = ControlOutput(nameof(exit)); Requirement(dictionaryInput, enter); Assignment(enter, dictionaryOutput); Succession(enter, exit); }
protected override void Definition() { enter = ControlInput(nameof(enter), Enter); input = ValueInput <object>(nameof(input)).AllowsNull(); ifNotNull = ControlOutput(nameof(ifNotNull)); ifNull = ControlOutput(nameof(ifNull)); Requirement(input, enter); Succession(enter, ifNotNull); Succession(enter, ifNull); }
protected override void Definition() { enter = ControlInput(nameof(enter), Clear); listInput = ValueInput <IList>(nameof(listInput)); listOutput = ValueOutput <IList>(nameof(listOutput)); exit = ControlOutput(nameof(exit)); Requirement(listInput, enter); Assignment(enter, listOutput); Succession(enter, exit); }
protected override void Definition() { enter = ControlInput(nameof(enter), Set); list = ValueInput <IList>(nameof(list)); index = ValueInput(nameof(index), 0); item = ValueInput <object>(nameof(item)); exit = ControlOutput(nameof(exit)); Requirement(list, enter); Requirement(index, enter); Requirement(item, enter); Succession(enter, exit); }
protected override void Definition() { enter = ControlInput(nameof(enter), Set); dictionary = ValueInput <IDictionary>(nameof(dictionary)); key = ValueInput <object>(nameof(key)); value = ValueInput <object>(nameof(value)); exit = ControlOutput(nameof(exit)); Requirement(dictionary, enter); Requirement(key, enter); Requirement(value, enter); Succession(enter, exit); }
private IEnumerable InvokeCoroutine(ControlOutput output) { var connection = output.connection; if (connection == null) { yield break; } var input = connection.destination; var recursionNode = new RecursionNode(output, stack); BeforeInvoke(output, recursionNode); if (input.supportsCoroutine) { foreach (var instruction in InvokeCoroutineDelegate(input)) { if (instruction is ControlOutput) { foreach (var unwrappedInstruction in InvokeCoroutine((ControlOutput)instruction)) { yield return(unwrappedInstruction); } } else { yield return(instruction); } } } else { ControlOutput nextPort = InvokeDelegate(input); if (nextPort != null) { foreach (var instruction in InvokeCoroutine(nextPort)) { yield return(instruction); } } } AfterInvoke(output, recursionNode); }
public void StartCoroutine(ControlOutput port, ICollection <Flow> registry = null) { isCoroutine = true; coroutineRunner = stack.component; if (coroutineRunner == null) { coroutineRunner = CoroutineRunner.instance; } activeCoroutinesRegistry = registry; activeCoroutinesRegistry?.Add(this); // We have to store the enumerator because Coroutine itself // can't be cast to IDisposable, which we'll need when stopping. coroutineEnumerator = Coroutine(port); coroutineRunner.StartCoroutine(coroutineEnumerator); }
public void Run(ControlOutput port) { Invoke(port); Dispose(); }
protected override void Definition() { base.Definition(); inputParameters = new Dictionary <int, ValueInput>(); outputParameters = new Dictionary <int, ValueOutput>(); useExpandedParameters = true; enter = ControlInput(nameof(enter), Enter); exit = ControlOutput(nameof(exit)); Succession(enter, exit); if (member.requiresTarget) { Requirement(target, enter); } if (supportsChaining && chainable) { targetOutput = ValueOutput(member.targetType, nameof(targetOutput)); Assignment(enter, targetOutput); } if (member.isGettable) { result = ValueOutput(member.type, nameof(result), Result); if (member.requiresTarget) { Requirement(target, result); } } var parameterInfos = member.GetParameterInfos().ToArray(); parameterCount = parameterInfos.Length; for (int parameterIndex = 0; parameterIndex < parameterCount; parameterIndex++) { var parameterInfo = parameterInfos[parameterIndex]; var parameterType = parameterInfo.UnderlyingParameterType(); if (!parameterInfo.HasOutModifier()) { var inputParameterKey = "%" + parameterInfo.Name; var inputParameter = ValueInput(parameterType, inputParameterKey); inputParameters.Add(parameterIndex, inputParameter); inputParameter.SetDefaultValue(parameterInfo.PseudoDefaultValue()); if (parameterInfo.AllowsNull()) { inputParameter.AllowsNull(); } Requirement(inputParameter, enter); if (member.isGettable) { Requirement(inputParameter, result); } } if (parameterInfo.ParameterType.IsByRef || parameterInfo.IsOut) { var outputParameterKey = "&" + parameterInfo.Name; var outputParameter = ValueOutput(parameterType, outputParameterKey); outputParameters.Add(parameterIndex, outputParameter); Assignment(enter, outputParameter); useExpandedParameters = false; } } if (inputParameters.Count > 5) { useExpandedParameters = false; } }
private void AfterInvoke(ControlOutput output, RecursionNode recursionNode) { recursion?.Exit(recursionNode); }
protected override void Definition() { enter = ControlInputCoroutine(nameof(enter), Await); exit = ControlOutput(nameof(exit)); Succession(enter, exit); }
/// <summary> /// Triggering the source may trigger the destination. /// </summary> protected void Succession(ControlInput source, ControlOutput destination) { Relation(source, destination); }