From cdeab7b3a4aebc66e18290bb81ae0e76475fda44 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 16 Sep 2016 12:08:04 +0100 Subject: [PATCH] Refactored Flowchart to use IFlowchart interface --- Assets/Fungus/Flowchart/Scripts/Block.cs | 2 +- Assets/Fungus/Flowchart/Scripts/Flowchart.cs | 426 ++++++------------ Assets/Fungus/Flowchart/Scripts/IFlowchart.cs | 289 ++++++++++++ .../Flowchart/Scripts/IFlowchart.cs.meta | 12 + .../Fungus/Flowchart/Scripts/IUpdateable.cs | 15 + .../Flowchart/Scripts/IUpdateable.cs.meta | 12 + 6 files changed, 463 insertions(+), 293 deletions(-) create mode 100644 Assets/Fungus/Flowchart/Scripts/IFlowchart.cs create mode 100644 Assets/Fungus/Flowchart/Scripts/IFlowchart.cs.meta create mode 100644 Assets/Fungus/Flowchart/Scripts/IUpdateable.cs create mode 100644 Assets/Fungus/Flowchart/Scripts/IUpdateable.cs.meta diff --git a/Assets/Fungus/Flowchart/Scripts/Block.cs b/Assets/Fungus/Flowchart/Scripts/Block.cs index 3c74d09d..245fe83e 100644 --- a/Assets/Fungus/Flowchart/Scripts/Block.cs +++ b/Assets/Fungus/Flowchart/Scripts/Block.cs @@ -210,7 +210,7 @@ namespace Fungus ICommand command = commandList[i]; activeCommand = command; - if (flowchart.gameObject.activeInHierarchy) + if (flowchart.IsActive()) { // Auto select a command in some situations if ((flowchart.SelectedCommands.Count == 0 && i == 0) || diff --git a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs index aff19c12..a3878e98 100644 --- a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs +++ b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs @@ -12,22 +12,12 @@ using System.Text.RegularExpressions; namespace Fungus { - /// - /// Interface for Flowchart components which can be updated when the - /// scene loads in the editor. This is used to maintain backwards - /// compatibility with earlier versions of Fungus. - /// - interface IUpdateable - { - void UpdateToVersion(int oldVersion, int newVersion); - } - /// /// Visual scripting controller for the Flowchart programming language. /// Flowchart objects may be edited visually using the Flowchart editor window. /// [ExecuteInEditMode] - public class Flowchart : MonoBehaviour, ISubstitutionHandler + public class Flowchart : MonoBehaviour, IFlowchart, ISubstitutionHandler { /// /// The current version of the Flowchart. Used for updating components. @@ -39,184 +29,91 @@ namespace Fungus /// public const string DEFAULT_BLOCK_NAME = "New Block"; - /// - /// Variable to track flowchart's version so components can update to new versions. - /// [HideInInspector] [SerializeField] protected int version = 0; // Default to 0 to always trigger an update for older versions of Fungus. - public int Version { set { version = value; } } - /// - /// Scroll position of Flowchart editor window. - /// [HideInInspector] [SerializeField] protected Vector2 scrollPos; - public virtual Vector2 ScrollPos { get { return scrollPos; } set { scrollPos = value; } } - /// - /// Scroll position of Flowchart variables window. - /// [HideInInspector] [SerializeField] protected Vector2 variablesScrollPos; - public virtual Vector2 VariablesScrollPos { get { return variablesScrollPos; } set { variablesScrollPos = value; } } - /// - /// Show the variables pane. - /// [HideInInspector] [SerializeField] protected bool variablesExpanded = true; - public virtual bool VariablesExpanded { get { return variablesExpanded; } set { variablesExpanded = value; } } - /// - /// Height of command block view in inspector. - /// [HideInInspector] [SerializeField] protected float blockViewHeight = 400; - public virtual float BlockViewHeight { get { return blockViewHeight; } set { blockViewHeight = value; } } - /// - /// Zoom level of Flowchart editor window. - /// [HideInInspector] [SerializeField] protected float zoom = 1f; - public virtual float Zoom { get { return zoom; } set { zoom = value; } } - /// - /// Scrollable area for Flowchart editor window. - /// [HideInInspector] [SerializeField] protected Rect scrollViewRect; - public virtual Rect ScrollViewRect { get { return scrollViewRect; } set { scrollViewRect = value; } } - /// - /// Currently selected block in the Flowchart editor. - /// [HideInInspector] [FormerlySerializedAs("selectedSequence")] [SerializeField] protected Block selectedBlock; - public virtual IBlock SelectedBlock { get { return selectedBlock; } set { selectedBlock = (Block)value; } } - /// - /// Currently selected command in the Flowchart editor. - /// [HideInInspector] [SerializeField] protected List selectedCommands = new List(); - public virtual List SelectedCommands { get { return selectedCommands; } } - /// - /// The list of variables that can be accessed by the Flowchart. - /// [HideInInspector] [SerializeField] protected List variables = new List(); - public virtual List Variables { get { return variables; } } - /// - /// Description text displayed in the Flowchart editor window - /// [TextArea(3, 5)] [Tooltip("Description text displayed in the Flowchart editor window")] [SerializeField] protected string description = ""; - public virtual string Description { get { return description; } } - /// - /// Slow down execution in the editor to make it easier to visualise program flow. - /// [Range(0f, 5f)] [Tooltip("Adds a pause after each execution step to make it easier to visualise program flow. Editor only, has no effect in platform builds.")] [SerializeField] protected float stepPause = 0f; - public virtual float StepPause { get { return stepPause; } } - /// - /// Use command color when displaying the command list in the inspector. - /// [Tooltip("Use command color when displaying the command list in the Fungus Editor window")] [SerializeField] protected bool colorCommands = true; - public virtual bool ColorCommands { get { return colorCommands; } } - - /// - /// Hides the Flowchart block and command components in the inspector. - /// Deselect to inspect the block and command components that make up the Flowchart. - /// + [Tooltip("Hides the Flowchart block and command components in the inspector. Deselect to inspect the block and command components that make up the Flowchart.")] [SerializeField] protected bool hideComponents = true; - /// - /// Saves the selected block and commands when saving the scene. Helps avoid version control conflicts if you've only changed the active selection. - /// [Tooltip("Saves the selected block and commands when saving the scene. Helps avoid version control conflicts if you've only changed the active selection.")] [SerializeField] protected bool saveSelection = true; - public virtual bool SaveSelection { get { return saveSelection; } } - /// - /// Unique identifier for identifying this flowchart in localized string keys. - /// [Tooltip("Unique identifier for this flowchart in localized string keys. If no id is specified then the name of the Flowchart object will be used.")] [SerializeField] protected string localizationId = ""; - public virtual string LocalizationId { get { return localizationId; } } - /// - /// Display line numbers in the command list in the Block inspector. - /// [Tooltip("Display line numbers in the command list in the Block inspector.")] [SerializeField] protected bool showLineNumbers = false; - public virtual bool ShowLineNumbers { get { return showLineNumbers; } } - /// - /// List of commands to hide in the Add Command menu. Use this to restrict the set of commands available when editing a Flowchart. - /// [Tooltip("List of commands to hide in the Add Command menu. Use this to restrict the set of commands available when editing a Flowchart.")] [SerializeField] protected List hideCommands = new List(); - /// - /// Lua Environment to be used by default for all Execute Lua commands in this Flowchart. - /// [Tooltip("Lua Environment to be used by default for all Execute Lua commands in this Flowchart")] [SerializeField] protected LuaEnvironment luaEnvironment; - public virtual ILuaEnvironment LuaEnv { get { return luaEnvironment; } } - /// - /// The ExecuteLua command adds a global Lua variable with this name bound to the flowchart prior to executing. - /// [Tooltip("The ExecuteLua command adds a global Lua variable with this name bound to the flowchart prior to executing.")] [SerializeField] protected string luaBindingName = "flowchart"; - public virtual string LuaBindingName { get { return luaBindingName; } } - - /// - /// Position in the center of all blocks in the flowchart. - /// - public virtual Vector2 CenterPosition { set; get; } /// /// Cached list of flowchart objects in the scene for fast lookup. /// public static List cachedFlowcharts = new List(); - protected static bool eventSystemPresent; - - protected StringSubstituter stringSubstituer; - /// - /// Returns the next id to assign to a new flowchart item. - /// Item ids increase monotically so they are guaranteed to - /// be unique within a Flowchart. + /// Sends a message to all Flowchart objects in the current scene. + /// Any block with a matching MessageReceived event handler will start executing. /// - public int NextItemId() + public static void BroadcastFungusMessage(string messageName) { - int maxId = -1; - IBlock[] blocks = GetComponents(); - foreach (IBlock block in blocks) - { - maxId = Math.Max(maxId, block.ItemId); - } - - var commands = GetComponents(); - foreach (var command in commands) + MessageReceived[] eventHandlers = UnityEngine.Object.FindObjectsOfType(); + foreach (MessageReceived eventHandler in eventHandlers) { - maxId = Math.Max(maxId, command.ItemId); + eventHandler.OnSendFungusMessage(messageName); } - return maxId + 1; } + protected static bool eventSystemPresent; + + protected StringSubstituter stringSubstituer; + #if UNITY_5_4_OR_NEWER protected virtual void Awake() { @@ -266,7 +163,7 @@ namespace Fungus eventSystemPresent = true; } - public virtual void OnEnable() + protected virtual void OnEnable() { if (!cachedFlowcharts.Contains(this)) { @@ -299,7 +196,7 @@ namespace Fungus version = CURRENT_VERSION; } - public virtual void OnDisable() + protected virtual void OnDisable() { cachedFlowcharts.Remove(this); } @@ -395,9 +292,68 @@ namespace Fungus return block; } - /// - /// Create a new block node which you can then add commands to. - /// + #region IFlowchart implementation + + public virtual Vector2 ScrollPos { get { return scrollPos; } set { scrollPos = value; } } + + public virtual Vector2 VariablesScrollPos { get { return variablesScrollPos; } set { variablesScrollPos = value; } } + + public virtual bool VariablesExpanded { get { return variablesExpanded; } set { variablesExpanded = value; } } + + public virtual float BlockViewHeight { get { return blockViewHeight; } set { blockViewHeight = value; } } + + public virtual float Zoom { get { return zoom; } set { zoom = value; } } + + public virtual Rect ScrollViewRect { get { return scrollViewRect; } set { scrollViewRect = value; } } + + public virtual IBlock SelectedBlock { get { return selectedBlock; } set { selectedBlock = (Block)value; } } + + public virtual List SelectedCommands { get { return selectedCommands; } } + + public virtual List Variables { get { return variables; } } + + public virtual string Description { get { return description; } } + + public virtual float StepPause { get { return stepPause; } } + + public virtual bool ColorCommands { get { return colorCommands; } } + + public virtual bool SaveSelection { get { return saveSelection; } } + + public virtual string LocalizationId { get { return localizationId; } } + + public virtual bool ShowLineNumbers { get { return showLineNumbers; } } + + public virtual ILuaEnvironment LuaEnv { get { return luaEnvironment; } } + + public virtual string LuaBindingName { get { return luaBindingName; } } + + public virtual Vector2 CenterPosition { set; get; } + + public int Version { set { version = value; } } + + public bool IsActive() + { + return gameObject.activeInHierarchy; + } + + public int NextItemId() + { + int maxId = -1; + IBlock[] blocks = GetComponents(); + foreach (IBlock block in blocks) + { + maxId = Math.Max(maxId, block.ItemId); + } + + var commands = GetComponents(); + foreach (var command in commands) + { + maxId = Math.Max(maxId, command.ItemId); + } + return maxId + 1; + } + public virtual Block CreateBlock(Vector2 position) { Block b = CreateBlockComponent(gameObject); @@ -408,9 +364,6 @@ namespace Fungus return b; } - /// - /// Returns the named Block in the flowchart, or null if not found. - /// public virtual IBlock FindBlock(string blockName) { IBlock [] blocks = GetComponents(); @@ -421,13 +374,10 @@ namespace Fungus return block; } } - + return null; } - /// - /// Execute a child block in the Flowchart. - /// You can use this method in a UI event. e.g. to handle a button click. public virtual void ExecuteBlock(string blockName) { IBlock block = null; @@ -452,12 +402,6 @@ namespace Fungus } } - /// - /// Execute a child block in the flowchart. - /// The block must be in an idle state to be executed. - /// This version provides extra options to control how the block is executed. - /// Returns true if the Block started execution. - /// public virtual bool ExecuteBlock(IBlock block, int commandIndex = 0, Action onComplete = null) { if (block == null) @@ -484,9 +428,6 @@ namespace Fungus return true; } - /// - /// Stop all executing Blocks in this Flowchart. - /// public virtual void StopAllBlocks() { IBlock [] blocks = GetComponents(); @@ -499,10 +440,6 @@ namespace Fungus } } - /// - /// Sends a message to this Flowchart only. - /// Any block with a matching MessageReceived event handler will start executing. - /// public virtual void SendFungusMessage(string messageName) { MessageReceived[] eventHandlers = GetComponents(); @@ -512,22 +449,6 @@ namespace Fungus } } - /// - /// Sends a message to all Flowchart objects in the current scene. - /// Any block with a matching MessageReceived event handler will start executing. - /// - public static void BroadcastFungusMessage(string messageName) - { - MessageReceived[] eventHandlers = UnityEngine.Object.FindObjectsOfType(); - foreach (MessageReceived eventHandler in eventHandlers) - { - eventHandler.OnSendFungusMessage(messageName); - } - } - - /// - /// Returns a new variable key that is guaranteed not to clash with any existing variable in the list. - /// public virtual string GetUniqueVariableKey(string originalKey, Variable ignoreVariable = null) { int suffix = 0; @@ -566,7 +487,7 @@ namespace Fungus key = baseKey + suffix; } } - + if (!collision) { return key; @@ -574,14 +495,11 @@ namespace Fungus } } - /// - /// Returns a new Block key that is guaranteed not to clash with any existing Block in the Flowchart. - /// public virtual string GetUniqueBlockKey(string originalKey, IBlock ignoreBlock = null) { int suffix = 0; string baseKey = originalKey.Trim(); - + // No empty keys allowed if (baseKey.Length == 0) { @@ -601,7 +519,7 @@ namespace Fungus { continue; } - + if (block.BlockName.Equals(key, StringComparison.CurrentCultureIgnoreCase)) { collision = true; @@ -609,7 +527,7 @@ namespace Fungus key = baseKey + suffix; } } - + if (!collision) { return key; @@ -617,22 +535,19 @@ namespace Fungus } } - /// - /// Returns a new Label key that is guaranteed not to clash with any existing Label in the Block. - /// public virtual string GetUniqueLabelKey(string originalKey, Label ignoreLabel) { int suffix = 0; string baseKey = originalKey.Trim(); - + // No empty keys allowed if (baseKey.Length == 0) { baseKey = "New Label"; } - + IBlock block = ignoreLabel.ParentBlock; - + string key = baseKey; while (true) { @@ -645,7 +560,7 @@ namespace Fungus { continue; } - + if (label.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)) { collision = true; @@ -653,21 +568,14 @@ namespace Fungus key = baseKey + suffix; } } - + if (!collision) { return key; } } } - - /// - /// Returns the variable with the specified key, or null if the key is not found. - /// You will need to cast the returned variable to the correct sub-type. - /// You can then access the variable's value using the Value property. e.g. - /// BooleanVariable boolVar = flowchart.GetVariable("MyBool") as BooleanVariable; - /// boolVar.Value = false; - /// + public Variable GetVariable(string key) { foreach (Variable variable in variables) @@ -681,12 +589,6 @@ namespace Fungus return null; } - /// - /// Returns the variable with the specified key, or null if the key is not found. - /// You can then access the variable's value using the Value property. e.g. - /// BooleanVariable boolVar = flowchart.GetVariable("MyBool"); - /// boolVar.Value = false; - /// public T GetVariable(string key) where T : Variable { foreach (Variable variable in variables) @@ -701,10 +603,6 @@ namespace Fungus return null; } - /// - /// Register a new variable with the Flowchart at runtime. - /// The variable should be added as a component on the Flowchart game object. - /// public void SetVariable(string key, T newvariable) where T : Variable { foreach (Variable v in variables) @@ -723,9 +621,6 @@ namespace Fungus Debug.LogWarning("Variable " + key + " not found."); } - /// - /// Gets a list of all variables with public scope in this Flowchart. - /// public virtual List GetPublicVariables() { List publicVariables = new List(); @@ -740,10 +635,6 @@ namespace Fungus return publicVariables; } - /// - /// Gets the value of a boolean variable. - /// Returns false if the variable key does not exist. - /// public virtual bool GetBooleanVariable(string key) { BooleanVariable variable = GetVariable(key); @@ -758,10 +649,6 @@ namespace Fungus } } - /// - /// Sets the value of a boolean variable. - /// The variable must already be added to the list of variables for this Flowchart. - /// public virtual void SetBooleanVariable(string key, bool value) { BooleanVariable variable = GetVariable(key); @@ -771,10 +658,6 @@ namespace Fungus } } - /// - /// Gets the value of an integer variable. - /// Returns 0 if the variable key does not exist. - /// public virtual int GetIntegerVariable(string key) { IntegerVariable variable = GetVariable(key); @@ -789,10 +672,6 @@ namespace Fungus } } - /// - /// Sets the value of an integer variable. - /// The variable must already be added to the list of variables for this Flowchart. - /// public virtual void SetIntegerVariable(string key, int value) { IntegerVariable variable = GetVariable(key); @@ -802,10 +681,6 @@ namespace Fungus } } - /// - /// Gets the value of a float variable. - /// Returns 0 if the variable key does not exist. - /// public virtual float GetFloatVariable(string key) { FloatVariable variable = GetVariable(key); @@ -820,10 +695,6 @@ namespace Fungus } } - /// - /// Sets the value of a float variable. - /// The variable must already be added to the list of variables for this Flowchart. - /// public virtual void SetFloatVariable(string key, float value) { FloatVariable variable = GetVariable(key); @@ -833,10 +704,6 @@ namespace Fungus } } - /// - /// Gets the value of a string variable. - /// Returns the empty string if the variable key does not exist. - /// public virtual string GetStringVariable(string key) { StringVariable variable = GetVariable(key); @@ -851,10 +718,6 @@ namespace Fungus } } - /// - /// Sets the value of a string variable. - /// The variable must already be added to the list of variables for this Flowchart. - /// public virtual void SetStringVariable(string key, string value) { StringVariable variable = GetVariable(key); @@ -864,9 +727,6 @@ namespace Fungus } } - /// - /// Set the block objects to be hidden or visible depending on the hideComponents property. - /// public virtual void UpdateHideFlags() { if (hideComponents) @@ -910,17 +770,11 @@ namespace Fungus } - /// - /// Clears the list of selected commands. - /// public virtual void ClearSelectedCommands() { selectedCommands.Clear(); } - - /// - /// Adds a command to the list of selected commands. - /// + public virtual void AddSelectedCommand(ICommand command) { if (!selectedCommands.Contains((Command)command)) @@ -929,9 +783,6 @@ namespace Fungus } } - /// - /// Reset the commands and variables in the Flowchart. - /// public virtual void Reset(bool resetCommands, bool resetVariables) { if (resetCommands) @@ -952,9 +803,6 @@ namespace Fungus } } - /// - /// Override this in a Flowchart subclass to filter which commands are shown in the Add Command list. - /// public virtual bool IsCommandSupported(CommandInfoAttribute commandInfo) { foreach (string key in hideCommands) @@ -970,9 +818,6 @@ namespace Fungus return true; } - /// - /// Returns true if there are any executing blocks in this Flowchart. - /// public virtual bool HasExecutingBlocks() { IBlock[] blocks = GetComponents(); @@ -986,9 +831,6 @@ namespace Fungus return false; } - /// - /// Returns a list of all executing blocks in this Flowchart. - /// public virtual List GetExecutingBlocks() { List executingBlocks = new List(); @@ -1005,51 +847,6 @@ namespace Fungus return executingBlocks; } - /// - /// Implementation of StringSubstituter.ISubstitutionHandler which matches any public variable in the Flowchart. - /// To perform full variable substitution with all substitution handlers in the scene, you should - /// use the SubstituteVariables() method instead. - /// - [MoonSharp.Interpreter.MoonSharpHidden] - public virtual bool SubstituteStrings(StringBuilder input) - { - // Instantiate the regular expression object. - Regex r = new Regex("{\\$.*?}"); - - bool modified = false; - - // Match the regular expression pattern against a text string. - var results = r.Matches(input.ToString()); - foreach (Match match in results) - { - string key = match.Value.Substring(2, match.Value.Length - 3); - - // Look for any matching public variables in this Flowchart - foreach (Variable variable in variables) - { - if (variable == null) - continue; - - if (variable.Scope == VariableScope.Public && - variable.Key == key) - { - string value = variable.ToString(); - input.Replace(match.Value, value); - - modified = true; - } - } - } - - return modified; - } - - /// - /// Substitute variables in the input text with the format {$VarName} - /// This will first match with private variables in this Flowchart, and then - /// with public variables in all Flowcharts in the scene (and any component - /// in the scene that implements StringSubstituter.ISubstitutionHandler). - /// public virtual string SubstituteVariables(string input) { if (stringSubstituer == null) @@ -1062,7 +859,7 @@ namespace Fungus StringBuilder sb = stringSubstituer._StringBuilder; sb.Length = 0; sb.Append(input); - + // Instantiate the regular expression object. Regex r = new Regex("{\\$.*?}"); @@ -1102,5 +899,50 @@ namespace Fungus return input; } } + + #endregion + + #region IStringSubstituter implementation + + /// + /// Implementation of StringSubstituter.ISubstitutionHandler which matches any public variable in the Flowchart. + /// To perform full variable substitution with all substitution handlers in the scene, you should + /// use the SubstituteVariables() method instead. + /// + [MoonSharp.Interpreter.MoonSharpHidden] + public virtual bool SubstituteStrings(StringBuilder input) + { + // Instantiate the regular expression object. + Regex r = new Regex("{\\$.*?}"); + + bool modified = false; + + // Match the regular expression pattern against a text string. + var results = r.Matches(input.ToString()); + foreach (Match match in results) + { + string key = match.Value.Substring(2, match.Value.Length - 3); + + // Look for any matching public variables in this Flowchart + foreach (Variable variable in variables) + { + if (variable == null) + continue; + + if (variable.Scope == VariableScope.Public && + variable.Key == key) + { + string value = variable.ToString(); + input.Replace(match.Value, value); + + modified = true; + } + } + } + + return modified; + } + + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Flowchart/Scripts/IFlowchart.cs b/Assets/Fungus/Flowchart/Scripts/IFlowchart.cs new file mode 100644 index 00000000..4638696f --- /dev/null +++ b/Assets/Fungus/Flowchart/Scripts/IFlowchart.cs @@ -0,0 +1,289 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace Fungus +{ + /// + /// Visual scripting controller for the Flowchart programming language. + /// Flowchart objects may be edited visually using the Flowchart editor window. + /// + public interface IFlowchart + { + /// + /// Scroll position of Flowchart editor window. + /// + Vector2 ScrollPos { get; set; } + + /// + /// Scroll position of Flowchart variables window. + /// + Vector2 VariablesScrollPos { get; set; } + + /// + /// Show the variables pane. + /// + bool VariablesExpanded { get; set; } + + /// + /// Height of command block view in inspector. + /// + float BlockViewHeight { get; set; } + + /// + /// Zoom level of Flowchart editor window. + /// + float Zoom { get; set; } + + /// + /// Scrollable area for Flowchart editor window. + /// + Rect ScrollViewRect { get; set; } + + /// + /// Currently selected block in the Flowchart editor. + /// + IBlock SelectedBlock { get; set; } + + /// + /// Currently selected command in the Flowchart editor. + /// + List SelectedCommands { get; } + + /// + /// The list of variables that can be accessed by the Flowchart. + /// + List Variables { get; } + + /// + /// Description text displayed in the Flowchart editor window + /// + string Description { get; } + + /// + /// Slow down execution in the editor to make it easier to visualise program flow. + /// + float StepPause { get; } + + /// + /// Use command color when displaying the command list in the inspector. + /// + bool ColorCommands { get; } + + /// + /// Saves the selected block and commands when saving the scene. Helps avoid version control conflicts if you've only changed the active selection. + /// + bool SaveSelection { get; } + + /// + /// Unique identifier for identifying this flowchart in localized string keys. + /// + string LocalizationId { get; } + + /// + /// Display line numbers in the command list in the Block inspector. + /// + bool ShowLineNumbers { get; } + + /// + /// Lua Environment to be used by default for all Execute Lua commands in this Flowchart. + /// + ILuaEnvironment LuaEnv { get; } + + /// + /// The ExecuteLua command adds a global Lua variable with this name bound to the flowchart prior to executing. + /// + string LuaBindingName { get; } + + /// + /// Position in the center of all blocks in the flowchart. + /// + Vector2 CenterPosition { set; get; } + + /// + /// Variable to track flowchart's version so components can update to new versions. + /// + int Version { set; } + + /// + /// Returns the next id to assign to a new flowchart item. + /// Item ids increase monotically so they are guaranteed to + /// be unique within a Flowchart. + /// + int NextItemId(); + + /// + /// Returns true if the Flowchart gameobject is active. + /// + /// true if this instance is active; otherwise, false. + bool IsActive(); + + /// + /// Create a new block node which you can then add commands to. + /// + Block CreateBlock(Vector2 position); + + /// + /// Returns the named Block in the flowchart, or null if not found. + /// + IBlock FindBlock(string blockName); + + /// + /// Execute a child block in the Flowchart. + /// You can use this method in a UI event. e.g. to handle a button click. + void ExecuteBlock(string blockName); + + /// + /// Execute a child block in the flowchart. + /// The block must be in an idle state to be executed. + /// This version provides extra options to control how the block is executed. + /// Returns true if the Block started execution. + /// + bool ExecuteBlock(IBlock block, int commandIndex = 0, System.Action onComplete = null); + + /// + /// Stop all executing Blocks in this Flowchart. + /// + void StopAllBlocks(); + + /// + /// Sends a message to this Flowchart only. + /// Any block with a matching MessageReceived event handler will start executing. + /// + void SendFungusMessage(string messageName); + + /// + /// Returns a new variable key that is guaranteed not to clash with any existing variable in the list. + /// + string GetUniqueVariableKey(string originalKey, Variable ignoreVariable = null); + + /// + /// Returns a new Block key that is guaranteed not to clash with any existing Block in the Flowchart. + /// + string GetUniqueBlockKey(string originalKey, IBlock ignoreBlock = null); + + /// + /// Returns a new Label key that is guaranteed not to clash with any existing Label in the Block. + /// + string GetUniqueLabelKey(string originalKey, Label ignoreLabel); + + /// + /// Returns the variable with the specified key, or null if the key is not found. + /// You will need to cast the returned variable to the correct sub-type. + /// You can then access the variable's value using the Value property. e.g. + /// BooleanVariable boolVar = flowchart.GetVariable("MyBool") as BooleanVariable; + /// boolVar.Value = false; + /// + Variable GetVariable(string key); + + /// + /// Returns the variable with the specified key, or null if the key is not found. + /// You can then access the variable's value using the Value property. e.g. + /// BooleanVariable boolVar = flowchart.GetVariable("MyBool"); + /// boolVar.Value = false; + /// + T GetVariable(string key) where T : Variable; + + /// + /// Register a new variable with the Flowchart at runtime. + /// The variable should be added as a component on the Flowchart game object. + /// + void SetVariable(string key, T newvariable) where T : Variable; + + /// + /// Gets a list of all variables with public scope in this Flowchart. + /// + List GetPublicVariables(); + + /// + /// Gets the value of a boolean variable. + /// Returns false if the variable key does not exist. + /// + bool GetBooleanVariable(string key); + + /// + /// Sets the value of a boolean variable. + /// The variable must already be added to the list of variables for this Flowchart. + /// + void SetBooleanVariable(string key, bool value); + + /// + /// Gets the value of an integer variable. + /// Returns 0 if the variable key does not exist. + /// + int GetIntegerVariable(string key); + + /// + /// Sets the value of an integer variable. + /// The variable must already be added to the list of variables for this Flowchart. + /// + void SetIntegerVariable(string key, int value); + + /// + /// Gets the value of a float variable. + /// Returns 0 if the variable key does not exist. + /// + float GetFloatVariable(string key); + + /// + /// Sets the value of a float variable. + /// The variable must already be added to the list of variables for this Flowchart. + /// + void SetFloatVariable(string key, float value); + + /// + /// Gets the value of a string variable. + /// Returns the empty string if the variable key does not exist. + /// + string GetStringVariable(string key); + + /// + /// Sets the value of a string variable. + /// The variable must already be added to the list of variables for this Flowchart. + /// + void SetStringVariable(string key, string value); + + /// + /// Set the block objects to be hidden or visible depending on the hideComponents property. + /// + void UpdateHideFlags(); + + /// + /// Clears the list of selected commands. + /// + void ClearSelectedCommands(); + + /// + /// Adds a command to the list of selected commands. + /// + void AddSelectedCommand(ICommand command); + + /// + /// Reset the commands and variables in the Flowchart. + /// + void Reset(bool resetCommands, bool resetVariables); + + /// + /// Override this in a Flowchart subclass to filter which commands are shown in the Add Command list. + /// + bool IsCommandSupported(CommandInfoAttribute commandInfo); + + /// + /// Returns true if there are any executing blocks in this Flowchart. + /// + bool HasExecutingBlocks(); + + /// + /// Returns a list of all executing blocks in this Flowchart. + /// + List GetExecutingBlocks(); + + /// + /// Substitute variables in the input text with the format {$VarName} + /// This will first match with private variables in this Flowchart, and then + /// with public variables in all Flowcharts in the scene (and any component + /// in the scene that implements StringSubstituter.ISubstitutionHandler). + /// + string SubstituteVariables(string input); + } +} diff --git a/Assets/Fungus/Flowchart/Scripts/IFlowchart.cs.meta b/Assets/Fungus/Flowchart/Scripts/IFlowchart.cs.meta new file mode 100644 index 00000000..295020cd --- /dev/null +++ b/Assets/Fungus/Flowchart/Scripts/IFlowchart.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e0dd617b954d242bdb37e9c5de4f63cc +timeCreated: 1473856422 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Flowchart/Scripts/IUpdateable.cs b/Assets/Fungus/Flowchart/Scripts/IUpdateable.cs new file mode 100644 index 00000000..2f736011 --- /dev/null +++ b/Assets/Fungus/Flowchart/Scripts/IUpdateable.cs @@ -0,0 +1,15 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus +{ + /// + /// Interface for Flowchart components which can be updated when the + /// scene loads in the editor. This is used to maintain backwards + /// compatibility with earlier versions of Fungus. + /// + interface IUpdateable + { + void UpdateToVersion(int oldVersion, int newVersion); + } +} \ No newline at end of file diff --git a/Assets/Fungus/Flowchart/Scripts/IUpdateable.cs.meta b/Assets/Fungus/Flowchart/Scripts/IUpdateable.cs.meta new file mode 100644 index 00000000..e92074e3 --- /dev/null +++ b/Assets/Fungus/Flowchart/Scripts/IUpdateable.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5c893a3523cc1497090726522c805cb8 +timeCreated: 1474016919 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: