public void DestinationStateIsCalculatedBasedOnTriggerParameters_Binding() { var sm = new StateMachine <State, Trigger>(State.A); var trigger = sm.SetTriggerParameters <int>(Trigger.X); sm.Configure(State.A) .PermitDynamic(trigger, i => i == 1 ? State.B : State.C); StateMachineInfo inf = sm.GetInfo(); Assert.True(inf.StateType == typeof(State)); Assert.Equal(inf.TriggerType, typeof(Trigger)); Assert.Equal(inf.States.Count(), 1); var binding = inf.States.Single(s => (State)s.UnderlyingState == State.A); Assert.True(binding.UnderlyingState is State); Assert.Equal(State.A, (State)binding.UnderlyingState); // Assert.Equal(0, binding.Substates.Count()); Assert.Equal(null, binding.Superstate); Assert.Equal(0, binding.EntryActions.Count()); Assert.Equal(0, binding.ExitActions.Count()); // Assert.Equal(0, binding.FixedTransitions.Count()); // Binding transition count mismatch" Assert.Equal(0, binding.IgnoredTriggers.Count()); Assert.Equal(1, binding.DynamicTransitions.Count()); // Dynamic transition count mismatch foreach (DynamicTransitionInfo trans in binding.DynamicTransitions) { Assert.True(trans.Trigger.UnderlyingTrigger is Trigger); Assert.Equal(Trigger.X, (Trigger)trans.Trigger.UnderlyingTrigger); Assert.Equal(0, trans.GuardConditionsMethodDescriptions.Count()); } }
public void OnExitWithNamedDelegateActionAndDescription_Binding() { var sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .OnExit(OnExit, "exitA"); StateMachineInfo inf = sm.GetInfo(); Assert.True(inf.StateType == typeof(State)); Assert.Equal(inf.States.Count(), 1); var binding = inf.States.Single(s => (State)s.UnderlyingState == State.A); Assert.True(binding.UnderlyingState is State); Assert.Equal(State.A, (State)binding.UnderlyingState); // Assert.Equal(0, binding.Substates.Count()); Assert.Equal(null, binding.Superstate); // Assert.Equal(0, binding.EntryActions.Count()); Assert.Equal(1, binding.ExitActions.Count()); foreach (InvocationInfo entryAction in binding.ExitActions) { Assert.Equal("exitA", entryAction.Description); } // Assert.Equal(0, binding.FixedTransitions.Count()); // Binding count mismatch Assert.Equal(0, binding.IgnoredTriggers.Count()); Assert.Equal(0, binding.DynamicTransitions.Count()); // Dynamic transition count mismatch }
internal StateMachine(State <TTrig, TName> startState, List <State <TTrig, TName> > allStates, string?name) { CurrentState = startState; PreviousState = null; OnStateSet?.Invoke(PreviousState, CurrentState); StateMachineInfo = new StateMachineInfo <TTrig, TName>(allStates, startState, name); }
public void SimpleTransition_Binding() { var sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .Permit(Trigger.X, State.B); StateMachineInfo inf = sm.GetInfo(); Assert.Equal(inf.TriggerType, typeof(Trigger)); Assert.Equal(inf.States.Count(), 2); var binding = inf.States.Single(s => (State)s.UnderlyingState == State.A); Assert.True(binding.UnderlyingState is State); Assert.Equal(State.A, (State)binding.UnderlyingState); // Assert.Equal(0, binding.Substates.Count()); Assert.Equal(null, binding.Superstate); Assert.Equal(0, binding.EntryActions.Count()); Assert.Equal(0, binding.ExitActions.Count()); // Assert.Equal(1, binding.FixedTransitions.Count()); foreach (FixedTransitionInfo trans in binding.FixedTransitions) { Assert.True(trans.Trigger.UnderlyingTrigger is Trigger); Assert.Equal(Trigger.X, (Trigger)trans.Trigger.UnderlyingTrigger); // Assert.True(trans.DestinationState.UnderlyingState is State); Assert.Equal(State.B, (State)trans.DestinationState.UnderlyingState); Assert.Equal(0, trans.GuardConditionsMethodDescriptions.Count()); } Assert.Equal(0, binding.IgnoredTriggers.Count()); Assert.Equal(0, binding.DynamicTransitions.Count()); }
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; }
public static List <string> BuildWeaponPreloadAssets(int proto, int gender, int weaponID, int weaponItemID = -1, int offWeaponID = -1, int offWeaponItemID = -1, List <string> assets = null, bool player = false) { if (assets == null) { assets = new List <string>(); } assets.Add(Creature.GetAnimatorName(weaponID, gender)); // Animator var w = WeaponInfo.GetWeapon(weaponID, weaponItemID); // Main-hand weapon models w.GetAllAssets(assets); assets.Add(WeaponInfo.GetVictoryAnimation(weaponID, gender)); if (offWeaponID > -1) { w = WeaponInfo.GetWeapon(offWeaponID, offWeaponItemID); // Off-hand weapon models w.GetAllAssets(assets); } // Collect all weapon assets StateMachineInfo.GetAllAssets(weaponID, offWeaponID, assets, proto, gender, weaponItemID, offWeaponItemID, player); return(assets); }
protected override void OnInitialize() { speed = 1.0; m_forceTransitionUpdate = false; m_preventShake = false; m_pending = false; m_playable = true; m_freezCount = 0; m_pendingTime = 0; m_nextPendingTime = 0; m_passiveMask = 0; m_passiveSource = null; freezing = false; if (!info) { info = StateMachineInfo.empty; } if (animator) { if (!animator.isInitialized && animator.gameObject.activeInHierarchy) { animator.Update(0); } animator.enabled = false; } }
/// <summary> /// Add states to the graph that are neither superstates, nor substates of a superstate. /// </summary> /// <param name="machineInfo"></param> void AddSingleStates(StateMachineInfo machineInfo) { foreach (var stateInfo in machineInfo.States) { if (!States.ContainsKey(stateInfo.UnderlyingState.ToString())) States[stateInfo.UnderlyingState.ToString()] = new State(stateInfo); } }
public void TwoSimpleTransitions_Binding() { var sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .Permit(Trigger.X, State.B) .Permit(Trigger.Y, State.C); StateMachineInfo inf = sm.GetInfo(); Assert.True(inf.StateType == typeof(State)); Assert.Equal(inf.TriggerType, typeof(Trigger)); Assert.Equal(inf.States.Count(), 3); var binding = inf.States.Single(s => (State)s.UnderlyingState == State.A); Assert.True(binding.UnderlyingState is State); Assert.Equal(State.A, (State)binding.UnderlyingState); // Binding state value mismatch // Assert.Equal(0, binding.Substates.Count()); // Binding substate count mismatch" Assert.Equal(null, binding.Superstate); Assert.Equal(0, binding.EntryActions.Count()); // Binding entry actions count mismatch Assert.Equal(0, binding.ExitActions.Count()); // Assert.Equal(2, binding.FixedTransitions.Count()); // Transition count mismatch // bool haveXB = false; bool haveYC = false; foreach (FixedTransitionInfo trans in binding.FixedTransitions) { Assert.True(trans.Trigger.UnderlyingTrigger is Trigger); // Assert.True(trans.DestinationState.UnderlyingState is State); Assert.Equal(0, trans.GuardConditionsMethodDescriptions.Count()); // // Can't make assumptions about which trigger/destination comes first in the list if ((Trigger)trans.Trigger.UnderlyingTrigger == Trigger.X) { Assert.Equal(State.B, (State)trans.DestinationState.UnderlyingState); Assert.False(haveXB); haveXB = true; } else if ((Trigger)trans.Trigger.UnderlyingTrigger == Trigger.Y) { Assert.Equal(State.C, (State)trans.DestinationState.UnderlyingState); Assert.False(haveYC); haveYC = true; } else { throw new XunitException("Failed."); } } Assert.True(haveXB && haveYC); // Assert.Equal(0, binding.IgnoredTriggers.Count()); Assert.Equal(0, binding.DynamicTransitions.Count()); }
/// <summary> /// Add superstates to the graph (states that have substates) /// </summary> /// <param name="machineInfo"></param> void AddSuperstates(StateMachineInfo machineInfo) { foreach (var stateInfo in machineInfo.States.Where(sc => (sc.Substates?.Count() > 0) && (sc.Superstate == null))) { SuperState state = new SuperState(stateInfo); States[stateInfo.UnderlyingState.ToString()] = state; AddSubstates(state, stateInfo.Substates); } }
/// <summary> /// Add all transitions to the graph /// </summary> /// <param name="machineInfo"></param> void AddTransitions(StateMachineInfo machineInfo) { foreach (var stateInfo in machineInfo.States) { State fromState = States[stateInfo.UnderlyingState.ToString()]; foreach (var fix in stateInfo.FixedTransitions) { State toState = States[fix.DestinationState.UnderlyingState.ToString()]; if (fromState == toState) { StayTransition stay = new StayTransition(fromState, fix.Trigger, fix.GuardConditionsMethodDescriptions, true); Transitions.Add(stay); fromState.Leaving.Add(stay); fromState.Arriving.Add(stay); } else { FixedTransition trans = new FixedTransition(fromState, toState, fix.Trigger, fix.GuardConditionsMethodDescriptions); Transitions.Add(trans); fromState.Leaving.Add(trans); toState.Arriving.Add(trans); } } foreach (var dyno in stateInfo.DynamicTransitions) { Decision decide = new Decision(dyno.DestinationStateSelectorDescription, Decisions.Count + 1); Decisions.Add(decide); FixedTransition trans = new FixedTransition(fromState, decide, dyno.Trigger, dyno.GuardConditionsMethodDescriptions); Transitions.Add(trans); fromState.Leaving.Add(trans); decide.Arriving.Add(trans); if (dyno.PossibleDestinationStates != null) { foreach (var dynamicStateInfo in dyno.PossibleDestinationStates) { State toState = null; States.TryGetValue(dynamicStateInfo.DestinationState, out toState); if (toState != null) { DynamicTransition dtrans = new DynamicTransition(decide, toState, dyno.Trigger, dynamicStateInfo.Criterion); Transitions.Add(dtrans); decide.Leaving.Add(dtrans); toState.Arriving.Add(dtrans); } } } } foreach (var igno in stateInfo.IgnoredTriggers) { StayTransition stay = new StayTransition(fromState, igno.Trigger, igno.GuardConditionsMethodDescriptions, false); Transitions.Add(stay); fromState.Leaving.Add(stay); fromState.Arriving.Add(stay); } } }
public void AddSubStateMachine(StateMachineInfo subInfo) { var sub = subStateMachines.Find(s => s.hash == subInfo.hash && s.ID == subInfo.ID); if (sub) { subStateMachines.Remove(sub); } subStateMachines.Add(info); Rebuild(); }
public StateGraph(StateMachineInfo machineInfo) { // Start with top-level superstates AddSuperstates(machineInfo); // Now add any states that aren't part of a tree AddSingleStates(machineInfo); // Now grab transitions AddTransitions(machineInfo); // Handle "OnEntryFrom" ProcessOnEntryFrom(machineInfo); }
public static StateMachine Create(StateMachineInfo info, Creature creature, bool isAI, params StateMachineInfo[] subStateMachines) { var sm = Create(false); sm.info = info; sm.creature = creature; sm.animator = creature.animator; sm.transtionGroupId = info == null ? 0 : isAI ? info.aiTransitionGroup : info.transitionGroup; sm.subStateMachines.AddRange(subStateMachines); sm.subStateMachines.RemoveAll(s => !s); sm.OnInitialize(); return(sm); }
public static List <string> BuildWeaponSimplePreloadAssets(int proto, int gender, int weaponID, int weaponItemID, List <string> assets = null) { if (assets == null) { assets = new List <string>(); } assets.Add(Creature.GetAnimatorNameSimple(weaponID, gender)); // Animator var w = WeaponInfo.GetWeapon(weaponID, weaponItemID); // Main-hand weapon models w.GetAllAssets(assets); // Simple statemachine StateMachineInfo.GetAllAssets(weaponID, -1, assets, proto, gender, weaponItemID, -1, false, true); return(assets); }
private void CreateStates() { states.Clear(); m_passiveHash.Clear(); m_coolGroups.Clear(); var ss = info.states; foreach (var s in ss) { CreateState(s, info); } StateMachineInfoPassive psm = null; foreach (var sub in subStateMachines) { if (psm == null && sub is StateMachineInfoPassive) { psm = sub as StateMachineInfoPassive; } foreach (var s in sub.states) { CreateState(s, sub); } } m_laydown = GetState(StateMachineState.STATE_LAYDOWN); if (!m_laydown) { var p = psm ?? info; CreateState(StateMachineInfo.GetDefaultLaydownState(p.GetType().GetHashCode(), p.ID), p); } if (states.Count < 1) { states.Add(StateMachineState.Create(this, info, StateMachineInfo.emptyState, SkilLEntry.empty)); } }
public static StateMachineState Create(StateMachine stateMachine, StateMachineInfo parent, StateMachineInfo.StateDetail info, SkilLEntry skill) { var state = Create(false); state.stateMachine = stateMachine; state.parent = parent; state.info = info; state.OnInitialize(); if (skill.valid) { state.m_skill = skill.skillId; state.m_level = skill.level; state.m_skillDamageMul = state.m_skill > -1 && state.m_level > -1 ? UpSkillInfo.GetOverrideDamage(state.m_skill, state.m_level) : 0; state.m_skillDamageMul *= 1 + skill.addtion; // @TODO: ?? } return(state); }
public void WhenDiscriminatedByAnonymousGuardWithDescription_Binding() { bool anonymousGuard() => true; var sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .PermitIf(Trigger.X, State.B, anonymousGuard, "description"); StateMachineInfo inf = sm.GetInfo(); Assert.True(inf.StateType == typeof(State)); Assert.Equal(inf.TriggerType, typeof(Trigger)); Assert.Equal(inf.States.Count(), 2); var binding = inf.States.Single(s => (State)s.UnderlyingState == State.A); Assert.True(binding.UnderlyingState is State); Assert.Equal(State.A, (State)binding.UnderlyingState); // Assert.Equal(0, binding.Substates.Count()); Assert.Equal(null, binding.Superstate); Assert.Equal(0, binding.EntryActions.Count()); Assert.Equal(0, binding.ExitActions.Count()); // Assert.Equal(1, binding.FixedTransitions.Count()); foreach (FixedTransitionInfo trans in binding.FixedTransitions) { Assert.True(trans.Trigger.UnderlyingTrigger is Trigger); Assert.Equal(Trigger.X, (Trigger)trans.Trigger.UnderlyingTrigger); // Assert.True(trans.DestinationState.UnderlyingState is State); Assert.Equal(State.B, (State)trans.DestinationState.UnderlyingState); // Assert.Equal(1, trans.GuardConditionsMethodDescriptions.Count()); Assert.Equal("description", trans.GuardConditionsMethodDescriptions.First().Description); } Assert.Equal(0, binding.IgnoredTriggers.Count()); Assert.Equal(0, binding.DynamicTransitions.Count()); }
/// <summary> /// Process all entry actions that have a "FromTrigger" (meaning they are /// only executed when the state is entered because the specified trigger /// was fired). /// </summary> /// <param name="machineInfo"></param> void ProcessOnEntryFrom(StateMachineInfo machineInfo) { foreach (var stateInfo in machineInfo.States) { State state = States[stateInfo.UnderlyingState.ToString()]; foreach (var entryAction in stateInfo.EntryActions) { if (entryAction.FromTrigger != null) { // This 'state' has an 'entryAction' that only fires when it gets the trigger 'entryAction.FromTrigger' // Does it have any incoming transitions that specify that trigger? foreach (var transit in state.Arriving) { if ((transit.ExecuteEntryExitActions) && (transit.Trigger.UnderlyingTrigger.ToString() == entryAction.FromTrigger)) { transit.DestinationEntryActions.Add(entryAction); } } } } } }
private bool CreateState(StateMachineInfo.StateDetail s, StateMachineInfo parent) { if (!s.valid) { return(false); } StateMachineState state = null; var skillID = SkillToStateInfo.GetSkillID(creature.weaponID, s.ID); if (skillID < 0) { var list = AwakeInfo.GetSkillIDList(s.hash); if (list != null && list.Count > 0) { var ss = new List <StateMachineInfo.StateDetail>(); foreach (var id in list) { var lv = creature.GetSkillLevel(id); if (lv > 0) { var ainfo = ConfigManager.Get <AwakeInfo>(id); var stateLevel = ainfo?.states.Find(Item => Item.state == s.state); if (stateLevel != null) { lv = stateLevel.level; } } if (lv >= 0) { var os = StateOverrideInfo.GetOriginOverrideState(info, s, lv); if (os != null) { ss.Add(os); } } } s = StateOverrideInfo.StateOverride.Combin(s, ss); } if (!s.valid) { return(false); } state = StateMachineState.Create(this, parent, s, SkilLEntry.empty); } else { var skill = creature.GetSkillEntry(skillID); var level = skill.valid ? skill.level : 0; var ls = level <= 0 ? s : StateOverrideInfo.GetOverrideState(info, s, level); if (!ls.valid) { return(false); } state = StateMachineState.Create(this, parent, ls, skill); } states.Add(state); if (state.passive) { m_passiveHash.Set(s.ID, states.Count - 1); } if (s.coolGroup != 0) { m_coolGroups.GetDefault(s.coolGroup).Add(state); } return(true); }
public void TransitionGuardNames() { var sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .PermitIf(Trigger.X, State.B, Permit); sm.Configure(State.B) .PermitIf(Trigger.X, State.C, Permit, UserDescription + "B-Permit"); sm.Configure(State.C) .PermitIf(Trigger.X, State.B, () => Permit()); sm.Configure(State.D) .PermitIf(Trigger.X, State.C, () => Permit(), UserDescription + "D-Permit"); StateMachineInfo inf = sm.GetInfo(); foreach (StateInfo stateInfo in inf.States) { Assert.Equal(1, stateInfo.Transitions.Count()); TransitionInfo transInfo = stateInfo.Transitions.First(); Assert.Equal(1, transInfo.GuardConditionsMethodDescriptions.Count()); VerifyMethodNames(transInfo.GuardConditionsMethodDescriptions, "", "Permit", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Synchronous); } // -------------------------------------------------------- sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .PermitDynamicIf(Trigger.X, NextState, Permit); sm.Configure(State.B) .PermitDynamicIf(Trigger.X, NextState, Permit, UserDescription + "B-Permit"); sm.Configure(State.C) .PermitDynamicIf(Trigger.X, NextState, () => Permit()); sm.Configure(State.D) .PermitDynamicIf(Trigger.X, NextState, () => Permit(), UserDescription + "D-Permit"); inf = sm.GetInfo(); foreach (StateInfo stateInfo in inf.States) { Assert.Equal(1, stateInfo.Transitions.Count()); TransitionInfo transInfo = stateInfo.Transitions.First(); Assert.Equal(1, transInfo.GuardConditionsMethodDescriptions.Count()); VerifyMethodNames(transInfo.GuardConditionsMethodDescriptions, "", "Permit", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Synchronous); } /* * public IgnoredTriggerBehaviour(TTrigger trigger, Func<bool> guard, string description = null) * : base(trigger, new TransitionGuard(guard, description)) * public InternalTriggerBehaviour(TTrigger trigger, Func<bool> guard) * : base(trigger, new TransitionGuard(guard, "Internal Transition")) * public TransitioningTriggerBehaviour(TTrigger trigger, TState destination, Func<bool> guard = null, string guardDescription = null) * : base(trigger, new TransitionGuard(guard, guardDescription)) * * public StateConfiguration PermitReentryIf(TTrigger trigger, Func<bool> guard, string guardDescription = null) * * public StateConfiguration PermitDynamicIf<TArg0>(TriggerWithParameters<TArg0> trigger, Func<TArg0, TState> destinationStateSelector, Func<bool> guard, string guardDescription = null) * public StateConfiguration PermitDynamicIf<TArg0, TArg1>(TriggerWithParameters<TArg0, TArg1> trigger, Func<TArg0, TArg1, TState> destinationStateSelector, Func<bool> guard, string guardDescription = null) * public StateConfiguration PermitDynamicIf<TArg0, TArg1, TArg2>(TriggerWithParameters<TArg0, TArg1, TArg2> trigger, Func<TArg0, TArg1, TArg2, TState> destinationStateSelector, Func<bool> guard, string guardDescription = null) * * StateConfiguration InternalPermit(TTrigger trigger, TState destinationState, string guardDescription) * StateConfiguration InternalPermitDynamic(TTrigger trigger, Func<object[], TState> destinationStateSelector, string guardDescription) */ }
public void ReflectionMethodNamesAsync() { var sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .OnActivateAsync(OnActivateAsync) .OnEntryAsync(OnEntryAsync) .OnExitAsync(OnExitAsync) .OnDeactivateAsync(OnDeactivateAsync); sm.Configure(State.B) .OnActivateAsync(OnActivateAsync, UserDescription + "B-Activate") .OnEntryAsync(OnEntryAsync, UserDescription + "B-Entry") .OnExitAsync(OnExitAsync, UserDescription + "B-Exit") .OnDeactivateAsync(OnDeactivateAsync, UserDescription + "B-Deactivate"); sm.Configure(State.C) .OnActivateAsync(() => OnActivateAsync()) .OnEntryAsync(() => OnEntryAsync()) .OnExitAsync(() => OnExitAsync()) .OnDeactivateAsync(() => OnDeactivateAsync()); sm.Configure(State.D) .OnActivateAsync(() => OnActivateAsync(), UserDescription + "D-Activate") .OnEntryAsync(() => OnEntryAsync(), UserDescription + "D-Entry") .OnExitAsync(() => OnExitAsync(), UserDescription + "D-Exit") .OnDeactivateAsync(() => OnDeactivateAsync(), UserDescription + "D-Deactivate"); StateMachineInfo inf = sm.GetInfo(); foreach (StateInfo stateInfo in inf.States) { VerifyMethodNames(stateInfo.ActivateActions, "On", "Activate", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Asynchronous); VerifyMethodNames(stateInfo.EntryActions.Select(x => x.Method), "On", "Entry", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Asynchronous); VerifyMethodNames(stateInfo.ExitActions, "On", "Exit", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Asynchronous); VerifyMethodNames(stateInfo.DeactivateActions, "On", "Deactivate", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Asynchronous); } // New StateMachine, new tests: entry and exit, functions that take the transition as an argument sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .OnEntryAsync(OnEntryTransAsync) .OnExitAsync(OnExitTransAsync); sm.Configure(State.B) .OnEntryAsync(OnEntryTransAsync, UserDescription + "B-EntryTrans") .OnExitAsync(OnExitTransAsync, UserDescription + "B-ExitTrans"); sm.Configure(State.C) .OnEntryAsync(t => OnEntryTransAsync(t)) .OnExitAsync(t => OnExitTransAsync(t)); sm.Configure(State.D) .OnEntryAsync(t => OnEntryTransAsync(t), UserDescription + "D-EntryTrans") .OnExitAsync(t => OnExitTransAsync(t), UserDescription + "D-ExitTrans"); inf = sm.GetInfo(); foreach (StateInfo stateInfo in inf.States) { VerifyMethodNames(stateInfo.EntryActions.Select(x => x.Method), "On", "EntryTrans", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Asynchronous); VerifyMethodNames(stateInfo.ExitActions, "On", "ExitTrans", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Asynchronous); } /* * public StateConfiguration OnEntryFromAsync(TTrigger trigger, Func<Task> entryAction, string entryActionDescription = null) * public StateConfiguration OnEntryFromAsync(TTrigger trigger, Func<Transition, Task> entryAction, string entryActionDescription = null) * public StateConfiguration OnEntryFromAsync<TArg0>(TriggerWithParameters<TArg0> trigger, Func<TArg0, Task> entryAction, string entryActionDescription = null) * public StateConfiguration OnEntryFromAsync<TArg0>(TriggerWithParameters<TArg0> trigger, Func<TArg0, Transition, Task> entryAction, string entryActionDescription = null) * public StateConfiguration OnEntryFromAsync<TArg0, TArg1>(TriggerWithParameters<TArg0, TArg1> trigger, Func<TArg0, TArg1, Task> entryAction, string entryActionDescription = null) * public StateConfiguration OnEntryFromAsync<TArg0, TArg1>(TriggerWithParameters<TArg0, TArg1> trigger, Func<TArg0, TArg1, Transition, Task> entryAction, string entryActionDescription = null) * public StateConfiguration OnEntryFromAsync<TArg0, TArg1, TArg2>(TriggerWithParameters<TArg0, TArg1, TArg2> trigger, Func<TArg0, TArg1, TArg2, Task> entryAction, string entryActionDescription = null) * public StateConfiguration OnEntryFromAsync<TArg0, TArg1, TArg2>(TriggerWithParameters<TArg0, TArg1, TArg2> trigger, Func<TArg0, TArg1, TArg2, Transition, Task> entryAction, string entryActionDescription = null) */ }
public void ReflectionMethodNames() { var sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .OnActivate(OnActivate) .OnEntry(OnEntry) .OnExit(OnExit) .OnDeactivate(OnDeactivate); sm.Configure(State.B) .OnActivate(OnActivate, UserDescription + "B-Activate") .OnEntry(OnEntry, UserDescription + "B-Entry") .OnExit(OnExit, UserDescription + "B-Exit") .OnDeactivate(OnDeactivate, UserDescription + "B-Deactivate"); sm.Configure(State.C) .OnActivate(() => OnActivate()) .OnEntry(() => OnEntry()) .OnExit(() => OnExit()) .OnDeactivate(() => OnDeactivate()); sm.Configure(State.D) .OnActivate(() => OnActivate(), UserDescription + "D-Activate") .OnEntry(() => OnEntry(), UserDescription + "D-Entry") .OnExit(() => OnExit(), UserDescription + "D-Exit") .OnDeactivate(() => OnDeactivate(), UserDescription + "D-Deactivate"); StateMachineInfo inf = sm.GetInfo(); foreach (StateInfo stateInfo in inf.States) { VerifyMethodNames(stateInfo.ActivateActions, "On", "Activate", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Synchronous); VerifyMethodNames(stateInfo.EntryActions.Select(x => x.Method), "On", "Entry", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Synchronous); VerifyMethodNames(stateInfo.ExitActions, "On", "Exit", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Synchronous); VerifyMethodNames(stateInfo.DeactivateActions, "On", "Deactivate", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Synchronous); } // -------------------------------------------------------- // New StateMachine, new tests: entry and exit, functions that take the transition as an argument sm = new StateMachine <State, Trigger>(State.A); sm.Configure(State.A) .OnEntry(OnEntryTrans) .OnExit(OnExitTrans); sm.Configure(State.B) .OnEntry(OnEntryTrans, UserDescription + "B-EntryTrans") .OnExit(OnExitTrans, UserDescription + "B-ExitTrans"); sm.Configure(State.C) .OnEntry(t => OnEntryTrans(t)) .OnExit(t => OnExitTrans(t)); sm.Configure(State.D) .OnEntry(t => OnEntryTrans(t), UserDescription + "D-EntryTrans") .OnExit(t => OnExitTrans(t), UserDescription + "D-ExitTrans"); inf = sm.GetInfo(); foreach (StateInfo stateInfo in inf.States) { VerifyMethodNames(stateInfo.EntryActions.Select(x => x.Method), "On", "EntryTrans", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Synchronous); VerifyMethodNames(stateInfo.ExitActions, "On", "ExitTrans", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Synchronous); } // -------------------------------------------------------- sm = new StateMachine <State, Trigger>(State.A); var triggerX = sm.SetTriggerParameters <int>(Trigger.X); var triggerY = sm.SetTriggerParameters <int, int>(Trigger.Y); var triggerZ = sm.SetTriggerParameters <int, int, int>(Trigger.Z); sm.Configure(State.A) .OnEntryFrom(Trigger.X, OnEntry) .OnEntryFrom(Trigger.Y, OnEntryTrans) .OnEntryFrom(triggerX, OnEntryInt) .OnEntryFrom(triggerX, OnEntryIntTrans) .OnEntryFrom(triggerY, OnEntryIntInt) .OnEntryFrom(triggerZ, OnEntryIntIntInt); sm.Configure(State.B) .OnEntryFrom(Trigger.X, OnEntry, UserDescription + "B-Entry") .OnEntryFrom(Trigger.Y, OnEntryTrans, UserDescription + "B-EntryTrans") .OnEntryFrom(triggerX, OnEntryInt, UserDescription + "B-EntryInt") .OnEntryFrom(triggerX, OnEntryIntTrans, UserDescription + "B-EntryIntTrans") .OnEntryFrom(triggerY, OnEntryIntInt, UserDescription + "B-EntryIntInt") .OnEntryFrom(triggerZ, OnEntryIntIntInt, UserDescription + "B-EntryIntIntInt"); sm.Configure(State.C) .OnEntryFrom(Trigger.X, () => OnEntry()) .OnEntryFrom(Trigger.Y, trans => OnEntryTrans(trans)) .OnEntryFrom(triggerX, i => OnEntryInt(i)) .OnEntryFrom(triggerX, (i, trans) => OnEntryIntTrans(i, trans)) .OnEntryFrom(triggerY, (i, j) => OnEntryIntInt(i, j)) .OnEntryFrom(triggerZ, (i, j, k) => OnEntryIntIntInt(i, j, k)); sm.Configure(State.D) .OnEntryFrom(Trigger.X, () => OnEntry(), UserDescription + "D-Entry") .OnEntryFrom(Trigger.Y, trans => OnEntryTrans(trans), UserDescription + "D-EntryTrans") .OnEntryFrom(triggerX, i => OnEntryInt(i), UserDescription + "D-EntryInt") .OnEntryFrom(triggerX, (i, trans) => OnEntryIntTrans(i, trans), UserDescription + "D-EntryIntTrans") .OnEntryFrom(triggerY, (i, j) => OnEntryIntInt(i, j), UserDescription + "D-EntryIntInt") .OnEntryFrom(triggerZ, (i, j, k) => OnEntryIntIntInt(i, j, k), UserDescription + "D-EntryIntIntInt"); inf = sm.GetInfo(); foreach (StateInfo stateInfo in inf.States) { VerifyMethodNameses(stateInfo.EntryActions.Select(x => x.Method), "On", "Entry", (State)stateInfo.UnderlyingState, InvocationInfo.Timing.Synchronous, new HashSet <string> { "", "Trans", "Int", "IntTrans", "IntInt", "IntIntInt" }); } /* * public StateConfiguration OnEntryFrom<TArg0, TArg1>(TriggerWithParameters<TArg0, TArg1> trigger, Action<TArg0, TArg1, Transition> entryAction, string entryActionDescription = null) * public StateConfiguration OnEntryFrom<TArg0, TArg1, TArg2>(TriggerWithParameters<TArg0, TArg1, TArg2> trigger, Action<TArg0, TArg1, TArg2, Transition> entryAction, string entryActionDescription = null) */ }
private void LoadStateMachineEffect(List <string> assets, int weaponId, int weaponItemID, int proto, int gender) { StateMachineInfo.GetAllAssets(weaponId, -1, assets, proto, gender, weaponItemID); }
/// <summary> /// Generate a UML DOT graph from the state machine info /// </summary> /// <param name="machineInfo"></param> /// <returns></returns> public static string Format(StateMachineInfo machineInfo) { var graph = new StateGraph(machineInfo); return(graph.ToGraph(new UmlDotGraphStyle())); }