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.

129 lines
3.6 KiB

4 years ago
4 years ago
  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("Is this block editable")]
  11. //public bool isEditable = false;
  12. [SerializeField]
  13. [Tooltip("Blocks this will run through")]
  14. public BlockReader blockReader = new BlockReader();
  15. #endregion Inspector Variables
  16. #region ReadOnly Variables
  17. public override bool WaitUntilFinished { get { if (blockReader != null && blockReader.CurrentBlock != null) return (blockReader.CurrentBlock.WaitUntilFinished || base.WaitUntilFinished); else return base.WaitUntilFinished; } }
  18. #endregion
  19. #region Private Variables
  20. #endregion Private Variables
  21. public override IEnumerator Run(Character player, float animationTime, bool useBlockDirection = false)
  22. {
  23. BlockLogic(player,animationTime);
  24. if (WaitUntilFinished)
  25. {
  26. for (int i = 0; i < blockReader.Length; i++)
  27. {
  28. yield return player.StartCoroutine(blockReader.Read(player, animationTime / SpeedMultiplier));
  29. }
  30. }
  31. else
  32. {
  33. yield return player.StartCoroutine(blockReader.Read(player, animationTime / SpeedMultiplier));
  34. }
  35. if (blockReader.Finished)
  36. {
  37. blockReader.Reset();
  38. RepeatCount++;
  39. }
  40. }
  41. protected override IEnumerator BlockLogic(Character player, float animationTime, bool useBlockDirection = false)
  42. {
  43. yield break;
  44. }
  45. /// <summary>
  46. /// Returns the block that the character will endUp on after they use this logic element
  47. /// </summary>
  48. /// <param name="startBlock">block character is on</param>
  49. /// <param name="layerMask">layers to ignore</param>
  50. /// <returns>block which character will finish on after performing this function </returns>
  51. public override Block GetEndBlock(Block startBlock, Transform transform, LayerMask layerMask)
  52. {
  53. return blockReader.CurrentBlock.GetEndBlock(startBlock, transform, layerMask);
  54. }
  55. /// <summary>
  56. /// Resets the block to be ready to used again
  57. /// </summary>
  58. public override void Reset()
  59. {
  60. base.Reset();
  61. blockReader.Reset();
  62. }
  63. public override LogicBlock Clone()
  64. {
  65. CombinedBlock retVal = base.Clone() as CombinedBlock;
  66. retVal.blockReader = new BlockReader();
  67. foreach (LogicBlock block in blockReader.LogicChain)
  68. retVal.blockReader.Add(block.Clone());
  69. return retVal;
  70. }
  71. #region Serialisation Functions
  72. public override void CopyToken(BlockToken token)
  73. {
  74. base.CopyToken(token);
  75. blockReader = new BlockReader();
  76. foreach (BlockToken subToken in ((CombinedToken)token).subBlocks)
  77. blockReader.Add(subToken.ToLogicBlock());
  78. }
  79. public override BlockToken ToToken(BlockToken token = null)
  80. {
  81. if (token == null)
  82. token = new CombinedToken(this);
  83. CombinedToken retVal = (CombinedToken)base.ToToken(token);
  84. retVal.subBlocks = new BlockToken[blockReader.LogicChain.Count];
  85. for (int i = 0; i < retVal.subBlocks.Length; i++)
  86. retVal.subBlocks[i] = blockReader.LogicChain[i].ToToken();
  87. return retVal;
  88. }
  89. #endregion Serialisation Functions
  90. }
  91. [System.Serializable]
  92. public class CombinedToken : BlockToken
  93. {
  94. public BlockToken[] subBlocks;
  95. public CombinedToken(LogicBlock block) : base(block)
  96. {
  97. }
  98. }