示例#1
0
        public HierarchicalStateMachine(IEqualityComparer <TState> stateComparer, IEqualityComparer <TTrigger> triggerComparer)
        {
            if (stateComparer == null)
            {
                throw new ArgumentNullException(nameof(stateComparer));
            }
            if (triggerComparer == null)
            {
                throw new ArgumentNullException(nameof(triggerComparer));
            }

            _stateComparer   = new Comparer <TState>();
            _triggerComparer = new Comparer <TTrigger>();

            SetStateComparer(stateComparer);
            SetTriggerComparer(triggerComparer);

            _stateHierarchy = new StateHierarchy <TState>(_stateComparer);
            _stateHierarchyBehaviourScheduler = new StateHierarchyBehaviourScheduler <TState>(_stateHierarchy, _stateComparer);
            _transitionValidator         = new TransitionValidator <TState, TTrigger>(_stateComparer, _triggerComparer, _stateHierarchyBehaviourScheduler);
            _transitionHandler           = new TransitionHandler <TState, TTrigger>(_stateComparer, _triggerComparer, _stateHierarchyBehaviourScheduler, _transitionValidator);
            _hierarchicalEventDispatcher = new HierarchicalEventDispatcher <TState>(_stateComparer, _stateHierarchyBehaviourScheduler);

            SubscribeToEventsForInternalStateChanging();
            SubscribeToHierarchyPathChangeEvents();
            SubscribeToEventsForSavingValidTransition();
        }
示例#2
0
        public HierarchicalStateMachine(IEqualityComparer <TState> stateComparer, IEqualityComparer <TTrigger> triggerComparer)
        {
            if (stateComparer == null)
            {
                throw new ArgumentNullException(nameof(stateComparer));
            }
            if (triggerComparer == null)
            {
                throw new ArgumentNullException(nameof(triggerComparer));
            }

            _stateComparer   = new StateEqualityComparer(stateComparer);
            _triggerComparer = new TriggerEqualityComparer(triggerComparer);

            _transitionComparer = new TransitionEqualityComparer <TState, TTrigger>(_stateComparer, _triggerComparer);

            _stateHierarchy = new StateHierarchy <TState, TTrigger>(this, _stateComparer);
            _stateHierarchyBehaviourScheduler = new StateHierarchyBehaviourScheduler <TState, TTrigger>(this, _stateHierarchy, _transitions, _transitionValidator, _stateComparer, _triggerComparer);
            _transitionValidator = new HierarchicalTransitionValidator <TState, TTrigger>(_stateComparer, _transitionComparer, _stateHierarchyBehaviourScheduler, _stateHierarchy);
            _transitions         = new HierarchicalTransitionCollection <TState, TTrigger>(this, _stateComparer, _transitionComparer);
            _eventHandlers       = new HierarchicalStateEventHandlerCollection <TState, TTrigger>(this, _stateComparer);
            _eventDispatcher     = new HierarchicalEventDispatcher <TState, TTrigger>(_stateComparer, _eventHandlers, _stateHierarchyBehaviourScheduler);
        }