PseudoState.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Wayne.Lib.StateEngine.Generic
  5. {
  6. /// <summary>
  7. /// Generic pseudo state class that has a main object of a generic type.
  8. /// </summary>
  9. /// <typeparam name="TMain">Specifies the type of the main object.</typeparam>
  10. /// <typeparam name="TData">Specifies the type of state data the state uses.</typeparam>
  11. public abstract class PseudoState<TMain, TData> : PseudoState<TMain> where TData : StateData
  12. {
  13. #region Fields
  14. private IStateWithData dataCompositeState;
  15. #endregion
  16. #region Properties
  17. /// <summary>
  18. /// Gets the state data for this state.
  19. /// </summary>
  20. protected TData Data
  21. {
  22. get
  23. {
  24. if (dataCompositeState == null)
  25. {
  26. dataCompositeState = StateData.GetParentCompositeStateWithStateData<TData>(this);
  27. }
  28. return dataCompositeState.StateData as TData;
  29. }
  30. }
  31. #endregion
  32. }
  33. }