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.

68 lines
2.0 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// Class which reads a a list of logic blocks and applies to a character
  6. /// </summary>
  7. [System.Serializable]
  8. public class BlockReader
  9. {
  10. #region Inspector Variables
  11. [SerializeField]
  12. [Tooltip("List of LogicBlocks which will affected this character")]
  13. protected List<LogicBlock> LogicChain;
  14. #endregion Inspector Variables
  15. #region Read-only Variables
  16. /// <summary>
  17. /// returns true if all LogicBlocks in LogicChain have been completed
  18. /// </summary>
  19. public bool Finished { get { return currentBlockIndex >= LogicChain.Count; } }
  20. #endregion Read-only Variables
  21. #region Private Variables
  22. private int currentBlockIndex;//Block currently on
  23. #endregion Private Variables
  24. #region Class Implementation
  25. /// <summary>
  26. /// Resets Block reader;
  27. /// </summary>
  28. public void Reset()
  29. {
  30. currentBlockIndex = 0;
  31. }
  32. /// <summary>
  33. /// Reads the current block in the logic chain
  34. /// </summary>
  35. /// <param name="character">Character to control</param>
  36. /// <returns>Returns false if other readers should wait for this one to run again</returns>
  37. public bool Read(Character character)
  38. {
  39. //return that this is done if no more blocks left in chain
  40. if (LogicChain.Count <= currentBlockIndex)
  41. return true;
  42. //get current Block
  43. LogicBlock currentBlock = LogicChain[currentBlockIndex];
  44. //apply blocks to character
  45. currentBlock.Run(character);
  46. //if the block is finished reset it and move on to next one
  47. //(it might not be finished if it is a for loop or something)
  48. if (currentBlock.isFinished())
  49. {
  50. currentBlock.Reset();
  51. currentBlockIndex++;
  52. }
  53. //Should other readers wait for this one
  54. return (currentBlock.isFinished() || !currentBlock.WaitUntilFinished);
  55. }
  56. #endregion
  57. }