diff --git a/Assets/Fungus/Flowchart/Scripts/Block.cs b/Assets/Fungus/Flowchart/Scripts/Block.cs
index 8d3f8fb3..32fe99c9 100644
--- a/Assets/Fungus/Flowchart/Scripts/Block.cs
+++ b/Assets/Fungus/Flowchart/Scripts/Block.cs
@@ -15,73 +15,34 @@ namespace Fungus
[ExecuteInEditMode]
[RequireComponent(typeof(Flowchart))]
[AddComponentMenu("")]
- public class Block : Node
+ public class Block : Node, IBlock
{
- public enum ExecutionState
- {
- Idle,
- Executing,
- }
-
- ///
- /// The execution state of the Block.
- ///
- protected ExecutionState executionState;
- public virtual ExecutionState State { get { return executionState; } }
-
- ///
- /// Unique identifier for the Block.
- ///
[SerializeField] protected int itemId = -1; // Invalid flowchart item id
- public virtual int ItemId { get { return itemId; } set { itemId = value; } }
- ///
- /// The name of the block node as displayed in the Flowchart window.
- ///
[FormerlySerializedAs("sequenceName")]
[Tooltip("The name of the block node as displayed in the Flowchart window")]
[SerializeField] protected string blockName = "New Block";
- public virtual string BlockName { get { return blockName; } set { blockName = value; } }
- ///
- /// Description text to display under the block node
- ///
[TextArea(2, 5)]
[Tooltip("Description text to display under the block node")]
[SerializeField] protected string description = "";
- public virtual string Description { get { return description; } }
- ///
- /// An optional Event Handler which can execute the block when an event occurs.
- ///
[Tooltip("An optional Event Handler which can execute the block when an event occurs")]
[SerializeField] protected EventHandler eventHandler;
- public virtual EventHandler _EventHandler { get { return eventHandler; } set { eventHandler = value; } }
- ///
- /// The currently executing command.
- ///
+ [SerializeField] protected List commandList = new List();
+
+ protected ExecutionState executionState;
+
protected Command activeCommand;
- public virtual Command ActiveCommand { get { return activeCommand; } }
///
// Index of last command executed before the current one.
// -1 indicates no previous command.
///
protected int previousActiveCommandIndex = -1;
- public virtual float ExecutingIconTimer { get; set; }
- ///
- /// The list of commands in the sequence.
- ///
- [SerializeField] protected List commandList = new List();
- public virtual List CommandList { get { return commandList; } }
-
- ///
- /// Controls the next command to execute in the block execution coroutine.
- ///
protected int jumpToCommandIndex = -1;
- public int JumpToCommandIndex { set { jumpToCommandIndex = value; } }
///
/// Duration of fade for executing icon displayed beside blocks & commands.
@@ -128,7 +89,7 @@ namespace Fungus
// The user can modify the command list order while playing in the editor,
// so we keep the command indices updated every frame. There's no need to
// do this in player builds so we compile this bit out for those builds.
- void Update()
+ protected virtual void Update()
{
int index = 0;
foreach (Command command in commandList)
@@ -143,6 +104,53 @@ namespace Fungus
}
#endif
+ #region IBlock implementation
+
+ ///
+ /// The execution state of the Block.
+ ///
+ public virtual ExecutionState State { get { return executionState; } }
+
+ ///
+ /// Unique identifier for the Block.
+ ///
+ public virtual int ItemId { get { return itemId; } set { itemId = value; } }
+
+ ///
+ /// The name of the block node as displayed in the Flowchart window.
+ ///
+ public virtual string BlockName { get { return blockName; } set { blockName = value; } }
+
+ ///
+ /// Description text to display under the block node
+ ///
+ public virtual string Description { get { return description; } }
+
+ ///
+ /// An optional Event Handler which can execute the block when an event occurs.
+ ///
+ public virtual EventHandler _EventHandler { get { return eventHandler; } set { eventHandler = value; } }
+
+ ///
+ /// The currently executing command.
+ ///
+ public virtual Command ActiveCommand { get { return activeCommand; } }
+
+ ///
+ /// Timer for fading Block execution icon.
+ ///
+ public virtual float ExecutingIconTimer { get; set; }
+
+ ///
+ /// The list of commands in the sequence.
+ ///
+ public virtual List CommandList { get { return commandList; } }
+
+ ///
+ /// Controls the next command to execute in the block execution coroutine.
+ ///
+ public virtual int JumpToCommandIndex { set { jumpToCommandIndex = value; } }
+
///
/// Returns the parent Flowchart for this Block.
///
@@ -221,7 +229,7 @@ namespace Fungus
// Skip disabled commands, comments and labels
while (i < commandList.Count &&
- (!commandList[i].enabled ||
+ (!commandList[i].enabled ||
commandList[i].GetType() == typeof(Comment) ||
commandList[i].GetType() == typeof(Label)))
{
@@ -364,5 +372,7 @@ namespace Fungus
}
}
}
+
+ #endregion
}
}
diff --git a/Assets/Fungus/Flowchart/Scripts/IBlock.cs b/Assets/Fungus/Flowchart/Scripts/IBlock.cs
new file mode 100644
index 00000000..c8e02abe
--- /dev/null
+++ b/Assets/Fungus/Flowchart/Scripts/IBlock.cs
@@ -0,0 +1,114 @@
+using UnityEngine;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Fungus
+{
+ ///
+ /// Execution state of a Block.
+ ///
+ public enum ExecutionState
+ {
+ Idle,
+ Executing,
+ }
+
+ ///
+ /// A container for a sequence of Fungus comands.
+ ///
+ public interface IBlock
+ {
+ ///
+ /// The execution state of the Block.
+ ///
+ ExecutionState State { get; }
+
+ ///
+ /// Unique identifier for the Block.
+ ///
+ int ItemId { get; set; }
+
+ ///
+ /// The name of the block node as displayed in the Flowchart window.
+ ///
+ string BlockName { get; set; }
+
+ ///
+ /// Description text to display under the block node
+ ///
+ string Description { get; }
+
+ ///
+ /// An optional Event Handler which can execute the block when an event occurs.
+ ///
+ EventHandler _EventHandler { get; set; }
+
+ ///
+ /// The currently executing command.
+ ///
+ Command ActiveCommand { get; }
+
+ ///
+ /// Timer for fading Block execution icon.
+ ///
+ float ExecutingIconTimer { get; set; }
+
+ ///
+ /// The list of commands in the sequence.
+ ///
+ List CommandList { get; }
+
+ ///
+ /// Controls the next command to execute in the block execution coroutine.
+ ///
+ int JumpToCommandIndex { set; }
+
+ ///
+ /// Returns the parent Flowchart for this Block.
+ ///
+ Flowchart GetFlowchart();
+
+ ///
+ /// Returns true if the Block is executing a command.
+ ///
+ bool IsExecuting();
+
+ ///
+ /// Returns the number of times this Block has executed.
+ ///
+ int GetExecutionCount();
+
+ ///
+ /// Start a coroutine which executes all commands in the Block. Only one running instance of each Block is permitted.
+ ///
+ void StartExecution();
+
+ ///
+ /// A coroutine method that executes all commands in the Block. Only one running instance of each Block is permitted.
+ ///
+ /// Index of command to start execution at
+ /// Delegate function to call when execution completes
+ IEnumerator Execute(int commandIndex = 0, System.Action onComplete = null);
+
+ ///
+ /// Stop executing commands in this Block.
+ ///
+ void Stop();
+
+ ///
+ /// Returns a list of all Blocks connected to this one.
+ ///
+ List GetConnectedBlocks();
+
+ ///
+ /// Returns the type of the previously executing command.
+ ///
+ /// The previous active command type.
+ System.Type GetPreviousActiveCommandType();
+
+ ///
+ /// Recalculate the indent levels for all commands in the list.
+ ///
+ void UpdateIndentLevels();
+ }
+}
\ No newline at end of file
diff --git a/Assets/Fungus/Flowchart/Scripts/IBlock.cs.meta b/Assets/Fungus/Flowchart/Scripts/IBlock.cs.meta
new file mode 100644
index 00000000..a0965ceb
--- /dev/null
+++ b/Assets/Fungus/Flowchart/Scripts/IBlock.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 3a23dd66c807e4fab86a64184c3faa9a
+timeCreated: 1473856388
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: