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.

81 lines
1.9 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [CreateAssetMenu(menuName = "Major Project/Combined Block")]
  5. [System.Serializable]
  6. public class CombinedBlock : LogicBlock
  7. {
  8. #region Inspector Variables
  9. [SerializeField]
  10. [Tooltip("Blocks this will run through")]
  11. protected BlockReader blockReader;
  12. #endregion Inspector Variables
  13. #region Private Variables
  14. #endregion Private Variables
  15. public override bool Run(Character player, float animationTime)
  16. {
  17. BlockLogic(player,animationTime);
  18. if (blockReader.Finished)
  19. {
  20. blockReader.Reset();
  21. RepeatCount++;
  22. }
  23. return isFinished();
  24. }
  25. protected override void BlockLogic(Character player, float animationTime)
  26. {
  27. blockReader.Read(player,animationTime);
  28. }
  29. /// <summary>
  30. /// Resets the block to be ready to used again
  31. /// </summary>
  32. public override void Reset()
  33. {
  34. base.Reset();
  35. blockReader.Reset();
  36. }
  37. public override void CopyToken(BlockToken token)
  38. {
  39. base.CopyToken(token);
  40. blockReader = new BlockReader();
  41. foreach (BlockToken subToken in ((CombinedToken)token).subBlocks)
  42. blockReader.Add(subToken.ToLogicBlock());
  43. }
  44. public override BlockToken ToToken(BlockToken token = null)
  45. {
  46. if (token == null)
  47. token = new CombinedToken(this);
  48. CombinedToken retVal = (CombinedToken)base.ToToken(token);
  49. retVal.subBlocks = new BlockToken[blockReader.LogicChain.Count];
  50. for (int i = 0; i < retVal.subBlocks.Length; i++)
  51. retVal.subBlocks[i] = blockReader.LogicChain[i].ToToken();
  52. return retVal;
  53. }
  54. }
  55. [System.Serializable]
  56. public class CombinedToken : BlockToken
  57. {
  58. public BlockToken[] subBlocks;
  59. public CombinedToken(LogicBlock block) : base(block)
  60. {
  61. }
  62. }