1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System.Collections;
- using System.Collections.Generic;
- namespace Wayne.Lib.StateEngine
- {
-
-
-
-
- public class StateFactories
- {
- #region Fields
- private List<IStateFactory> factoryList = new List<IStateFactory>();
- #endregion
- #region Construction
-
-
-
- public StateFactories()
- {
- }
- #endregion
- #region Public Methods
-
-
-
- public void Clear()
- {
- factoryList.Clear();
- }
-
-
-
-
-
-
- public void AddFactory(IStateFactory stateFactory)
- {
- if ((stateFactory != null) && !factoryList.Contains(stateFactory))
- factoryList.Add(stateFactory);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- public State CreateState(string stateFactoryName, StateTypeContainer stateTypeContainer)
- {
- State foundState = null;
-
- foreach (IStateFactory factory in factoryList)
- {
- IStateFactory2 stateFactory2 = factory as IStateFactory2;
- State state;
- if (stateFactory2 != null)
- state = stateFactory2.CreateState(stateFactoryName, stateTypeContainer);
- else
- state = factory.CreateState(stateFactoryName);
- if (state != null)
- {
- foundState = state;
- break;
- }
- }
- CompositeState compositeState = foundState as CompositeState;
- if (compositeState != null)
- {
- compositeState.StateMachine.stateFactories = this;
- compositeState.StateMachine.SetAndMergeTypeContainer(stateTypeContainer);
- }
- return foundState;
- }
- #endregion
- }
- }
|