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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class which reads a a list of logic blocks and applies to a character
/// </summary>
[System.Serializable]
public class BlockReader
{
#region Inspector Variables
[SerializeField]
[Tooltip("List of LogicBlocks which will affected this character")]
protected List<LogicBlock> LogicChain;
#endregion Inspector Variables
#region Read-only Variables
/// <summary>
/// returns true if all LogicBlocks in LogicChain have been completed
/// </summary>
public bool Finished { get { return currentBlockIndex >= LogicChain.Count; } }
#endregion Read-only Variables
#region Private Variables
private int currentBlockIndex;//Block currently on
#endregion Private Variables
#region Class Implementation
/// <summary>
/// Resets Block reader;
/// </summary>
public void Reset()
{
currentBlockIndex = 0;
}
/// <summary>
/// Reads the current block in the logic chain
/// </summary>
/// <param name="character">Character to control</param>
/// <returns>Returns false if other readers should wait for this one to run again</returns>
public bool Read(Character character)
{
//return that this is done if no more blocks left in chain
if (LogicChain.Count <= currentBlockIndex)
return true;
//get current Block
LogicBlock currentBlock = LogicChain[currentBlockIndex];
//apply blocks to character
currentBlock.Run(character);
//if the block is finished reset it and move on to next one
//(it might not be finished if it is a for loop or something)
if (currentBlock.isFinished())
{
currentBlock.Reset();
currentBlockIndex++;
}
//Should other readers wait for this one
return (currentBlock.isFinished() || !currentBlock.WaitUntilFinished);
}
#endregion
}