You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
namespace Unity.VisualScripting
{
[Analyser(typeof(FlowStateTransition))]
public class FlowStateTransitionAnalyser : NesterStateTransitionAnalyser<FlowStateTransition>
{
public FlowStateTransitionAnalyser(GraphReference reference, FlowStateTransition transition) : base(reference, transition) { }
protected override bool IsTraversed()
{
var graph = transition.nest.graph;
if (graph == null)
{
return false;
}
using (var recursion = Recursion.New(1))
{
foreach (var trigger in graph.GetUnitsRecursive(recursion).OfType<TriggerStateTransition>())
{
if (trigger.Analysis<UnitAnalysis>(context).isEntered)
{
return true;
}
}
}
return false;
}
protected override IEnumerable<Warning> Warnings()
{
foreach (var baseWarning in base.Warnings())
{
yield return baseWarning;
}
var graph = transition.nest.graph;
if (graph == null)
{
yield break;
}
using (var recursion = Recursion.New(1))
{
if (!graph.GetUnitsRecursive(recursion).OfType<IEventUnit>().Any())
{
yield return Warning.Caution("Transition graph is missing an event.");
}
}
using (var recursion = Recursion.New(1))
{
if (!graph.GetUnitsRecursive(recursion).OfType<TriggerStateTransition>().Any())
{
yield return Warning.Caution("Transition graph is missing a trigger unit.");
}
}
}
}
}