ControllerAction.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using FairyGUI.Utils;
  3. namespace FairyGUI
  4. {
  5. public class ControllerAction
  6. {
  7. public enum ActionType
  8. {
  9. PlayTransition,
  10. ChangePage
  11. }
  12. public string[] fromPage;
  13. public string[] toPage;
  14. public static ControllerAction CreateAction(ActionType type)
  15. {
  16. switch (type)
  17. {
  18. case ActionType.PlayTransition:
  19. return new PlayTransitionAction();
  20. case ActionType.ChangePage:
  21. return new ChangePageAction();
  22. }
  23. return null;
  24. }
  25. public ControllerAction()
  26. {
  27. }
  28. public void Run(Controller controller, string prevPage, string curPage)
  29. {
  30. if ((fromPage == null || fromPage.Length == 0 || Array.IndexOf(fromPage, prevPage) != -1)
  31. && (toPage == null || toPage.Length == 0 || Array.IndexOf(toPage, curPage) != -1))
  32. Enter(controller);
  33. else
  34. Leave(controller);
  35. }
  36. virtual protected void Enter(Controller controller)
  37. {
  38. }
  39. virtual protected void Leave(Controller controller)
  40. {
  41. }
  42. virtual public void Setup(ByteBuffer buffer)
  43. {
  44. int cnt;
  45. cnt = buffer.ReadShort();
  46. fromPage = new string[cnt];
  47. for (int i = 0; i < cnt; i++)
  48. fromPage[i] = buffer.ReadS();
  49. cnt = buffer.ReadShort();
  50. toPage = new string[cnt];
  51. for (int i = 0; i < cnt; i++)
  52. toPage[i] = buffer.ReadS();
  53. }
  54. }
  55. }