protected ValueInput ValueInput(Type type, string key) { EnsureUniqueInput(key); var port = new ValueInput(key, type); valueInputs.Add(port); return(port); }
protected override void Definition() { base.Definition(); condition = ValueInput <bool>(nameof(condition)); Requirement(condition, enter); }
protected override void Definition() { source = ValueInput <GameObject>(nameof(source), null).NullMeansSelf(); base.Definition(); Requirement(source, assign); }
private object GetDefaultValue(ValueInput input) { if (!TryGetDefaultValue(input, out var defaultValue)) { throw new InvalidOperationException("Value input port does not have a default value."); } return(defaultValue); }
protected override void Definition() { name = ValueInput(nameof(name), string.Empty); if (kind == VariableKind.Object) { @object = ValueInput <GameObject>(nameof(@object), null).NullMeansSelf(); } }
public static object FetchValue(ValueInput input, GraphReference reference) { var flow = New(reference); var result = flow.GetValue(input); flow.Dispose(); return(result); }
protected override void Definition() { base.Definition(); seconds = ValueInput(nameof(seconds), 0f); unscaledTime = ValueInput(nameof(unscaledTime), false); Requirement(seconds, enter); Requirement(unscaledTime, enter); }
public bool TryGetDefaultValue(ValueInput input, out object defaultValue) { if (!input.unit.defaultValues.TryGetValue(input.key, out defaultValue)) { return(false); } if (input.nullMeansSelf && defaultValue == null) { defaultValue = stack.self; } return(true); }
protected override void Definition() { base.Definition(); ArgumentCount(argumentCount + 1); name = ValueInput(nameof(name), string.Empty); for (var i = 0; i < argumentCount; i++) { var _i = i; // Cache outside closure ValueOutput("argument_" + i, (recursion) => arguments[1 + _i]); } }
protected override void Definition() { if (custom) { enter = ControlInput(nameof(enter), ThrowCustom); exception = ValueInput <Exception>(nameof(exception)); Requirement(exception, enter); } else { enter = ControlInput(nameof(enter), ThrowMessage); message = ValueInput(nameof(message), string.Empty); Requirement(message, enter); } }
private bool CanPredict(ValueInput input) { if (!input.hasValidConnection) { if (!TryGetDefaultValue(input, out var defaultValue)) { return(false); } if (typeof(Component).IsAssignableFrom(input.type)) { defaultValue = defaultValue?.ConvertTo(input.type); } if (!input.allowsNull && defaultValue == null) { return(false); } return(true); } var output = input.validConnectedPorts.Single(); if (!CanPredict(output)) { return(false); } var connectedValue = GetValue(output); if (!ConversionUtility.CanConvert(connectedValue, input.type, false)) { return(false); } if (typeof(Component).IsAssignableFrom(input.type)) { connectedValue = connectedValue?.ConvertTo(input.type); } if (!input.allowsNull && connectedValue == null) { return(false); } return(true); }
protected override void OnFieldsGUI(Rect position) { base.OnFieldsGUI(position); if (typeMetadata.value != null && ValueInput.SupportsDefaultValue((Type)typeMetadata.value)) { y += EditorGUIUtility.standardVerticalSpacing; OnHasDefaultValueGUI(position.VerticalSection(ref y, GetHasDefaultValueHeight(position.width))); if ((bool)hasDefaultValueMetadata.value) { y += EditorGUIUtility.standardVerticalSpacing; OnDefaultValueGUI(position.VerticalSection(ref y, GetDefaultValueHeight(position.width))); } } }
public object GetValue(ValueInput input) { if (locals.TryGetValue(input, out var local)) { return(local); } var connection = input.connection; if (connection != null) { if (enableDebug) { var connectionEditorData = stack.GetElementDebugData <IUnitConnectionDebugData>(connection); connectionEditorData.lastInvokeFrame = EditorTimeBinding.frame; connectionEditorData.lastInvokeTime = EditorTimeBinding.time; } var output = connection.source; var value = GetValue(output); if (enableDebug) { var connectionEditorData = stack.GetElementDebugData <ValueConnection.DebugData>(connection); connectionEditorData.lastValue = value; connectionEditorData.assignedLastValue = true; } return(value); } else if (TryGetDefaultValue(input, out var defaultValue)) { return(defaultValue); } else { throw new MissingValuePortInputException(input.key); } }
protected override float GetHeight(float width, GUIContent label) { var height = base.GetHeight(width, label); if (typeMetadata.value != null && ValueInput.SupportsDefaultValue((Type)typeMetadata.value)) { height += EditorGUIUtility.standardVerticalSpacing; height += GetHasDefaultValueHeight(width); if ((bool)hasDefaultValueMetadata.value) { height += EditorGUIUtility.standardVerticalSpacing; height += GetDefaultValueHeight(width); } } return(height); }
protected override void Definition() { member.EnsureReflected(); if (!IsMemberValid(member)) { throw new NotSupportedException("The member type is not valid for this unit."); } if (member.requiresTarget) { target = ValueInput(member.targetType, nameof(target)); target.SetDefaultValue(member.targetType.PseudoDefault()); if (typeof(UnityObject).IsAssignableFrom(member.targetType)) { target.NullMeansSelf(); } } }
public static object FetchValue(ValueInput input, Type type, GraphReference reference) { return(ConversionUtility.Convert(FetchValue(input, reference), type)); }
protected override void Definition() { base.Definition(); target = ValueInput <GameObject>(nameof(target), null).NullMeansSelf(); }
protected override void Definition() { base.Definition(); delayIn = ValueInput("delay", 0f); }
/// <summary> /// Getting the value of the destination may fetch the value of the source. /// </summary> protected void Requirement(ValueInput source, ValueOutput destination) { Relation(source, destination); }
public object GetValue(ValueInput input, Type type) { return(ConversionUtility.Convert(GetValue(input), type)); }
protected override void Definition() { base.Definition(); conditionIn = ValueInput <bool>("condition"); valueIn = ValueInput("value", true); }
private IEnumerable <Warning> ValueInputWarnings(ValueInput valueInput) { // We can disable null reference check if no self is available // and the port requires an owner, for example in macros. var trustFutureOwner = valueInput.nullMeansSelf && reference.self == null; var checkForNullReference = BoltFlow.Configuration.predictPotentialNullReferences && !valueInput.allowsNull && !trustFutureOwner; var checkForMissingComponent = BoltFlow.Configuration.predictPotentialMissingComponents && typeof(Component).IsAssignableFrom(valueInput.type); // Note that we cannot directly check the input's predicted value, because it // will return false for safeguard specifically because it might be missing requirements. // Therefore, we first check the connected value, then the default value. // If the port is connected to a predictable output, use the connected value to perform checks. if (valueInput.hasValidConnection) { var valueOutput = valueInput.validConnectedPorts.Single(); if (Flow.CanPredict(valueOutput, reference)) { if (checkForNullReference) { if (Flow.Predict(valueOutput, reference) == null) { yield return(Warning.Severe($"{PortLabel(valueInput)} cannot be null.")); } } if (checkForMissingComponent) { var connectedPredictedValue = Flow.Predict(valueOutput, reference); // This check is necessary, because the predicted value could be // incompatible as connections with non-guaranteed conversions are allowed. if (ConversionUtility.CanConvert(connectedPredictedValue, typeof(GameObject), true)) { var gameObject = ConversionUtility.Convert <GameObject>(connectedPredictedValue); if (gameObject != null) { var component = (Component)ConversionUtility.Convert(gameObject, valueInput.type); if (component == null) { yield return(Warning.Caution($"{PortLabel(valueInput)} is missing a {valueInput.type.DisplayName()} component.")); } } } } } } // If the port isn't connected but has a default value, use the default value to perform checks. else if (valueInput.hasDefaultValue) { if (checkForNullReference) { if (Flow.Predict(valueInput, reference) == null) { yield return(Warning.Severe($"{PortLabel(valueInput)} cannot be null.")); } } if (checkForMissingComponent) { var unconnectedPredictedValue = Flow.Predict(valueInput, reference); if (ConversionUtility.CanConvert(unconnectedPredictedValue, typeof(GameObject), true)) { var gameObject = ConversionUtility.Convert <GameObject>(unconnectedPredictedValue); if (gameObject != null) { var component = (Component)ConversionUtility.Convert(gameObject, valueInput.type); if (component == null) { yield return(Warning.Caution($"{PortLabel(valueInput)} is missing a {valueInput.type.DisplayName()} component.")); } } } } } // The value isn't connected and has no default value, // therefore it is certain to be missing at runtime. else { yield return(Warning.Severe($"{PortLabel(valueInput)} is missing.")); } }
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)); }
protected override void Definition() { base.Definition(); targetPort = ValueInput <FlowMachine>(nameof(target), flowmachine); }
protected override void Definition() { name = ValueInput(nameof(name), defaultName); }
public T GetValue <T>(ValueInput input) { return((T)GetValue(input, typeof(T))); }
public object GetConvertedValue(ValueInput input) { return(GetValue(input, input.type)); }
protected override void Definition() { base.Definition(); name = ValueInput(nameof(name), string.Empty); }
public static T FetchValue <T>(ValueInput input, GraphReference reference) { return((T)FetchValue(input, typeof(T), reference)); }