123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System.Collections.Generic;
-
- namespace Unity.VisualScripting
- {
- [Analyser(typeof(IState))]
- public class StateAnalyser<TState> : Analyser<TState, StateAnalysis>
- where TState : class, IState
- {
- public StateAnalyser(GraphReference reference, TState target) : base(reference, target) { }
-
- public TState state => target;
-
- [Assigns]
- protected virtual bool IsEntered()
- {
- using (var recursion = Recursion.New(1))
- {
- return IsEntered(state, recursion);
- }
- }
-
- [Assigns]
- protected virtual IEnumerable<Warning> Warnings()
- {
- if (!IsEntered())
- {
- yield return Warning.Info("State is never entered.");
- }
- }
-
- private bool IsEntered(IState state, Recursion recursion)
- {
- if (state.isStart)
- {
- return true;
- }
-
- if (!recursion?.TryEnter(state) ?? false)
- {
- return false;
- }
-
- foreach (var incomingTransition in state.incomingTransitions)
- {
- if (IsEntered(incomingTransition.source, recursion) && incomingTransition.Analysis<StateTransitionAnalysis>(context).isTraversed)
- {
- recursion?.Exit(state);
- return true;
- }
- }
-
- recursion?.Exit(state);
-
- return false;
- }
- }
- }
|