コード例 #1
0
 public void AddState(StateMachineState state)
 {
     if (parent != null)
     {
         parent.AddState(state, this);
     }
 }
コード例 #2
0
    protected override void OnDestroy()
    {
        foreach (var param in m_parameters)
        {
            param.Clear();
        }

        states.Clear(true);
        preStateTransitions.Clear(true);
        anyStateTransitions.Clear(true);
        subStateMachines.Clear();
        hitEffects.Clear();
        deadEffects.Clear();

        m_coolGroups.Clear();
        m_passiveHash.Clear();

        m_laydown = null;

        creature      = null;
        passiveSource = null;
        passiveMask   = 0;

        info         = null;
        onStateEnded = null;
        onEnterState = null;
        onQuitState  = null;
        onRebuild    = null;
    }
コード例 #3
0
ファイル: GUIOnState.cs プロジェクト: horsman/shieldlord
 void Start()
 {
     state = GetComponent<StateMachineState>();
     panel = GetComponent<UIPanel>();
     state.Enter += Enter;
     state.Exit += Exit;
 }
コード例 #4
0
        /// <summary>
        /// Declares a sub-state on the machine. A sub-state is a state that is valid within a super-state,
        /// allowing a state machine to have multiple "states" -- nested parts of an overall state.
        /// </summary>
        /// <param name="propertyExpression">The state property expression</param>
        /// <param name="superState">The superstate of which this state is a substate</param>
        protected virtual void SubState(Expression <Func <State> > propertyExpression, State superState)
        {
            if (superState == null)
            {
                throw new ArgumentNullException(nameof(superState));
            }

            State <TInstance> superStateInstance = GetState(superState.Name);

            PropertyInfo property = propertyExpression.GetPropertyInfo();

            string name = property.Name;

            var propertyValue = property.GetValue(this);

            // If the state was already defined, don't define it again
            var existingState = propertyValue as StateMachineState <TInstance>;

            if (name.Equals(existingState?.Name) && superState.Name.Equals(existingState?.SuperState?.Name))
            {
                return;
            }

            var state = new StateMachineState <TInstance>(this, name, _eventObservers, superStateInstance);

            property.SetValue(this, state);

            SetState(name, state);
        }
コード例 #5
0
    public bool ChangeState(StateMachineState to)
    {
        bool changedState;

        if (CanChangeState(to))
        {
            var from = State;
            if (from)
            {
                from.OnExit();
            }
            State = to;
            if (to)
            {
                to.OnEnter();
            }
            changedState = true;
        }
        else
        {
            changedState = false;
        }

        return(changedState);
    }
コード例 #6
0
        /// <summary>
        /// Declares a state on the state machine, and initialized the property
        /// </summary>
        /// <param name="propertyExpression">The property containing the state</param>
        /// <param name="statePropertyExpression">The state property</param>
        protected virtual void State <TProperty>(Expression <Func <TProperty> > propertyExpression,
                                                 Expression <Func <TProperty, State> > statePropertyExpression)
            where TProperty : class
        {
            PropertyInfo property      = propertyExpression.GetPropertyInfo();
            var          propertyValue = property.GetValue(this, null) as TProperty;

            if (propertyValue == null)
            {
                throw new ArgumentException("The property is not initialized: " + property.Name, nameof(propertyExpression));
            }

            PropertyInfo stateProperty = statePropertyExpression.GetPropertyInfo();

            string name = $"{property.Name}.{stateProperty.Name}";

            var existingState = GetStateProperty(stateProperty, propertyValue);

            if (name.Equals(existingState?.Name))
            {
                return;
            }

            var state = new StateMachineState <TInstance>(this, name, _eventObservers);

            SetStateProperty(stateProperty, propertyValue, state);

            SetState(name, state);
        }
コード例 #7
0
        /// <summary>
        /// Declares a state on the state machine, and initialized the property
        /// </summary>
        /// <param name="propertyExpression">The property containing the state</param>
        /// <param name="statePropertyExpression">The state property</param>
        /// <param name="superState">The superstate of which this state is a substate</param>
        protected virtual void SubState <TProperty>(Expression <Func <TProperty> > propertyExpression,
                                                    Expression <Func <TProperty, State> > statePropertyExpression, State superState)
            where TProperty : class
        {
            if (superState == null)
            {
                throw new ArgumentNullException(nameof(superState));
            }

            State <TInstance> superStateInstance = GetState(superState.Name);

            PropertyInfo property      = propertyExpression.GetPropertyInfo();
            var          propertyValue = property.GetValue(this, null) as TProperty;

            if (propertyValue == null)
            {
                throw new ArgumentException("The property is not initialized: " + property.Name, nameof(propertyExpression));
            }

            PropertyInfo stateProperty = statePropertyExpression.GetPropertyInfo();

            string name = $"{property.Name}.{stateProperty.Name}";

            var state = new StateMachineState <TInstance>(this, name, _eventObservers, superStateInstance);

            SetStateProperty(stateProperty, propertyValue, state);

            SetState(name, state);
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StateMachineTransitionContext{TState, TTransition, TPayload}"/> class.
 /// </summary>
 /// <param name="startState">The start state.</param>
 /// <param name="endState">The end state.</param>
 /// <param name="transition">The transition.</param>
 /// <param name="stateMachine">The state machine.</param>
 /// <param name="payload">The payload.</param>
 internal StateMachineTransitionContext(StateMachineState <TState, TTransition, TPayload> startState, TState endState, TTransition transition, StateMachineBase <TState, TTransition, TPayload> stateMachine, TPayload payload)
     : base(stateMachine, startState, payload)
 {
     this.StartState = startState.State;
     this.EndState   = endState;
     this.Transition = transition;
 }
コード例 #9
0
    public void Rebuild()
    {
        m_cachedParamIndex = 0;
        m_cachedParams.Clear();

        AddParam("section", StateMachineParamTypes.Long);                    // Current animation section
        AddParam("process", StateMachineParamTypes.Long);                    // Current process
        AddParam("key", StateMachineParamTypes.Long);                        // The first valid input in current state
        AddParam("exit", StateMachineParamTypes.Bool);                       // Current animation can exit ?
        AddParam("moveBreak", StateMachineParamTypes.Bool);                  // Current animation can break by movement ?
        AddParam("moving", StateMachineParamTypes.Bool);                     // Are we in moving state ?
        AddParam("state", StateMachineParamTypes.Long);                      // Current state
        AddParam("groupMask", StateMachineParamTypes.Long);                  // Current state group mask
        AddParam("prevGroupMask", StateMachineParamTypes.Long);              // Prev state group mask
        AddParam("targetGroupMask", StateMachineParamTypes.Long);            // Target group mask after hit (target passive state)
        AddParam("targetHitGroupMask", StateMachineParamTypes.Long);         // Target group mask when hit
        AddParam("configID", StateMachineParamTypes.Long);                   // Config ID (If statemachine is player, configID is player class)
        AddParam("targetConfigID", StateMachineParamTypes.Long);             // Target config ID
        AddParam("forcePassive", StateMachineParamTypes.Long);               // Force translate passive state
        AddParam("isDead", StateMachineParamTypes.Bool);                     // Creature dead (health < 1) ?
        AddParam("realDead", StateMachineParamTypes.Bool);                   // Creature real dead (health < 1 and dead animation ended) ?
        AddParam("hit", StateMachineParamTypes.Bool);                        // Hit target ?
        AddParam("hited", StateMachineParamTypes.Long);                      // Hited by other target ?
        AddParam("frame", StateMachineParamTypes.Long);                      // Current frame
        AddParam("rage", StateMachineParamTypes.Double);                     // Current rage
        AddParam("rageRate", StateMachineParamTypes.Double);                 // Current rage rate
        AddParam("weak", StateMachineParamTypes.Bool);                       // Creature in weak state ?
        AddParam("tough", StateMachineParamTypes.Bool);                      // Creature in tough state ?
        AddParam("fatal", StateMachineParamTypes.Long);                      // Creature in other creature's fatal radius ?
        AddParam("catchState", StateMachineParamTypes.Bool);                 // Creature in catch state ?
        AddParam("passiveCatchState", StateMachineParamTypes.Bool);          // Creature in passive catch state ?
        AddParam("immuneDeath", StateMachineParamTypes.Bool);                // Immune death
        AddParam("speedRun", StateMachineParamTypes.Double);                 // Creature run speed
        AddParam("speedAttack", StateMachineParamTypes.Double);              // Creature attack speed
        AddParam("weaponItemID", StateMachineParamTypes.Long);               // Current weapon item id
        AddParam("offWeaponItemID", StateMachineParamTypes.Long);            // Current off-hand weapon item id
        AddParam("hasLaydownTime", StateMachineParamTypes.Bool);             // Current state has laydown time ?
        AddParam("nextLayDownTime", StateMachineParamTypes.Long);            // Next laydown state time
        AddParam("prevEthreal", StateMachineParamTypes.Long);                // Prev state ethreal count
        AddParam("prevPassiveEthreal", StateMachineParamTypes.Long);         // Prev state passive ethreal count
        AddParam("stateType", StateMachineParamTypes.Long);                  // Current state type   0 = normal  1 = off  2 = passive
        AddParam("loopCount", StateMachineParamTypes.Long);                  // Current loop count, first loop is 0
        AddParam("totalFrame", StateMachineParamTypes.Long);                 // Current frame count
        AddParam("freezing", StateMachineParamTypes.Bool);                   // StateMachine freezing ?
        AddParam("onGround", StateMachineParamTypes.Bool);                   // Creature on ground ?
        AddParam("morph", StateMachineParamTypes.Long);                      // Creature morph, see CreatureMorphs
        AddParam("energy", StateMachineParamTypes.Long);                     // Current energy
        AddParam("energyRate", StateMachineParamTypes.Double);               // Current energy rate

        CollectHitAndDeadEffects();
        CreateStates();
        CreateTransitions();

        currentState = states[0];
        currentState.Enter();

        onEnterState?.Invoke(null, currentState);
        onRebuild?.Invoke();
    }
コード例 #10
0
        /// <summary>
        /// Changes the state of the simulation.
        /// </summary>
        private ServiceResult OnControlSimulation(
            ISystemContext context,
            StateMachineState machine,
            uint transitionId,
            uint causeId,
            IList<object> inputArguments,
            IList<object> outputArguments)
        {
            switch (causeId)
            {
                case Opc.Ua.Methods.ProgramStateMachineType_Start:
                {
                    if (m_simulationTimer != null)
                    {
                        m_simulationTimer.Dispose();
                        m_simulationTimer = null;
                    }

                    uint updateRate = this.Simulation.UpdateRate.Value;

                    if (updateRate < 100)
                    {
                        updateRate = 100;
                        Simulation.UpdateRate.Value = updateRate;
                    }

                    m_simulationContext = context;
                    m_simulationTimer = new Timer(DoSimulation, null, (int)updateRate, (int)updateRate);
                    break;
                }

                case Opc.Ua.Methods.ProgramStateMachineType_Halt:
                case Opc.Ua.Methods.ProgramStateMachineType_Suspend:
                {
                    if (m_simulationTimer != null)
                    {
                        m_simulationTimer.Dispose();
                        m_simulationTimer = null;
                    }
                    
                    m_simulationContext = context;
                    break;
                }

                case Opc.Ua.Methods.ProgramStateMachineType_Reset:
                {
                    if (m_simulationTimer != null)
                    {
                        m_simulationTimer.Dispose();
                        m_simulationTimer = null;
                    }
                    
                    m_simulationContext = context;
                    break;
                }
            }
                
            return ServiceResult.Good;
        }
コード例 #11
0
ファイル: BoilerState.cs プロジェクト: MD-V/UA-.NETStandard
        /// <summary>
        /// Changes the state of the simulation.
        /// </summary>
        private ServiceResult OnControlSimulation(
            ISystemContext context,
            StateMachineState machine,
            uint transitionId,
            uint causeId,
            IList <object> inputArguments,
            IList <object> outputArguments)
        {
            switch (causeId)
            {
            case Opc.Ua.Methods.ProgramStateMachineType_Start:
            {
                if (m_simulationTimer != null)
                {
                    m_simulationTimer.Dispose();
                    m_simulationTimer = null;
                }

                uint updateRate = this.Simulation.UpdateRate.Value;

                if (updateRate < 100)
                {
                    updateRate = 100;
                    Simulation.UpdateRate.Value = updateRate;
                }

                m_simulationContext = context;
                m_simulationTimer   = new Timer(DoSimulation, null, (int)updateRate, (int)updateRate);
                break;
            }

            case Opc.Ua.Methods.ProgramStateMachineType_Halt:
            case Opc.Ua.Methods.ProgramStateMachineType_Suspend:
            {
                if (m_simulationTimer != null)
                {
                    m_simulationTimer.Dispose();
                    m_simulationTimer = null;
                }

                m_simulationContext = context;
                break;
            }

            case Opc.Ua.Methods.ProgramStateMachineType_Reset:
            {
                if (m_simulationTimer != null)
                {
                    m_simulationTimer.Dispose();
                    m_simulationTimer = null;
                }

                m_simulationContext = context;
                break;
            }
            }

            return(ServiceResult.Good);
        }
コード例 #12
0
 public void TransitionToState(StateMachineState nextState)
 {
     if (nextState != remainState)
     {
         currentState = nextState;
         OnExitState();
     }
 }
コード例 #13
0
 public ResumableStateMachineStateAllocator(VariableSlotAllocator?slotAllocator, StateMachineState firstState, bool increasing)
 {
     _increasing        = increasing;
     _slotAllocator     = slotAllocator;
     _matchedStateCount = 0;
     _firstState        = firstState;
     _nextState         = slotAllocator?.GetFirstUnusedStateMachineState(increasing) ?? firstState;
 }
コード例 #14
0
        private IteratorFinallyMethodSymbol MakeSynthesizedFinally(StateMachineState finalizeState)
        {
            var stateMachineType = (IteratorStateMachine)F.CurrentType;
            var finallyMethod    = new IteratorFinallyMethodSymbol(stateMachineType, GeneratedNames.MakeIteratorFinallyMethodName(finalizeState));

            F.ModuleBuilderOpt.AddSynthesizedDefinition(stateMachineType, finallyMethod.GetCciAdapter());
            return(finallyMethod);
        }
コード例 #15
0
        public void Configure(ActivityBuilder <TWorkflow, TInstance> builder)
        {
            StateMachineState <TInstance> targetState = _getTargetState(builder.Model);

            var activity = new TransitionActivity <TInstance>(builder.Model.CurrentStateAccessor, builder.State, builder.Event,
                                                              targetState);

            builder.AddActivity(activity);
        }
コード例 #16
0
        /// <summary>
        /// Adds the state, and state transition events, to the cache
        /// </summary>
        /// <param name="name"></param>
        /// <param name="state"></param>
        void SetState(string name, StateMachineState <TInstance> state)
        {
            _stateCache[name] = state;

            _eventCache[state.BeforeEnter.Name] = new StateMachineEvent <TInstance>(state.BeforeEnter, true);
            _eventCache[state.Enter.Name]       = new StateMachineEvent <TInstance>(state.Enter, true);
            _eventCache[state.Leave.Name]       = new StateMachineEvent <TInstance>(state.Leave, true);
            _eventCache[state.AfterLeave.Name]  = new StateMachineEvent <TInstance>(state.AfterLeave, true);
        }
コード例 #17
0
ファイル: PetCreature.cs プロジェクト: NoeCalmness/CoreFrame
    protected override void OnEnterState(StateMachineState old, StateMachineState now, float overrideBlendTime)
    {
        base.OnEnterState(old, now, overrideBlendTime);

        if (skills.ContainsKey(now.name))
        {
            skills[now.name].OnUseSkill();
        }
    }
コード例 #18
0
        internal static string MakeIteratorFinallyMethodName(StateMachineState finalizeState)
        {
            Debug.Assert((int)finalizeState < -2);

            // It is important that the name is only derived from the finalizeState, so that when
            // editing method during EnC the Finally methods corresponding to matching states have matching names.
            Debug.Assert((char)GeneratedNameKind.IteratorFinallyMethod == 'm');
            return("<>m__Finally" + StringExtensions.GetNumeral(-((int)finalizeState + 2)));
        }
コード例 #19
0
        void DeclareState(PropertyInfo property)
        {
            string name = property.Name;

            var state = new StateMachineState <TInstance>(this, name, _eventObservers);

            property.SetValue(this, state);

            SetState(name, state);
        }
コード例 #20
0
        public override bool TryGetPreviousStateMachineState(SyntaxNode syntax, out StateMachineState state)
        {
            if (_stateMachineStateMap != null &&
                TryGetPreviousSyntaxOffset(syntax, out int syntaxOffset) &&
                _stateMachineStateMap.TryGetValue(syntaxOffset, out state))
            {
                return(true);
            }

            state = default;
            return(false);
        }
コード例 #21
0
 void Start()
 {
     state = GetComponent<StateMachineState>();
     state.Enter += Enter;
     state.Exit += Exit;
     // give 'em a chance to start up
     StartCoroutine(
         Util.AfterOneFrame(
         () => behaviour.enabled = false)
     )
     ;
 }
コード例 #22
0
 void Start()
 {
     state        = GetComponent <StateMachineState>();
     state.Enter += Enter;
     state.Exit  += Exit;
     // give 'em a chance to start up
     StartCoroutine(
         Util.AfterOneFrame(
             () => behaviour.enabled = false)
         )
     ;
 }
コード例 #23
0
        /// <summary>
        /// Converts a state for scriban
        /// </summary>
        /// <param name="state">State</param>
        /// <param name="transitions">Transitions</param>
        /// <param name="endNodes">End nodes</param>
        /// <param name="startId">Id of the start node</param>
        /// <returns>Converted state</returns>
        private static ScribanExportState ConvertState(StateMachineState state, List <StateTransition> transitions, List <StateMachineStartEnd> endNodes, string startId)
        {
            ScribanExportState exportState = new ScribanExportState();

            exportState.Id               = state.Id;
            exportState.Name             = state.Name;
            exportState.Description      = state.Description;
            exportState.IsInitialState   = transitions.Any(l => l.TargetNodeId == state.Id && l.SourceNodeId == startId);
            exportState.HasEndConnection = transitions.Any(l => l.SourceNodeId == state.Id && endNodes.Any(e => e.Id == l.TargetNodeId));
            exportState.ScriptType       = ScribanScriptUtil.ConvertScriptType(state.ScriptType);
            exportState.ScriptName       = state.ScriptName;
            return(exportState);
        }
コード例 #24
0
        /// <summary>
        /// Sets the next state.
        /// </summary>
        /// <param name="state">The next state.</param>
        internal void SetState(StateMachineState <TState, TTransition, TPayload> state)
        {
            lock (this.transitionLock)
            {
                if (this.CurrentState.State.Equals(state.State))
                {
                    throw new ArgumentException($"Attempt to set state: {state.State} to itself.");
                }

                this.CurrentState = state;
                this.stateElapsedTime.Restart();
            }
        }
コード例 #25
0
 private static void ApplyOperation(StateValueOperations operation, BinaryTape tape, ref int position,
                                    out StateMachineState state)
 {
     tape[position] = operation.WriteValue;
     if (operation.TapeShiftDirection == Direction.Left)
     {
         position--;
     }
     else
     {
         position++;
     }
     state = operation.ContinueWithState;
 }
コード例 #26
0
    public bool CanChangeState(StateMachineState to)
    {
        bool result;

        if (Active) {
            if (to == null) result = false;
            else result = true;
        }
        else {
            result = false;
        }

        return result;
    }
コード例 #27
0
ファイル: CBus.cs プロジェクト: ardy30/CBus4Net
            public void Reset()
            {
                ParserState        = StateMachineState.NONE;
                ACK_Character      = null;
                CalculatedChecksum = 0xFF;
                MessageType        = CBusMessageType.NONE;

                //STX_Found = false;
                //ETX1_Found = ETX2_Found = false;
                //DataPointer = 0;

                CommandLength       = 0;
                PreviousRxCharacter = '\0';
            }
コード例 #28
0
            public IteratorFinallyFrame(
                IteratorFinallyFrame parent,
                StateMachineState finalizeState,
                IteratorFinallyMethodSymbol handler,
                HashSet <LabelSymbol> labels)
            {
                Debug.Assert(parent != null, "non root frame must have a parent");
                Debug.Assert((object)handler != null, "non root frame must have a handler");

                this.parent        = parent;
                this.finalizeState = finalizeState;
                this.handler       = handler;
                this.labels        = labels;
            }
コード例 #29
0
ファイル: StateMachine.cs プロジェクト: horsman/shieldlord
    public bool CanChangeState(StateMachineState to)
    {
        bool result;

        if (Active) {
            if (to == null) result = false;
            else if (state != null && !to.CanEnterFrom.Any(s => s == state)) result = false;
            else result = true;
        }
        else {
            result = false;
        }

        return result;
    }
コード例 #30
0
ファイル: StateMachine.cs プロジェクト: horsman/shieldlord
    public bool ChangeState(StateMachineState to)
    {
        bool changedState;
        if (CanChangeState(to)) {
            var from = State;
            if (from) from.OnExit();
            State = to;
            if (to) to.OnEnter();
            changedState = true;
        }
        else {
            changedState = false;
        }

        return changedState;
    }
コード例 #31
0
        public void Configure(StateMachineBuilder <TWorkflow, TInstance> stateMachineBuilder)
        {
            stateMachineBuilder.Model.States.Each(state =>
            {
                if (state.Name == StateMachineWorkflow.FinalStateName)
                {
                    return;
                }

                StateMachineState <TInstance> stateMachineState = stateMachineBuilder.Model.GetState(state.Name);

                var stateBuilder = new StateBuilderImpl <TWorkflow, TInstance>(stateMachineBuilder, stateMachineState);

                _configurators.Each(x => x.Configure(stateBuilder));
            });
        }
コード例 #32
0
            private void AddState(StateMachineState state, IteratorFinallyFrame innerHandler)
            {
                var knownStates = this.knownStates;

                if (knownStates == null)
                {
                    this.knownStates = knownStates = new Dictionary <StateMachineState, IteratorFinallyFrame>();
                }

                knownStates.Add(state, innerHandler);

                if (parent != null)
                {
                    // Present ourselves to the parent as responsible for a handling a state.
                    parent.AddState(state, this);
                }
            }
コード例 #33
0
        internal IteratorMethodToStateMachineRewriter(
            SyntheticBoundNodeFactory F,
            MethodSymbol originalMethod,
            FieldSymbol state,
            FieldSymbol current,
            IReadOnlySet <Symbol> hoistedVariables,
            IReadOnlyDictionary <Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
            SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals,
            ArrayBuilder <StateMachineStateDebugInfo> stateMachineStateDebugInfoBuilder,
            VariableSlotAllocator slotAllocatorOpt,
            int nextFreeHoistedLocalSlot,
            BindingDiagnosticBag diagnostics)
            : base(F, originalMethod, state, hoistedVariables, nonReusableLocalProxies, synthesizedLocalOrdinals, stateMachineStateDebugInfoBuilder, slotAllocatorOpt, nextFreeHoistedLocalSlot, diagnostics)
        {
            _current = current;

            _nextFinalizeState = slotAllocatorOpt?.GetFirstUnusedStateMachineState(increasing: false) ?? StateMachineState.FirstIteratorFinalizeState;
        }
コード例 #34
0
        /// <summary>
        /// Declares a sub-state on the machine. A sub-state is a state that is valid within a super-state,
        /// allowing a state machine to have multiple "states" -- nested parts of an overall state.
        /// </summary>
        /// <param name="propertyExpression">The state property expression</param>
        /// <param name="superState">The superstate of which this state is a substate</param>
        protected virtual void SubState(Expression <Func <State> > propertyExpression, State superState)
        {
            if (superState == null)
            {
                throw new ArgumentNullException(nameof(superState));
            }

            State <TInstance> superStateInstance = GetState(superState.Name);

            PropertyInfo property = propertyExpression.GetPropertyInfo();

            string name = property.Name;

            var state = new StateMachineState <TInstance>(this, name, _eventObservers, superStateInstance);

            property.SetValue(this, state);

            SetState(name, state);
        }
コード例 #35
0
        /// <summary>
        /// Invokes the callback function if it has been specified.
        /// </summary>
        protected ServiceResult InvokeCallback(
            StateMachineTransitionHandler callback,
            ISystemContext context,
            StateMachineState machine,
            uint transitionId,
            uint causeId,
            IList <object> inputArguments,
            IList <object> outputArguments)
        {
            if (callback != null)
            {
                try {
                    return(callback(context, this, transitionId, causeId, inputArguments, outputArguments));
                } catch (Exception e) {
                    return(new ServiceResult(e));
                }
            }

            return(ServiceResult.Good);
        }
コード例 #36
0
        void DeclareState(PropertyInfo property)
        {
            string name = property.Name;

            var propertyValue = property.GetValue(this);

            // If the state was already defined, don't define it again
            var existingState = propertyValue as StateMachineState <TInstance>;

            if (name.Equals(existingState?.Name))
            {
                return;
            }

            var state = new StateMachineState <TInstance>(this, name, _eventObservers);

            property.SetValue(this, state);

            SetState(name, state);
        }
コード例 #37
0
    public void SwitchState(string nextStateName)
    {
        if (CurrentStateName.Equals(nextStateName)) {
            return;
        }

        StateMachineState nextState = States.Get(nextStateName);

        if (nextState == null) {
            Debug.Log(string.Format("StateMachine on {0} could not switch to {1}.", gameObject.name, nextStateName));
            return;
        }

        if (CurrentState != null && CurrentState.End != null) {
            CurrentState.End();
        }

        CurrentState = nextState;
        if (CurrentState.Start != null) {
            CurrentState.Start();
        }
    }
コード例 #38
0
        /// <summary>
        /// Invokes the callback function if it has been specified.
        /// </summary>
        protected ServiceResult InvokeCallback(
            StateMachineTransitionHandler callback,
            ISystemContext context,
            StateMachineState machine,
            uint transitionId,
            uint causeId,
            IList<object> inputArguments,
            IList<object> outputArguments)
        {
            if (callback != null)
            {
                try
                {
                    return callback(context, this, transitionId, causeId, inputArguments, outputArguments);
                }
                catch (Exception e)
                {
                    return new ServiceResult(e);
                }
            }

            return ServiceResult.Good;
        }