Ejemplo n.º 1
0
        private static UnitDescription FetchReflectedDescription(Type unitType)
        {
            var oldName = BoltFlowNameUtility.UnitPreviousTitle(unitType);
            var prefix  = string.IsNullOrEmpty(oldName) ? string.Empty : $"(Previously named {oldName}) ";

            return(new UnitDescription()
            {
                title = BoltFlowNameUtility.UnitTitle(unitType, false, true),
                shortTitle = BoltFlowNameUtility.UnitTitle(unitType, true, true),
                surtitle = unitType.GetAttribute <UnitSurtitleAttribute>()?.surtitle,
                subtitle = unitType.GetAttribute <UnitSubtitleAttribute>()?.subtitle,
                summary = prefix + unitType.Summary()
            });
        }
Ejemplo n.º 2
0
 public EventLine(Type eventType)
 {
     content = new GUIContent(BoltFlowNameUtility.UnitTitle(eventType, false, true), eventType.Icon()?[IconSize.Small]);
 }
Ejemplo n.º 3
0
        protected virtual IEnumerable <Warning> Warnings()
        {
            var isEntered = IsEntered();

            if (!unit.isDefined)
            {
                if (unit.definitionException != null)
                {
                    yield return(Warning.Exception(unit.definitionException));
                }
                else if (!unit.canDefine)
                {
                    yield return(Warning.Caution("Unit is not properly configured."));
                }
            }

            if (!isEntered)
            {
                yield return(Warning.Info("Unit is never entered."));
            }

            // Obsolete attribute is not inherited, so traverse the chain manually
            var obsoleteAttribute = unit.GetType().AndHierarchy().FirstOrDefault(t => t.HasAttribute <ObsoleteAttribute>())?.GetAttribute <ObsoleteAttribute>();

            if (obsoleteAttribute != null)
            {
                var unitName = BoltFlowNameUtility.UnitTitle(unit.GetType(), true, false);

                if (obsoleteAttribute.Message != null)
                {
                    Debug.LogWarning($"\"{unitName}\" unit is deprecated: {obsoleteAttribute.Message}");
                    yield return(Warning.Caution($"Deprecated: {obsoleteAttribute.Message}"));
                }
                else
                {
                    Debug.LogWarning($"\"{unitName}\" unit is deprecated.");
                    yield return(Warning.Caution("This unit is deprecated."));
                }
            }

            if (unit.isDefined)
            {
                foreach (var invalidInput in unit.invalidInputs)
                {
                    yield return(Warning.Caution($"{PortLabel(invalidInput)} is not used by this unit."));
                }

                foreach (var invalidOutput in unit.invalidOutputs)
                {
                    yield return(Warning.Caution($"{PortLabel(invalidOutput)} is not provided by this unit."));
                }

                foreach (var validPort in unit.validPorts)
                {
                    if (validPort.hasInvalidConnection)
                    {
                        yield return(Warning.Caution($"{PortLabel(validPort)} has an invalid connection."));
                    }
                }
            }

            foreach (var controlInput in unit.controlInputs)
            {
                if (!controlInput.hasValidConnection)
                {
                    continue;
                }

                foreach (var relation in controlInput.relations)
                {
                    if (relation.source is ValueInput)
                    {
                        var valueInput = (ValueInput)relation.source;

                        foreach (var warning in ValueInputWarnings(valueInput))
                        {
                            yield return(warning);
                        }
                    }
                }
            }

            foreach (var controlOutput in unit.controlOutputs)
            {
                if (!controlOutput.hasValidConnection)
                {
                    continue;
                }

                var controlInputs = controlOutput.relations.Select(r => r.source).OfType <ControlInput>();

                var isTriggered = !controlInputs.Any() || controlInputs.Any(ci => !ci.isPredictable || ci.couldBeEntered);

                foreach (var relation in controlOutput.relations)
                {
                    if (relation.source is ValueInput)
                    {
                        var valueInput = (ValueInput)relation.source;

                        foreach (var warning in ValueInputWarnings(valueInput))
                        {
                            yield return(warning);
                        }
                    }
                }

                if (isEntered && !isTriggered)
                {
                    yield return(Warning.Caution($"{PortLabel(controlOutput)} is connected, but it is never triggered."));
                }
            }

            foreach (var valueOutput in unit.valueOutputs)
            {
                if (!valueOutput.hasValidConnection)
                {
                    continue;
                }

                foreach (var relation in valueOutput.relations)
                {
                    if (relation.source is ControlInput)
                    {
                        var controlInput = (ControlInput)relation.source;

                        if (isEntered && controlInput.isPredictable && !controlInput.couldBeEntered)
                        {
                            yield return(Warning.Severe($"{PortLabel(controlInput)} is required, but it is never entered."));
                        }
                    }
                    else if (relation.source is ValueInput)
                    {
                        var valueInput = (ValueInput)relation.source;

                        foreach (var warning in ValueInputWarnings(valueInput))
                        {
                            yield return(warning);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 protected virtual string Label(bool human)
 {
     return(BoltFlowNameUtility.UnitTitle(unitType, false, true));
 }