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.

92 lines
2.4KB

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