本文整理汇总了C#中IState.Enter方法的典型用法代码示例。如果您正苦于以下问题:C# IState.Enter方法的具体用法?C# IState.Enter怎么用?C# IState.Enter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IState
的用法示例。
在下文中一共展示了IState.Enter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeState
protected void ChangeState(IState newState)
{
state.Exit();
state = newState;
state.Enter();
Publish(new Events.NetworkOut { Action = (ep) => server.NetworkOut.SetUnitState(ep, Id, newState.EncodeEnum) });
}
示例2: ChangeState
public void ChangeState(IState state) {
if (currentState != null) {
currentState.Leave(this, state);
}
state.Enter(this, currentState);
this.previousState = currentState;
this.currentState = state;
}
示例3: ChangeState
public void ChangeState(IState newState, IActor Actor) {
if (state != null && newState != null) {
state.Exit(Actor);
previousState = state;
state = newState;
state.Enter(Actor);
Actor.Save();
}
}
示例4: ChangeState
public void ChangeState(IState state)
{
_prevState = _currState;
_currState = state;
if (_prevState != null)
_prevState.Leave();
if (_currState != null)
_currState.Enter();
}
示例5: DoState
public void DoState()
{
IState NextState = CurrentState.Step();
if (NextState.GetType() != CurrentState.GetType())
{
CurrentState.Leave();
CurrentState = NextState;
CurrentState.Enter();
}
}
示例6: Update
public void Update()
{
IState previous = _state;
_state = _state.Update();
if(_state != previous)
{
previous.Quit();
_state.Enter();
}
}
示例7: ChangeState
public virtual void ChangeState(ITransition transition)
{
if (transition == null)
{
throw new ArgumentNullException(nameof(transition), "Cannot change state with a null transition");
}
var oldState = this.State;
var newState = this.GetDestinationState(transition);
if (newState == null)
{
throw new InvalidTransitionException(oldState, transition);
}
FireChanging(newState);
// Exit old State
try
{
State.Exit(transition);
}
catch (Exception e)
{
throw new StateFailedToExitException(oldState, transition, e);
}
// Change State
State = newState;
// Enter new State
try
{
State.Enter(transition);
}
catch (Exception e)
{
throw new StateFailedToEnterException(oldState, transition, newState, e);
}
FireChanged();
State.Action(this);
}
示例8: AddAgent
/// <summary>
/// Adds an agent to the manager.
/// </summary>
/// <remarks>
/// <para>
/// The manager expects to take ownership of the state objects. It also assumes that the
/// state objects are inactive but ready to activate.
/// </para>
/// </remarks>
/// <param name="planner">The agent's planner.</param>
/// <param name="mover">The agent's mover.</param>
/// <returns>The index of the agent, or -1 on failure.</returns>
public int AddAgent(IState planner, IState mover)
{
if (planner == null || mover == null)
return -1;
for (int i = 0; i < mPlanners.Length; i++)
{
if (mPlanners[i] == null)
{
if (!planner.Enter())
break;
if (!mover.Enter())
{
planner.Exit();
break;
}
mPlanners[i] = planner;
mMovers[i] = mover;
return i;
}
}
return -1;
}
示例9: ProcessNextState
public void ProcessNextState()
{
if (null != m_CurrentState)
{
if (ProcessCurrentStateExit() && !m_CurrentState.Exit())
{
m_NextState = m_CurrentState;//yes this is right - don't let them change state
}
}
m_CurrentState = m_NextState;
m_NextState = null;
SetControlLayout(m_CurrentState.Control as IContextPanelControl);
m_CurrentState.Enter();
}
示例10: ChangeState
protected void ChangeState(IState newState)
{
if (aiState == newState) return;
if (aiState != null)
aiState.Exit();
aiState = newState;
aiState.Enter();
OnChangesState();
}
示例11: ChangeState
/// <summary>
/// Pushes the machine into a new state and retains the current state as previous state.
/// </summary>
/// <param name="newState"></param>
public void ChangeState(IState newState)
{
if(newState == null)
{
//System.Diagnostics.Debug.WriteLine("Attempted to set a null state for " + m_Owner.ToString());
#if DEBUG
throw new Exception("Attempted to set a null state for " + m_Owner.ToString());
#endif
return;
}
if (m_Owner.OnBeforeCurrentStateChanged(this, m_CurrentState, newState))
{
m_PreviousState = m_CurrentState;
if (m_CurrentState != null)
{
m_CurrentState.Exit(m_Owner);
}
m_CurrentState = newState;
m_CurrentState.Enter(m_Owner);
m_Owner.OnAfterCurrentStateChanged(this, m_PreviousState, m_CurrentState);
}
}
示例12: TryChangeState
public virtual bool TryChangeState(ITransition transition)
{
if (transition == null)
{
return false;
}
var oldState = this.State;
var newState = this.GetDestinationState(transition);
if (newState == null)
{
return false;
}
FireChanging(newState);
// Exit old State
try
{
State.Exit(transition);
}
catch
{
return false;
}
// Change State
State = newState;
// Enter new State
try
{
State.Enter(transition);
}
catch
{
State = oldState;
return false;
}
FireChanged();
try
{
State.Action(this);
}
catch
{
return false;
}
return true;
}
示例13: TransitionState
private void TransitionState(IState state)
{
mPlanner.Exit();
mPlanner = state;
if (mPlanner.Enter())
agent.data.flags &= ~NavFlag.PlannerFailed;
else
{
agent.data.flags |= NavFlag.PlannerFailed;
Debug.LogError(agent.transform.name + ": Planner transition failed: " + state);
}
}
示例14: EnterAncestors
/// <summary>
/// Calls all <see cref="RHFSM.State.Enter"/> methods on all states from the ancestor to the target state in the correct order.
/// </summary>
/// <param name="targetState">The target state down to which <see cref="RHFSM.State.Enter"/> of all states will be called. This state will be entered, too.</param>
/// <param name="startAncestor">The ancestor that will function as a starting point for the calls downwards through all states.
/// This state will not be entered, since it already should be active.</param>
/// <remarks>This algorithm is recursive. It moves from the <paramref name="targetState"/> up to the <paramref name="startAncestor"/>.
/// When the ancestor is found, it drops all the way back, calling the <see cref="RHFSM.State.Enter"/> method in the correct order.</remarks>
internal void EnterAncestors( IState targetState, IState startAncestor )
{
if ( targetState == null )
{
throw new ArgumentNullException( "targetState", "The given state must not be null." );
}
if ( startAncestor == null )
{
throw new ArgumentNullException( "startAncestor", "The given state must not be null." );
}
if ( startAncestor.Depth > targetState.Depth )
{
throw new InvalidOperationException( "The start ancestor must not be deeper than the target state." );
}
// IF current is nca, Enter() it and return.
if ( targetState == startAncestor )
{
return;
}
IState nextParent = targetState.Parent == null ? targetState : targetState.Parent;
this.EnterAncestors( nextParent, startAncestor );
targetState.Enter();
}
示例15: SetAgentPlanner
/// <summary>
/// Applies a new planner to an existing agent.
/// </summary>
/// <remarks>
/// <para>
/// The manager expects to take ownership of the planner. It also assumes that the planner
/// is inactive but ready to activate.
/// </para>
/// </remarks>
/// <param name="index">The index of the agent.</param>
/// <param name="planner">The new planner. (Must not be null.)</param>
public bool SetAgentPlanner(int index, IState planner)
{
if (planner == null || mPlanners[index] == null)
return false;
mPlanners[index].Exit();
if (planner.Enter())
{
mPlanners[index] = planner;
return true;
}
else
{
RemoveAgent(index);
return false;
}
}