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.

62 lines
1.5 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// Base class all logic blocks are derived from
  6. /// </summary>
  7. [System.Serializable]
  8. public abstract class LogicBlock : ScriptableObject
  9. {
  10. #region Inspector Fields
  11. [SerializeField]
  12. [Header("Base Settings")]
  13. [Tooltip("Wait until this block is resolved before moving to next")]
  14. protected bool WaitUntilFinished = false;
  15. [SerializeField]
  16. [Tooltip("Amount of times to run this Block before moving to next")]
  17. protected int RepeatAmount = 1;
  18. #endregion Inspector Fields
  19. #region private variables
  20. /// <summary>
  21. /// Amount of times this block has run
  22. /// </summary>
  23. protected int RepeatCount = 0;
  24. #endregion private variables
  25. #region Class Functions
  26. /// <summary>
  27. /// Runs the block
  28. /// </summary>
  29. /// <returns>returns true if block is finished</returns>
  30. public virtual bool Run()
  31. {
  32. RepeatCount++;
  33. BlockLogic();
  34. return (RepeatCount == RepeatAmount);
  35. }
  36. /// <summary>
  37. /// Returns the amount of space this logic block takes up
  38. /// </summary>
  39. /// <returns>Int which controlls how much space this takes up</returns>
  40. public virtual int Size()
  41. {
  42. return 1;
  43. }
  44. /// <summary>
  45. /// Where derived callses should implement the logic for their classes
  46. /// </summary>
  47. /// <returns>returns true if block is finished</returns>
  48. protected abstract void BlockLogic();
  49. #endregion Class Functions
  50. }