You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

ActionSequence.cs 2.6KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Runs several actions in a sequence.
  8. /// </summary>
  9. class ActionSequence : ActionInterval
  10. {
  11. protected ActionInstant[] actions;
  12. protected int index;
  13. public ActionSequence(ActionInstant action1, ActionInstant action2)
  14. : base(0)
  15. {
  16. actions = new ActionInstant[] { action1, action2 };
  17. }
  18. public ActionSequence(ActionInstant[] actionsList)
  19. : base(0)
  20. {
  21. actions = actionsList;
  22. }
  23. public override ActionInstant Clone()
  24. {
  25. ActionInstant[] aList = new ActionInstant[actions.Length];
  26. for (int i = 0; i < actions.Length; i++)
  27. {
  28. aList[i] = actions[i].Clone();
  29. }
  30. return new ActionSequence(aList);
  31. }
  32. public override ActionInstant Reverse()
  33. {
  34. ActionInstant[] aList = new ActionInstant[actions.Length];
  35. for (int i = 0; i < actions.Length; i++)
  36. {
  37. aList[actions.Length - 1 - i] = actions[i].Reverse();
  38. }
  39. return new ActionSequence(aList);
  40. }
  41. public override void Start()
  42. {
  43. base.Start();
  44. index = 0;
  45. actions[0].SetActor(target);
  46. actions[0].Start();
  47. while (!actions[index].running && index < actions.Length - 1)
  48. {
  49. index += 1;
  50. actions[index].SetActor(target);
  51. actions[index].Start();
  52. }
  53. }
  54. public override void StepTimer(float dt)
  55. {
  56. dt *= timeScale;
  57. float dtrdata = 0;
  58. if (actions[index].running)
  59. {
  60. actions[index].StepTimer(dt);
  61. if (!actions[index].running)
  62. dtrdata = actions[index].dtr;
  63. }
  64. while (!actions[index].running && index < actions.Length - 1)
  65. {
  66. index += 1;
  67. actions[index].SetActor(target);
  68. actions[index].Start();
  69. if (actions[index].running && dtrdata > 0)
  70. actions[index].StepTimer(dtrdata);
  71. }
  72. if (!actions[index].running)
  73. {
  74. Stop();
  75. dtr = dtrdata;
  76. }
  77. }
  78. public override void Stop()
  79. {
  80. base.Stop();
  81. if (actions[index].running)
  82. actions[index].Stop();
  83. }
  84. }
  85. }