diff --git a/Assets/Fungus/Flowchart/Editor/CommandEditor.cs b/Assets/Fungus/Flowchart/Editor/CommandEditor.cs index e579954e..f48ddb2c 100644 --- a/Assets/Fungus/Flowchart/Editor/CommandEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/CommandEditor.cs @@ -154,6 +154,7 @@ namespace Fungus serializedObject.ApplyModifiedProperties(); } + static public void ObjectField(SerializedProperty property, GUIContent label, GUIContent nullLabel, List objectList) where T : Object { if (property == null) @@ -172,14 +173,16 @@ namespace Fungus if (objectList[i] == null) continue; objectNames.Add(new GUIContent(objectList[i].name)); + if (selectedObject == objectList[i]) { selectedIndex = i + 1; } + } T result; - + selectedIndex = EditorGUILayout.Popup(label, selectedIndex, objectNames.ToArray()); if (selectedIndex == 0) { @@ -192,6 +195,7 @@ namespace Fungus property.objectReferenceValue = result; } + /** * When modifying custom editor code you can occasionally end up with orphaned editor instances. diff --git a/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs b/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs index 39217fe6..e6d5c83f 100644 --- a/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs +++ b/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs @@ -393,7 +393,17 @@ namespace Fungus } else { - GUI.Label(commandLabelRect, commandName, commandLabelStyle); + string commandNameLabel; + if (flowchart.showLineNumbers) + { + commandNameLabel = command.commandIndex.ToString() + ": " + commandName; + } + else + { + commandNameLabel = commandName; + } + + GUI.Label(commandLabelRect, commandNameLabel, commandLabelStyle); } if (command.executingIconTimer > Time.realtimeSinceStartup) @@ -421,8 +431,8 @@ namespace Fungus } else { - summaryRect.x += commandNameWidth; - summaryRect.width -= commandNameWidth; + summaryRect.x += commandNameWidth + 20; + summaryRect.width -= commandNameWidth + 20; summaryRect.width -= 5; } diff --git a/Assets/Fungus/Flowchart/Editor/EditorZoomArea.cs b/Assets/Fungus/Flowchart/Editor/EditorZoomArea.cs index 5f7d0aa1..c5b9ac58 100644 --- a/Assets/Fungus/Flowchart/Editor/EditorZoomArea.cs +++ b/Assets/Fungus/Flowchart/Editor/EditorZoomArea.cs @@ -66,11 +66,13 @@ namespace Fungus GUI.BeginGroup(clippedArea); _prevGuiMatrix = GUI.matrix; - Matrix4x4 translation = Matrix4x4.TRS(clippedArea.TopLeft(), Quaternion.identity, Vector3.one); + + Matrix4x4 translation = Matrix4x4.TRS(clippedArea.TopLeft(), Quaternion.identity, Vector3.one); Matrix4x4 scale = Matrix4x4.Scale(new Vector3(zoomScale, zoomScale, 1.0f)); GUI.matrix = translation * scale * translation.inverse * GUI.matrix; - - return clippedArea; + + + return clippedArea; } public static void End() diff --git a/Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs b/Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs index 24a4eced..f7aee951 100644 --- a/Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs @@ -25,6 +25,7 @@ namespace Fungus protected SerializedProperty saveSelectionProp; protected SerializedProperty localizationIdProp; protected SerializedProperty variablesProp; + protected SerializedProperty showLineNumbersProp; protected SerializedProperty hideCommandsProp; protected Texture2D addTexture; @@ -41,6 +42,7 @@ namespace Fungus saveSelectionProp = serializedObject.FindProperty("saveSelection"); localizationIdProp = serializedObject.FindProperty("localizationId"); variablesProp = serializedObject.FindProperty("variables"); + showLineNumbersProp = serializedObject.FindProperty("showLineNumbers"); hideCommandsProp = serializedObject.FindProperty("hideCommands"); addTexture = Resources.Load("Icons/add_small") as Texture2D; @@ -60,6 +62,7 @@ namespace Fungus EditorGUILayout.PropertyField(stepPauseProp); EditorGUILayout.PropertyField(saveSelectionProp); EditorGUILayout.PropertyField(localizationIdProp); + EditorGUILayout.PropertyField(showLineNumbersProp); // Show list of commands to hide in Add Command menu ReorderableListGUI.Title(new GUIContent(hideCommandsProp.displayName, hideCommandsProp.tooltip)); diff --git a/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs b/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs index 2f5fd60e..3063420d 100755 --- a/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs +++ b/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs @@ -559,8 +559,8 @@ namespace Fungus return; } - // Select block when node is clicked - if (Event.current.button == 0 && + // Select block when node is clicked + if (Event.current.button == 0 && Event.current.type == EventType.MouseDown && !mouseOverVariables) { diff --git a/Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs b/Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs old mode 100644 new mode 100755 index 7e265272..b725317c --- a/Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs +++ b/Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs @@ -172,129 +172,137 @@ namespace Fungus } protected object[] GetParameterValues() - { - object[] values = new object[methodParameters.Length]; - var flowChart = GetFlowchart(); - - for (int i = 0; i < methodParameters.Length; i++) - { - var item = methodParameters[i]; - - if (string.IsNullOrEmpty(item.variableKey)) - { - values[i] = item.objValue.GetValue(); - } - else - { - object objValue = null; - - switch (item.objValue.typeFullname) - { - case "System.Int32": - objValue = flowChart.GetIntegerVariable(item.variableKey); - break; - case "System.Boolean": - objValue = flowChart.GetBooleanVariable(item.variableKey); - break; - case "System.Single": - objValue = flowChart.GetFloatVariable(item.variableKey); - break; - case "System.String": - objValue = flowChart.GetStringVariable(item.variableKey); - break; - case "UnityEngine.Color": - var color = flowChart.GetVariable(item.variableKey); - if (color != null) - objValue = color.value; - break; - case "UnityEngine.GameObject": - var gameObject = flowChart.GetVariable(item.variableKey); - if (gameObject != null) - objValue = gameObject.value; - break; - case "UnityEngine.Material": - var material = flowChart.GetVariable(item.variableKey); - if (material != null) - objValue = material.value; - break; - case "UnityEngine.Sprite": - var sprite = flowChart.GetVariable(item.variableKey); - if (sprite != null) - objValue = sprite.value; - break; - case "UnityEngine.Texture": - var texture = flowChart.GetVariable(item.variableKey); - if (texture != null) - objValue = texture.value; - break; - case "UnityEngine.Vector2": - var vector2 = flowChart.GetVariable(item.variableKey); - if (vector2 != null) - objValue = vector2.value; - break; - case "UnityEngine.Vector3": - var vector3 = flowChart.GetVariable(item.variableKey); - if (vector3 != null) - objValue = vector3.value; - break; - default: - var obj = flowChart.GetVariable(item.variableKey); - if (obj != null) - objValue = obj.value; - break; - } - - values[i] = objValue; - } - } - - return values; - } + { + object[] values = new object[methodParameters.Length]; + var flowChart = GetFlowchart(); + + for (int i = 0; i < methodParameters.Length; i++) + { + var item = methodParameters[i]; + + if (string.IsNullOrEmpty(item.variableKey)) + { + values[i] = item.objValue.GetValue(); + } + else + { + object objValue = null; + + switch (item.objValue.typeFullname) + { + case "System.Int32": + var intvalue = flowChart.GetVariable(item.variableKey); + if (intvalue != null) + objValue = intvalue.value; + break; + case "System.Boolean": + var boolean = flowChart.GetVariable(item.variableKey); + if (boolean != null) + objValue = boolean.value; + break; + case "System.Single": + var floatvalue = flowChart.GetVariable(item.variableKey); + if (floatvalue != null) + objValue = floatvalue.value; + break; + case "System.String": + var stringvalue = flowChart.GetVariable(item.variableKey); + if (stringvalue != null) + objValue = stringvalue.value; + break; + case "UnityEngine.Color": + var color = flowChart.GetVariable(item.variableKey); + if (color != null) + objValue = color.value; + break; + case "UnityEngine.GameObject": + var gameObject = flowChart.GetVariable(item.variableKey); + if (gameObject != null) + objValue = gameObject.value; + break; + case "UnityEngine.Material": + var material = flowChart.GetVariable(item.variableKey); + if (material != null) + objValue = material.value; + break; + case "UnityEngine.Sprite": + var sprite = flowChart.GetVariable(item.variableKey); + if (sprite != null) + objValue = sprite.value; + break; + case "UnityEngine.Texture": + var texture = flowChart.GetVariable(item.variableKey); + if (texture != null) + objValue = texture.value; + break; + case "UnityEngine.Vector2": + var vector2 = flowChart.GetVariable(item.variableKey); + if (vector2 != null) + objValue = vector2.value; + break; + case "UnityEngine.Vector3": + var vector3 = flowChart.GetVariable(item.variableKey); + if (vector3 != null) + objValue = vector3.value; + break; + default: + var obj = flowChart.GetVariable(item.variableKey); + if (obj != null) + objValue = obj.value; + break; + } + + values[i] = objValue; + } + } + + return values; + } protected void SetVariable(string key, object value, string returnType) - { - var flowChart = GetFlowchart(); - - switch (returnType) - { - case "System.Int32": - flowChart.SetIntegerVariable(key, (int)value); - break; - case "System.Boolean": - flowChart.SetBooleanVariable(key, (bool)value); - break; - case "System.Single": - flowChart.SetFloatVariable(key, (float)value); - break; - case "System.String": - flowChart.SetStringVariable(key, (string)value); - break; - case "UnityEngine.Color": - flowChart.GetVariable(key).value = (UnityEngine.Color)value; - break; - case "UnityEngine.GameObject": - flowChart.GetVariable(key).value = (UnityEngine.GameObject)value; - break; - case "UnityEngine.Material": - flowChart.GetVariable(key).value = (UnityEngine.Material)value; - break; - case "UnityEngine.Sprite": - flowChart.GetVariable(key).value = (UnityEngine.Sprite)value; - break; - case "UnityEngine.Texture": - flowChart.GetVariable(key).value = (UnityEngine.Texture)value; - break; - case "UnityEngine.Vector2": - flowChart.GetVariable(key).value = (UnityEngine.Vector2)value; - break; - case "UnityEngine.Vector3": - flowChart.GetVariable(key).value = (UnityEngine.Vector3)value; - break; - default: - flowChart.GetVariable(key).value = (UnityEngine.Object)value; - break; - } - } + { + var flowChart = GetFlowchart(); + + switch (returnType) + { + case "System.Int32": + flowChart.GetVariable(key).value = (int)value; + break; + case "System.Boolean": + flowChart.GetVariable(key).value = (bool)value; + break; + case "System.Single": + flowChart.GetVariable(key).value = (float)value; + break; + case "System.String": + flowChart.GetVariable(key).value = (string)value; + break; + case "UnityEngine.Color": + flowChart.GetVariable(key).value = (UnityEngine.Color)value; + break; + case "UnityEngine.GameObject": + flowChart.GetVariable(key).value = (UnityEngine.GameObject)value; + break; + case "UnityEngine.Material": + flowChart.GetVariable(key).value = (UnityEngine.Material)value; + break; + case "UnityEngine.Sprite": + flowChart.GetVariable(key).value = (UnityEngine.Sprite)value; + break; + case "UnityEngine.Texture": + flowChart.GetVariable(key).value = (UnityEngine.Texture)value; + break; + case "UnityEngine.Vector2": + flowChart.GetVariable(key).value = (UnityEngine.Vector2)value; + break; + case "UnityEngine.Vector3": + flowChart.GetVariable(key).value = (UnityEngine.Vector3)value; + break; + default: + flowChart.GetVariable(key).value = (UnityEngine.Object)value; + break; + } + } } [System.Serializable] diff --git a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs index faa7003f..00b9b64a 100644 --- a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs +++ b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs @@ -134,6 +134,12 @@ namespace Fungus [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.")] public string localizationId = ""; + /** + * Display line numbers in the command list in the Block inspector. + */ + [Tooltip("Display line numbers in the command list in the Block inspector.")] + public bool showLineNumbers = false; + /** * List of commands to hide in the Add Command menu. Use this to restrict the set of commands available when editing a Flowchart. */ @@ -641,13 +647,36 @@ namespace Fungus } } - return null; + Debug.LogWarning("Variable " + key + " not found."); + 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) + { + 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) @@ -661,178 +690,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) - { - foreach (Variable v in variables) - { - if (v != null && v.key == key) - { - BooleanVariable variable = v as BooleanVariable; - if (variable != null) - { - return variable.value; - } - } - } - Debug.LogWarning("Boolean variable " + key + " not found."); - return false; - } - - /** + 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) - { - foreach (Variable v in variables) - { - if (v != null && v.key == key) - { - BooleanVariable variable = v as BooleanVariable; - if (variable != null) - { - variable.value = value; - return; - } - } - } - Debug.LogWarning("Boolean variable " + key + " not found."); - } + 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) - { - foreach (Variable v in variables) - { - if (v != null && v.key == key) - { - IntegerVariable variable = v as IntegerVariable; - if (variable != null) - { - return variable.value; - } - } - } - Debug.LogWarning("Integer variable " + key + " not found."); - return 0; - } + 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) - { - foreach (Variable v in variables) - { - if (v != null && v.key == key) - { - IntegerVariable variable = v as IntegerVariable; - if (variable != null) - { - variable.value = value; - return; - } - } - } - Debug.LogWarning("Integer variable " + key + " not found."); - } + 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) - { - foreach (Variable v in variables) - { - if (v != null && v.key == key) - { - FloatVariable variable = v as FloatVariable; - if (variable != null) - { - return variable.value; - } - } - } - Debug.LogWarning("Float variable " + key + " not found."); - return 0f; - } - - /** + 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) - { - foreach (Variable v in variables) - { - if (v != null && v.key == key) - { - FloatVariable variable = v as FloatVariable; - if (variable != null) - { - variable.value = value; - return; - } - } - } - Debug.LogWarning("Float variable " + key + " not found."); - } + 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) - { - foreach (Variable v in variables) - { - if (v != null && v.key == key) - { - StringVariable variable = v as StringVariable; - if (variable != null) - { - return variable.value; - } - } - } - Debug.LogWarning("String variable " + key + " not found."); - return ""; - } + 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) - { - foreach (Variable v in variables) - { - if (v != null && v.key == key) - { - StringVariable variable = v as StringVariable; - if (variable != null) - { - variable.value = value; - return; - } - } - } - Debug.LogWarning("String variable " + key + " not found."); - } + 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 11a9ecb8..c0d5c764 100644 --- a/Assets/Fungus/Narrative/Editor/SayEditor.cs +++ b/Assets/Fungus/Narrative/Editor/SayEditor.cs @@ -111,17 +111,21 @@ namespace Fungus { DestroyImmediate(blackTex); } - + public override void DrawCommandGUI() { serializedObject.Update(); bool showPortraits = false; + CommandEditor.ObjectField(characterProp, + new GUIContent("Character", "Character that is speaking"), + new GUIContent(""), + Character.activeCharacters); - CommandEditor.ObjectField(characterProp, - new GUIContent("Character", "Character that is speaking"), - new GUIContent(""), - Character.activeCharacters); + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PrefixLabel(" "); + characterProp.objectReferenceValue = (Character) EditorGUILayout.ObjectField(characterProp.objectReferenceValue, typeof(Character), true); + EditorGUILayout.EndHorizontal(); Say t = target as Say; diff --git a/Assets/Tests/Scripting/TestInvoke.cs b/Assets/Tests/Scripting/TestInvoke.cs index f5a188ca..0c680587 100644 --- a/Assets/Tests/Scripting/TestInvoke.cs +++ b/Assets/Tests/Scripting/TestInvoke.cs @@ -95,10 +95,10 @@ namespace Fungus } // Check Fungus variables are populated with expected values - if (flowchart.GetBooleanVariable("BoolVar") != true || - flowchart.GetIntegerVariable("IntVar") != 5 || - flowchart.GetFloatVariable("FloatVar") != 22.1f || - flowchart.GetStringVariable("StringVar") != "a string") + if (flowchart.GetVariable("BoolVar").value != true || + flowchart.GetVariable("IntVar").value != 5 || + flowchart.GetVariable("FloatVar").value != 22.1f || + flowchart.GetVariable("StringVar").value != "a string") { IntegrationTest.Fail("Fungus variables do not match expected values"); return; diff --git a/Assets/Tests/TestAssets/Animation.meta b/Assets/Tests/TestAssets/Animation.meta deleted file mode 100644 index 3fd2cc3b..00000000 --- a/Assets/Tests/TestAssets/Animation.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: f5528a125b1c64ce4b4ad7ae57de4989 -folderAsset: yes -timeCreated: 1458814143 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index c4684cd5..bb60c067 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 5.3.4f1 +m_EditorVersion: 5.3.2f1 m_StandardAssetsVersion: 0