Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.

90 linhas
2.4KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Runs one random action from the given list.
  8. /// </summary>
  9. class ActionRandom : ActionInterval
  10. {
  11. protected ActionInstant[] actions;
  12. protected int index;
  13. public ActionRandom(ActionInstant action1, ActionInstant action2)
  14. : base(0)
  15. {
  16. actions = new ActionInstant[] { action1, action2 };
  17. }
  18. public ActionRandom(ActionInstant[] actionsList)
  19. : base(0)
  20. {
  21. actions = actionsList;
  22. }
  23. /// <summary>
  24. /// Returns a copy of the action.
  25. /// </summary>
  26. public override ActionInstant clone()
  27. {
  28. ActionInstant[] aList = new ActionInstant[actions.Length];
  29. for (int i = 0; i < actions.Length; i++)
  30. {
  31. aList[i] = actions[i].clone();
  32. }
  33. return new ActionRandom(aList);
  34. }
  35. /// <summary>
  36. /// Returns the reversed version of the action, if it is possible.
  37. /// </summary>
  38. public override ActionInstant reverse()
  39. {
  40. ActionInstant[] aList = new ActionInstant[actions.Length];
  41. for (int i = 0; i < actions.Length; i++)
  42. {
  43. aList[i] = actions[i].reverse();
  44. }
  45. return new ActionRandom(aList);
  46. }
  47. /// <summary>
  48. /// This method is called at the action start.
  49. /// </summary>
  50. public override void start()
  51. {
  52. base.start();
  53. index = UnityEngine.Random.Range(0, actions.Length);
  54. actions[index].setActor(target);
  55. actions[index].start();
  56. }
  57. /// <summary>
  58. /// This method is called every frame update.
  59. /// </summary>
  60. public override void step(float dt)
  61. {
  62. dt *= timeScale;
  63. if (actions[index].running)
  64. actions[index].step(dt);
  65. if (!actions[index].running)
  66. {
  67. stop();
  68. dtr = actions[index].dtr;
  69. }
  70. }
  71. /// <summary>
  72. /// This method is called after the interval action is stopped.
  73. /// </summary>
  74. public override void stop()
  75. {
  76. base.stop();
  77. actions[index].stop();
  78. }
  79. }
  80. }