diff --git a/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs b/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs index a1340d02..7aa96b8b 100644 --- a/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs +++ b/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs @@ -389,11 +389,11 @@ namespace Fungus if (isComment) { - GUI.Label(commandLabelRect, command.commandIndex + ": ", commandLabelStyle); + GUI.Label(commandLabelRect, "", commandLabelStyle); } else { - GUI.Label(commandLabelRect, command.commandIndex + ": " + commandName, commandLabelStyle); + GUI.Label(commandLabelRect, commandName, commandLabelStyle); } if (command.executingIconTimer > Time.realtimeSinceStartup) @@ -433,7 +433,7 @@ namespace Fungus summaryStyle.wordWrap = false; summaryStyle.clipping = TextClipping.Clip; commandLabelStyle.alignment = TextAnchor.MiddleLeft; - GUI.Label(summaryRect, summary, summaryStyle); + GUI.Label(summaryRect, command.commandIndex + ": " + summary, summaryStyle); if (error) { diff --git a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs index 15c87030..697cabc4 100644 --- a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs +++ b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs @@ -645,10 +645,27 @@ namespace Fungus return null; } - /** + public void SetVariable(string key, T newvariable) where T : Variable + { + foreach (Variable v in variables) + { + if (v != null && v.key == key) + { + T variable = v as T; + if (variable != null) + { + variable = newvariable; + return; + } + } + } + Debug.LogWarning("Variable " + key + " not found."); + } + + /** * Gets a list of all variables with public scope in this Flowchart. */ - public virtual List GetPublicVariables() + public virtual List GetPublicVariables() { List publicVariables = new List(); foreach (Variable v in variables) @@ -662,10 +679,134 @@ 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); + + if(variable != null) + { + return GetVariable(key).value; + } + else + { + return false; + } + } + + /** + * 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); + if(variable != null) + { + variable.value = value; + } + } + + /** + * 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); + + if (variable != null) + { + return GetVariable(key).value; + } + else + { + return 0; + } + } + + /** + * 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); + if (variable != null) + { + variable.value = value; + } + } + + /** + * 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); + + if (variable != null) + { + return GetVariable(key).value; + } + else + { + return 0f; + } + } + + /** + * 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); + if (variable != null) + { + variable.value = value; + } + } + + /** + * 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); + + if (variable != null) + { + return GetVariable(key).value; + } + else + { + return ""; + } + } + + /** + * 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); + if (variable != null) + { + variable.value = value; + } + } + + /** * Set the block objects to be hidden or visible depending on the hideComponents property. */ - public virtual void UpdateHideFlags() + public virtual void UpdateHideFlags() { if (hideComponents) { diff --git a/Assets/Fungus/Narrative/Editor/SayEditor.cs b/Assets/Fungus/Narrative/Editor/SayEditor.cs index ac128408..75580ac3 100644 --- a/Assets/Fungus/Narrative/Editor/SayEditor.cs +++ b/Assets/Fungus/Narrative/Editor/SayEditor.cs @@ -117,7 +117,10 @@ namespace Fungus serializedObject.Update(); bool showPortraits = false; - + CommandEditor.ObjectField(characterProp, + new GUIContent("Character", "Character that is speaking"), + new GUIContent(""), + Character.activeCharacters); characterProp.objectReferenceValue = (Character) EditorGUILayout.ObjectField(characterProp.objectReferenceValue, typeof(Character), true); Say t = target as Say;