Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
To repozytorium jest zarchiwizowane. Możesz wyświetlać pliki i je sklonować, ale nie możesz do niego przepychać zmian lub otwierać zgłoszeń/Pull Requestów.

78 wiersze
2.2KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Creates the and starts the given action instance at Start. If you're using calcers for parameters, they will be also calculated at start.
  8. /// </summary>
  9. class ActionHolder<T> : ActionInstant
  10. where T : ActionInstant
  11. {
  12. protected T action;
  13. protected object[] args;
  14. public ActionHolder(params object[] args) : base()
  15. {
  16. this.args = args;
  17. }
  18. public override void Start()
  19. {
  20. if (target == null)
  21. throw new Exception("Can start the action only after it's atached to the actor");
  22. object[] nargs = new object[args.Length];
  23. for (int i = 0; i < args.Length; i++)
  24. {
  25. if (args[i] is CalcerFloat)
  26. {
  27. nargs[i] = ((CalcerFloat)args[i]).value;
  28. }
  29. else if (args[i] is CalcerVector)
  30. {
  31. nargs[i] = ((CalcerVector)args[i]).value;
  32. }
  33. else
  34. {
  35. nargs[i] = args[i];
  36. }
  37. }
  38. action = (T)Activator.CreateInstance(typeof(T), nargs);
  39. action.SetActor(target);
  40. action.locks = locks;
  41. action.Start();
  42. duration = action.duration;
  43. if (action.running)
  44. running = true;
  45. }
  46. public override void StepTimer(float dt)
  47. {
  48. if (target == null)
  49. throw new Exception("Can update the action only after it's atached to the actor");
  50. action.StepTimer(dt);
  51. if (!action.running)
  52. {
  53. dtr = action.dtr;
  54. Stop();
  55. }
  56. }
  57. public override void Stop()
  58. {
  59. if (target == null)
  60. throw new Exception("Can stop the action only after it's atached to the actor");
  61. if (action.running)
  62. action.Stop();
  63. running = false;
  64. }
  65. public override ActionInstant Clone()
  66. {
  67. return new ActionHolder<T>(args);
  68. }
  69. }
  70. }