public void Start(IHierarchicalState oState) { if (m_bTerminated) { Debugger.LogError("[HStateController] has been terminated"); return; } if (m_bStarted) { Debugger.LogError("[HStateController] has been started"); return; } Debugger.Log("[HStateController] Start: " + oState.ToString()); m_bStarted = true; m_oCurrentState.Add(oState); m_oCurrentState[0].SetProperty(this, 0); }
public void TransTo(int iLevel, IHierarchicalState oState) { if (m_bTerminated) { Debugger.LogError("[StateController] has been terminated"); return; } if (!m_bStarted) { Debugger.LogError("[StateController] need to be started first"); return; } if (iLevel > m_oCurrentState.Count) { Debugger.LogError("[StateController] Level is too big"); return; } Debugger.Log(string.Format("[StateController] Level {0:} transTo: {1:}", iLevel, oState.ToString())); if (iLevel == m_oCurrentState.Count) { m_oCurrentState.Add(oState); m_oCurrentState [iLevel].SetProperty(this, iLevel); } else { for (int i = m_oCurrentState.Count - 1; i >= iLevel; i--) { m_oCurrentState [i].StateEnd(); m_oCurrentState.RemoveAt(i); } m_oCurrentState.Add(oState); m_oCurrentState [iLevel].SetProperty(this, iLevel); } }