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.

60 lines
1.2KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using coa4u;
  5. [System.Serializable]
  6. public class SeqActor : Actor
  7. {
  8. protected State[] states;
  9. protected int index;
  10. protected List<int> stateLog = new List<int>();
  11. protected ActionInstant currentStateAction;
  12. public void SetState(int idx)
  13. {
  14. if (idx < states.Length)
  15. {
  16. stateLog.Add(idx);
  17. index = idx;
  18. if (currentStateAction != null)
  19. RemoveAction(currentStateAction);
  20. currentStateAction = states[idx].action;
  21. AttachAction(currentStateAction);
  22. }
  23. else
  24. {
  25. throw new Exception("Actor doesn't have the state " + idx.ToString());
  26. }
  27. }
  28. public void SetState(string name)
  29. {
  30. SetState(Array.FindIndex<State>(states, x => x.name == name));
  31. }
  32. public int currentStateIndex
  33. {
  34. get
  35. {
  36. return index;
  37. }
  38. }
  39. public string currentStateName
  40. {
  41. get
  42. {
  43. return states[index].name;
  44. }
  45. }
  46. public List<int> log
  47. {
  48. get
  49. {
  50. return stateLog;
  51. }
  52. }
  53. }