using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "Major Project/Combined Block")]
|
|
[System.Serializable]
|
|
public class CombinedBlock : LogicBlock
|
|
{
|
|
#region Inspector Variables
|
|
[SerializeField]
|
|
[Tooltip("Is this block editable")]
|
|
public bool isEditable = false;
|
|
|
|
[SerializeField]
|
|
[Tooltip("Blocks this will run through")]
|
|
public BlockReader blockReader = new BlockReader();
|
|
#endregion Inspector Variables
|
|
|
|
#region Private Variables
|
|
public override int Size()
|
|
{
|
|
if (!isEditable)
|
|
return 1;
|
|
|
|
int retVal = 1;
|
|
foreach(LogicBlock block in blockReader.LogicChain)
|
|
retVal += block.Size();
|
|
|
|
return retVal;
|
|
}
|
|
#endregion Private Variables
|
|
|
|
|
|
public override bool Run(Character player, float animationTime)
|
|
{
|
|
BlockLogic(player,animationTime);
|
|
|
|
if (blockReader.Finished)
|
|
{
|
|
blockReader.Reset();
|
|
RepeatCount++;
|
|
}
|
|
|
|
return isFinished();
|
|
}
|
|
|
|
protected override void BlockLogic(Character player, float animationTime)
|
|
{
|
|
blockReader.Read(player,animationTime);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns the block that the character will endUp on after they use this logic element
|
|
/// </summary>
|
|
/// <param name="startBlock">block character is on</param>
|
|
/// <param name="layerMask">layers to ignore</param>
|
|
/// <returns>block which character will finish on after performing this function </returns>
|
|
public override Block GetEndBlock(Block startBlock, Transform transform, LayerMask layerMask)
|
|
{
|
|
return blockReader.CurrentBlock.GetEndBlock(startBlock, transform, layerMask);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets the block to be ready to used again
|
|
/// </summary>
|
|
public override void Reset()
|
|
{
|
|
base.Reset();
|
|
blockReader.Reset();
|
|
}
|
|
|
|
public override LogicBlock[] GetAllBlocks()
|
|
{
|
|
if (!isEditable)
|
|
return new LogicBlock[] { this };
|
|
|
|
List<LogicBlock> retVal = new List<LogicBlock>();
|
|
retVal.Add(this);
|
|
|
|
foreach (LogicBlock block in blockReader.LogicChain)
|
|
retVal.AddRange(block.GetAllBlocks());
|
|
|
|
return retVal.ToArray();
|
|
}
|
|
|
|
public override LogicBlock Clone()
|
|
{
|
|
CombinedBlock retVal = base.Clone() as CombinedBlock;
|
|
retVal.blockReader = new BlockReader();
|
|
|
|
foreach (LogicBlock block in blockReader.LogicChain)
|
|
retVal.blockReader.Add(block.Clone());
|
|
|
|
return retVal;
|
|
}
|
|
|
|
#region Serialisation Functions
|
|
public override void CopyToken(BlockToken token)
|
|
{
|
|
base.CopyToken(token);
|
|
|
|
blockReader = new BlockReader();
|
|
|
|
foreach (BlockToken subToken in ((CombinedToken)token).subBlocks)
|
|
blockReader.Add(subToken.ToLogicBlock());
|
|
}
|
|
|
|
public override BlockToken ToToken(BlockToken token = null)
|
|
{
|
|
if (token == null)
|
|
token = new CombinedToken(this);
|
|
|
|
CombinedToken retVal = (CombinedToken)base.ToToken(token);
|
|
retVal.subBlocks = new BlockToken[blockReader.LogicChain.Count];
|
|
|
|
for (int i = 0; i < retVal.subBlocks.Length; i++)
|
|
retVal.subBlocks[i] = blockReader.LogicChain[i].ToToken();
|
|
|
|
return retVal;
|
|
}
|
|
#endregion Serialisation Functions
|
|
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class CombinedToken : BlockToken
|
|
{
|
|
public BlockToken[] subBlocks;
|
|
|
|
public CombinedToken(LogicBlock block) : base(block)
|
|
{
|
|
}
|
|
}
|