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.

ActionPlayer.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Plays the action on another actor;
  8. /// </summary>
  9. class ActionPlayer : ActionInterval
  10. {
  11. protected ActionInstant action;
  12. protected Actor actor;
  13. public ActionPlayer(ActionInstant targetAction, Actor targetActor)
  14. : base(0)
  15. {
  16. action = targetAction;
  17. actor = targetActor;
  18. }
  19. public override ActionInstant Clone()
  20. {
  21. return new ActionPlayer(action, actor);
  22. }
  23. public override void Start()
  24. {
  25. base.Start();
  26. actor.AttachAction(action);
  27. if (!action.running)
  28. running = false;
  29. }
  30. public override void StepTimer(float dt)
  31. {
  32. if (target == null)
  33. throw new Exception("Can update the action only after it's atached to the actor");
  34. action.StepTimer(dt);
  35. if (!action.running)
  36. {
  37. dtr = action.dtr;
  38. Stop();
  39. }
  40. }
  41. public override void Step(float dt)
  42. {
  43. if (!action.running)
  44. running = false;
  45. }
  46. }
  47. }