Пример #1
0
        protected ValueInput ValueInput(Type type, string key)
        {
            EnsureUniqueInput(key);
            var port = new ValueInput(key, type);

            valueInputs.Add(port);
            return(port);
        }
Пример #2
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        protected override void Definition()
        {
            name = ValueInput(nameof(name), string.Empty);

            if (kind == VariableKind.Object)
            {
                @object = ValueInput <GameObject>(nameof(@object), null).NullMeansSelf();
            }
        }
Пример #6
0
        public static object FetchValue(ValueInput input, GraphReference reference)
        {
            var flow = New(reference);

            var result = flow.GetValue(input);

            flow.Dispose();

            return(result);
        }
Пример #7
0
        protected override void Definition()
        {
            base.Definition();

            seconds      = ValueInput(nameof(seconds), 0f);
            unscaledTime = ValueInput(nameof(unscaledTime), false);

            Requirement(seconds, enter);
            Requirement(unscaledTime, enter);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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]);
            }
        }
Пример #10
0
 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);
     }
 }
Пример #11
0
        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);
        }
Пример #12
0
        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)));
                }
            }
        }
Пример #13
0
        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);
            }
        }
Пример #14
0
        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);
        }
Пример #15
0
        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();
                }
            }
        }
Пример #16
0
 public static object FetchValue(ValueInput input, Type type, GraphReference reference)
 {
     return(ConversionUtility.Convert(FetchValue(input, reference), type));
 }
Пример #17
0
        protected override void Definition()
        {
            base.Definition();

            target = ValueInput <GameObject>(nameof(target), null).NullMeansSelf();
        }
Пример #18
0
 protected override void Definition()
 {
     base.Definition();
     delayIn = ValueInput("delay", 0f);
 }
Пример #19
0
 /// <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);
 }
Пример #20
0
 public object GetValue(ValueInput input, Type type)
 {
     return(ConversionUtility.Convert(GetValue(input), type));
 }
Пример #21
0
 protected override void Definition()
 {
     base.Definition();
     conditionIn = ValueInput <bool>("condition");
     valueIn     = ValueInput("value", true);
 }
Пример #22
0
        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."));
            }
        }
Пример #23
0
        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);
        }
Пример #25
0
 protected override void Definition()
 {
     name = ValueInput(nameof(name), defaultName);
 }
Пример #26
0
 public T GetValue <T>(ValueInput input)
 {
     return((T)GetValue(input, typeof(T)));
 }
Пример #27
0
 public object GetConvertedValue(ValueInput input)
 {
     return(GetValue(input, input.type));
 }
Пример #28
0
        protected override void Definition()
        {
            base.Definition();

            name = ValueInput(nameof(name), string.Empty);
        }
Пример #29
0
 public static T FetchValue <T>(ValueInput input, GraphReference reference)
 {
     return((T)FetchValue(input, typeof(T), reference));
 }