static public void RegisterState(ELifeState state, Type type) { if (null == m_StateFactory) { m_StateFactory = new Dictionary<ELifeState, Type>(); } m_StateFactory.Add(state, type); }
static public void RegisterState(ELifeState state, Type type) { if (null == m_StateFactory) { m_StateFactory = new Dictionary <ELifeState, Type>(); } m_StateFactory.Add(state, type); }
private void OnTriggerChangeState(MessageObject obj) { if (!(obj.msgValue is ELifeState)) { return; } ELifeState newState = (ELifeState)(obj.msgValue); TryEnterState(newState, false); }
void SetLifeState() { if (isAlive) { LifeState = ELifeState.ALIVE; } else { LifeState = ELifeState.DEAD; } }
void SetLifeState() { if (m_AIHealth.m_IsAlive) { LifeState = ELifeState.ALIVE; } else { LifeState = ELifeState.DEAD; } }
private static IState CreateStateInstance(ELifeState stateId, Ilife unit) { if (null == m_StateFactory) { StateDefine.RegisterState(); } IState result = null; Type type = null; if (m_StateFactory.TryGetValue(stateId, out type)) { result = Activator.CreateInstance(type, unit, stateId) as IState; } return(result); }
private IState StateFactory(ELifeState stateId) { IState result = null; if (null != m_StateUsingStore && m_StateUsingStore.TryGetValue(stateId, out result)) { return(result); } result = CreateStateInstance(stateId, m_lifeInstance); if (null == m_StateUsingStore) { m_StateUsingStore = new Dictionary <ELifeState, IState>(); } m_StateUsingStore.Add(stateId, result); return(result); }
public List <StateConflictConfigElement> GetStateConflicList(int uid, ELifeState state) { //get table StateConflictTable config = TryGetConfig <StateConflictTable>(ConfigPath_StateConflictConfig); if (null != config) { //match uid to sate conflict table StateConflictConfig res = null; if (config.StateConflictConfigMap.TryGetValue(uid, out res)) { //get state List <StateConflictConfigElement> result = null; if (res.StateConflictMap.TryGetValue((int)(state), out result)) { return(result); } } } return(null); }
public IState(Ilife unit, ELifeState state) { this.unit = unit; this.state = state; }
public bool TryEnterState(ELifeState newStateID, bool force,object param = null) { if (null != m_CurrentState && m_CurrentState.GetState() == newStateID) { //do nothing return true; } IState newState = StateFactory(newStateID); if (null == newState) { return false; } if (null == m_CurrentState) { if (!newState.CanEnter()) { return false; } //reset state m_CurrentState = newState; m_CurrentState.DoEnter(param); return true; } if (!force ) { List<StateConflictConfigElement> stateClash = null; /*if (m_CurrentCharStateConflictMap.StateConflictMap.TryGetValue((int)(m_CurrentState.GetState()), out stateClash)) { foreach (StateConflictConfigElement s in stateClash) { //与当前状态冲突 if (s.StateId == (int)newStateID) { if (s.IsConflict) { Debuger.LogWarning(string.Format("current state:{0} can't enter new state:{1}", m_CurrentState.GetState(), newStateID)); return false; } else { break; } } } }*/ if (!m_CurrentState.CanExit()) { return false; } if (!newState.CanEnter()) { return false; } } m_CurrentState.DoExit(); //reset state m_CurrentState = newState; m_CurrentState.DoEnter(param); return true; }
private static IState CreateStateInstance(ELifeState stateId, Ilife unit) { if (null == m_StateFactory) { StateDefine.RegisterState(); } IState result = null; Type type = null; if (m_StateFactory.TryGetValue(stateId, out type)) { result = Activator.CreateInstance(type, unit,stateId) as IState; } return result; }
private IState StateFactory(ELifeState stateId) { IState result = null; if (null != m_StateUsingStore && m_StateUsingStore.TryGetValue(stateId, out result)) { return result; } result = CreateStateInstance(stateId, m_lifeInstance); if (null == m_StateUsingStore) { m_StateUsingStore = new Dictionary<ELifeState, IState>(); } m_StateUsingStore.Add(stateId, result); return result; }
public IState(Ilife unit,ELifeState state) { this.unit = unit; this.state = state; }
public StateRun(Ilife unit, ELifeState state) : base(unit, state) { }
public bool TryEnterState(ELifeState newStateID, bool force, object param = null) { if (null != m_CurrentState && m_CurrentState.GetState() == newStateID) { //do nothing return(true); } IState newState = StateFactory(newStateID); if (null == newState) { return(false); } if (null == m_CurrentState) { if (!newState.CanEnter()) { return(false); } //reset state m_CurrentState = newState; m_CurrentState.DoEnter(param); return(true); } if (!force) { List <StateConflictConfigElement> stateClash = null; /*if (m_CurrentCharStateConflictMap.StateConflictMap.TryGetValue((int)(m_CurrentState.GetState()), out stateClash)) * { * foreach (StateConflictConfigElement s in stateClash) * { * //与当前状态冲突 * if (s.StateId == (int)newStateID) * { * if (s.IsConflict) * { * Debuger.LogWarning(string.Format("current state:{0} can't enter new state:{1}", * m_CurrentState.GetState(), newStateID)); * return false; * } * else * { * break; * } * } * } * }*/ if (!m_CurrentState.CanExit()) { return(false); } if (!newState.CanEnter()) { return(false); } } m_CurrentState.DoExit(); //reset state m_CurrentState = newState; m_CurrentState.DoEnter(param); return(true); }
public StateMove(Ilife unit, ELifeState state) : base(unit, state) { }
public StateIdle(Ilife unit, ELifeState state) : base(unit, state) { }