Browse Source

Merge pull request #414 from FungusGames/pr/412

Pr/412
master
Chris Gregan 9 years ago
parent
commit
3194fe5821
  1. 4
      Assets/Fungus/Flowchart/Editor/CommandEditor.cs
  2. 16
      Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs
  3. 6
      Assets/Fungus/Flowchart/Editor/EditorZoomArea.cs
  4. 3
      Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs
  5. 4
      Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs
  6. 250
      Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs
  7. 265
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  8. 12
      Assets/Fungus/Narrative/Editor/SayEditor.cs
  9. 8
      Assets/Tests/Scripting/TestInvoke.cs
  10. 9
      Assets/Tests/TestAssets/Animation.meta
  11. 2
      ProjectSettings/ProjectVersion.txt

4
Assets/Fungus/Flowchart/Editor/CommandEditor.cs

@ -154,6 +154,7 @@ namespace Fungus
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
} }
static public void ObjectField<T>(SerializedProperty property, GUIContent label, GUIContent nullLabel, List<T> objectList) where T : Object static public void ObjectField<T>(SerializedProperty property, GUIContent label, GUIContent nullLabel, List<T> objectList) where T : Object
{ {
if (property == null) if (property == null)
@ -172,10 +173,12 @@ namespace Fungus
if (objectList[i] == null) continue; if (objectList[i] == null) continue;
objectNames.Add(new GUIContent(objectList[i].name)); objectNames.Add(new GUIContent(objectList[i].name));
if (selectedObject == objectList[i]) if (selectedObject == objectList[i])
{ {
selectedIndex = i + 1; selectedIndex = i + 1;
} }
} }
T result; T result;
@ -193,6 +196,7 @@ namespace Fungus
property.objectReferenceValue = result; property.objectReferenceValue = result;
} }
/** /**
* When modifying custom editor code you can occasionally end up with orphaned editor instances. * When modifying custom editor code you can occasionally end up with orphaned editor instances.
* When this happens, you'll get a null exception error every time the scene serializes / deserialized. * When this happens, you'll get a null exception error every time the scene serializes / deserialized.

16
Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs

@ -393,7 +393,17 @@ namespace Fungus
} }
else 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) if (command.executingIconTimer > Time.realtimeSinceStartup)
@ -421,8 +431,8 @@ namespace Fungus
} }
else else
{ {
summaryRect.x += commandNameWidth; summaryRect.x += commandNameWidth + 20;
summaryRect.width -= commandNameWidth; summaryRect.width -= commandNameWidth + 20;
summaryRect.width -= 5; summaryRect.width -= 5;
} }

6
Assets/Fungus/Flowchart/Editor/EditorZoomArea.cs

@ -66,11 +66,13 @@ namespace Fungus
GUI.BeginGroup(clippedArea); GUI.BeginGroup(clippedArea);
_prevGuiMatrix = GUI.matrix; _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)); Matrix4x4 scale = Matrix4x4.Scale(new Vector3(zoomScale, zoomScale, 1.0f));
GUI.matrix = translation * scale * translation.inverse * GUI.matrix; GUI.matrix = translation * scale * translation.inverse * GUI.matrix;
return clippedArea;
return clippedArea;
} }
public static void End() public static void End()

3
Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs

@ -25,6 +25,7 @@ namespace Fungus
protected SerializedProperty saveSelectionProp; protected SerializedProperty saveSelectionProp;
protected SerializedProperty localizationIdProp; protected SerializedProperty localizationIdProp;
protected SerializedProperty variablesProp; protected SerializedProperty variablesProp;
protected SerializedProperty showLineNumbersProp;
protected SerializedProperty hideCommandsProp; protected SerializedProperty hideCommandsProp;
protected Texture2D addTexture; protected Texture2D addTexture;
@ -41,6 +42,7 @@ namespace Fungus
saveSelectionProp = serializedObject.FindProperty("saveSelection"); saveSelectionProp = serializedObject.FindProperty("saveSelection");
localizationIdProp = serializedObject.FindProperty("localizationId"); localizationIdProp = serializedObject.FindProperty("localizationId");
variablesProp = serializedObject.FindProperty("variables"); variablesProp = serializedObject.FindProperty("variables");
showLineNumbersProp = serializedObject.FindProperty("showLineNumbers");
hideCommandsProp = serializedObject.FindProperty("hideCommands"); hideCommandsProp = serializedObject.FindProperty("hideCommands");
addTexture = Resources.Load("Icons/add_small") as Texture2D; addTexture = Resources.Load("Icons/add_small") as Texture2D;
@ -60,6 +62,7 @@ namespace Fungus
EditorGUILayout.PropertyField(stepPauseProp); EditorGUILayout.PropertyField(stepPauseProp);
EditorGUILayout.PropertyField(saveSelectionProp); EditorGUILayout.PropertyField(saveSelectionProp);
EditorGUILayout.PropertyField(localizationIdProp); EditorGUILayout.PropertyField(localizationIdProp);
EditorGUILayout.PropertyField(showLineNumbersProp);
// Show list of commands to hide in Add Command menu // Show list of commands to hide in Add Command menu
ReorderableListGUI.Title(new GUIContent(hideCommandsProp.displayName, hideCommandsProp.tooltip)); ReorderableListGUI.Title(new GUIContent(hideCommandsProp.displayName, hideCommandsProp.tooltip));

4
Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs

@ -559,8 +559,8 @@ namespace Fungus
return; return;
} }
// Select block when node is clicked // Select block when node is clicked
if (Event.current.button == 0 && if (Event.current.button == 0 &&
Event.current.type == EventType.MouseDown && Event.current.type == EventType.MouseDown &&
!mouseOverVariables) !mouseOverVariables)
{ {

250
Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs

@ -172,129 +172,137 @@ namespace Fungus
} }
protected object[] GetParameterValues() protected object[] GetParameterValues()
{ {
object[] values = new object[methodParameters.Length]; object[] values = new object[methodParameters.Length];
var flowChart = GetFlowchart(); var flowChart = GetFlowchart();
for (int i = 0; i < methodParameters.Length; i++) for (int i = 0; i < methodParameters.Length; i++)
{ {
var item = methodParameters[i]; var item = methodParameters[i];
if (string.IsNullOrEmpty(item.variableKey)) if (string.IsNullOrEmpty(item.variableKey))
{ {
values[i] = item.objValue.GetValue(); values[i] = item.objValue.GetValue();
} }
else else
{ {
object objValue = null; object objValue = null;
switch (item.objValue.typeFullname) switch (item.objValue.typeFullname)
{ {
case "System.Int32": case "System.Int32":
objValue = flowChart.GetIntegerVariable(item.variableKey); var intvalue = flowChart.GetVariable<IntegerVariable>(item.variableKey);
break; if (intvalue != null)
case "System.Boolean": objValue = intvalue.value;
objValue = flowChart.GetBooleanVariable(item.variableKey); break;
break; case "System.Boolean":
case "System.Single": var boolean = flowChart.GetVariable<BooleanVariable>(item.variableKey);
objValue = flowChart.GetFloatVariable(item.variableKey); if (boolean != null)
break; objValue = boolean.value;
case "System.String": break;
objValue = flowChart.GetStringVariable(item.variableKey); case "System.Single":
break; var floatvalue = flowChart.GetVariable<FloatVariable>(item.variableKey);
case "UnityEngine.Color": if (floatvalue != null)
var color = flowChart.GetVariable<ColorVariable>(item.variableKey); objValue = floatvalue.value;
if (color != null) break;
objValue = color.value; case "System.String":
break; var stringvalue = flowChart.GetVariable<StringVariable>(item.variableKey);
case "UnityEngine.GameObject": if (stringvalue != null)
var gameObject = flowChart.GetVariable<GameObjectVariable>(item.variableKey); objValue = stringvalue.value;
if (gameObject != null) break;
objValue = gameObject.value; case "UnityEngine.Color":
break; var color = flowChart.GetVariable<ColorVariable>(item.variableKey);
case "UnityEngine.Material": if (color != null)
var material = flowChart.GetVariable<MaterialVariable>(item.variableKey); objValue = color.value;
if (material != null) break;
objValue = material.value; case "UnityEngine.GameObject":
break; var gameObject = flowChart.GetVariable<GameObjectVariable>(item.variableKey);
case "UnityEngine.Sprite": if (gameObject != null)
var sprite = flowChart.GetVariable<SpriteVariable>(item.variableKey); objValue = gameObject.value;
if (sprite != null) break;
objValue = sprite.value; case "UnityEngine.Material":
break; var material = flowChart.GetVariable<MaterialVariable>(item.variableKey);
case "UnityEngine.Texture": if (material != null)
var texture = flowChart.GetVariable<TextureVariable>(item.variableKey); objValue = material.value;
if (texture != null) break;
objValue = texture.value; case "UnityEngine.Sprite":
break; var sprite = flowChart.GetVariable<SpriteVariable>(item.variableKey);
case "UnityEngine.Vector2": if (sprite != null)
var vector2 = flowChart.GetVariable<Vector2Variable>(item.variableKey); objValue = sprite.value;
if (vector2 != null) break;
objValue = vector2.value; case "UnityEngine.Texture":
break; var texture = flowChart.GetVariable<TextureVariable>(item.variableKey);
case "UnityEngine.Vector3": if (texture != null)
var vector3 = flowChart.GetVariable<Vector3Variable>(item.variableKey); objValue = texture.value;
if (vector3 != null) break;
objValue = vector3.value; case "UnityEngine.Vector2":
break; var vector2 = flowChart.GetVariable<Vector2Variable>(item.variableKey);
default: if (vector2 != null)
var obj = flowChart.GetVariable<ObjectVariable>(item.variableKey); objValue = vector2.value;
if (obj != null) break;
objValue = obj.value; case "UnityEngine.Vector3":
break; var vector3 = flowChart.GetVariable<Vector3Variable>(item.variableKey);
} if (vector3 != null)
objValue = vector3.value;
values[i] = objValue; break;
} default:
} var obj = flowChart.GetVariable<ObjectVariable>(item.variableKey);
if (obj != null)
return values; objValue = obj.value;
} break;
}
values[i] = objValue;
}
}
return values;
}
protected void SetVariable(string key, object value, string returnType) protected void SetVariable(string key, object value, string returnType)
{ {
var flowChart = GetFlowchart(); var flowChart = GetFlowchart();
switch (returnType) switch (returnType)
{ {
case "System.Int32": case "System.Int32":
flowChart.SetIntegerVariable(key, (int)value); flowChart.GetVariable<IntegerVariable>(key).value = (int)value;
break; break;
case "System.Boolean": case "System.Boolean":
flowChart.SetBooleanVariable(key, (bool)value); flowChart.GetVariable<BooleanVariable>(key).value = (bool)value;
break; break;
case "System.Single": case "System.Single":
flowChart.SetFloatVariable(key, (float)value); flowChart.GetVariable<FloatVariable>(key).value = (float)value;
break; break;
case "System.String": case "System.String":
flowChart.SetStringVariable(key, (string)value); flowChart.GetVariable<StringVariable>(key).value = (string)value;
break; break;
case "UnityEngine.Color": case "UnityEngine.Color":
flowChart.GetVariable<ColorVariable>(key).value = (UnityEngine.Color)value; flowChart.GetVariable<ColorVariable>(key).value = (UnityEngine.Color)value;
break; break;
case "UnityEngine.GameObject": case "UnityEngine.GameObject":
flowChart.GetVariable<GameObjectVariable>(key).value = (UnityEngine.GameObject)value; flowChart.GetVariable<GameObjectVariable>(key).value = (UnityEngine.GameObject)value;
break; break;
case "UnityEngine.Material": case "UnityEngine.Material":
flowChart.GetVariable<MaterialVariable>(key).value = (UnityEngine.Material)value; flowChart.GetVariable<MaterialVariable>(key).value = (UnityEngine.Material)value;
break; break;
case "UnityEngine.Sprite": case "UnityEngine.Sprite":
flowChart.GetVariable<SpriteVariable>(key).value = (UnityEngine.Sprite)value; flowChart.GetVariable<SpriteVariable>(key).value = (UnityEngine.Sprite)value;
break; break;
case "UnityEngine.Texture": case "UnityEngine.Texture":
flowChart.GetVariable<TextureVariable>(key).value = (UnityEngine.Texture)value; flowChart.GetVariable<TextureVariable>(key).value = (UnityEngine.Texture)value;
break; break;
case "UnityEngine.Vector2": case "UnityEngine.Vector2":
flowChart.GetVariable<Vector2Variable>(key).value = (UnityEngine.Vector2)value; flowChart.GetVariable<Vector2Variable>(key).value = (UnityEngine.Vector2)value;
break; break;
case "UnityEngine.Vector3": case "UnityEngine.Vector3":
flowChart.GetVariable<Vector3Variable>(key).value = (UnityEngine.Vector3)value; flowChart.GetVariable<Vector3Variable>(key).value = (UnityEngine.Vector3)value;
break; break;
default: default:
flowChart.GetVariable<ObjectVariable>(key).value = (UnityEngine.Object)value; flowChart.GetVariable<ObjectVariable>(key).value = (UnityEngine.Object)value;
break; break;
} }
} }
} }
[System.Serializable] [System.Serializable]

265
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.")] [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 = ""; 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. * 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<T>(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. * Gets a list of all variables with public scope in this Flowchart.
*/ */
public virtual List<Variable> GetPublicVariables() public virtual List<Variable> GetPublicVariables()
{ {
List<Variable> publicVariables = new List<Variable>(); List<Variable> publicVariables = new List<Variable>();
foreach (Variable v in variables) foreach (Variable v in variables)
@ -661,178 +690,134 @@ namespace Fungus
return publicVariables; return publicVariables;
} }
/** /**
* Gets the value of a boolean variable. * Gets the value of a boolean variable.
* Returns false if the variable key does not exist. * Returns false if the variable key does not exist.
*/ */
public virtual bool GetBooleanVariable(string key) public virtual bool GetBooleanVariable(string key)
{ {
foreach (Variable v in variables) BooleanVariable variable = GetVariable<BooleanVariable>(key);
{
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;
}
/** if(variable != null)
{
return GetVariable<BooleanVariable>(key).value;
}
else
{
return false;
}
}
/**
* Sets the value of a boolean variable. * Sets the value of a boolean variable.
* The variable must already be added to the list of variables for this Flowchart. * The variable must already be added to the list of variables for this Flowchart.
*/ */
public virtual void SetBooleanVariable(string key, bool value) public virtual void SetBooleanVariable(string key, bool value)
{ {
foreach (Variable v in variables) BooleanVariable variable = GetVariable<BooleanVariable>(key);
{ if(variable != null)
if (v != null && v.key == key) {
{ variable.value = value;
BooleanVariable variable = v as BooleanVariable; }
if (variable != null) }
{
variable.value = value;
return;
}
}
}
Debug.LogWarning("Boolean variable " + key + " not found.");
}
/** /**
* Gets the value of an integer variable. * Gets the value of an integer variable.
* Returns 0 if the variable key does not exist. * Returns 0 if the variable key does not exist.
*/ */
public virtual int GetIntegerVariable(string key) public virtual int GetIntegerVariable(string key)
{ {
foreach (Variable v in variables) IntegerVariable variable = GetVariable<IntegerVariable>(key);
{
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;
}
/** if (variable != null)
{
return GetVariable<IntegerVariable>(key).value;
}
else
{
return 0;
}
}
/**
* Sets the value of an integer variable. * Sets the value of an integer variable.
* The variable must already be added to the list of variables for this Flowchart. * The variable must already be added to the list of variables for this Flowchart.
*/ */
public virtual void SetIntegerVariable(string key, int value) public virtual void SetIntegerVariable(string key, int value)
{ {
foreach (Variable v in variables) IntegerVariable variable = GetVariable<IntegerVariable>(key);
{ if (variable != null)
if (v != null && v.key == key) {
{ variable.value = value;
IntegerVariable variable = v as IntegerVariable; }
if (variable != null) }
{
variable.value = value;
return;
}
}
}
Debug.LogWarning("Integer variable " + key + " not found.");
}
/** /**
* Gets the value of a float variable. * Gets the value of a float variable.
* Returns 0 if the variable key does not exist. * Returns 0 if the variable key does not exist.
*/ */
public virtual float GetFloatVariable(string key) public virtual float GetFloatVariable(string key)
{ {
foreach (Variable v in variables) FloatVariable variable = GetVariable<FloatVariable>(key);
{
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;
}
/** if (variable != null)
{
return GetVariable<FloatVariable>(key).value;
}
else
{
return 0f;
}
}
/**
* Sets the value of a float variable. * Sets the value of a float variable.
* The variable must already be added to the list of variables for this Flowchart. * The variable must already be added to the list of variables for this Flowchart.
*/ */
public virtual void SetFloatVariable(string key, float value) public virtual void SetFloatVariable(string key, float value)
{ {
foreach (Variable v in variables) FloatVariable variable = GetVariable<FloatVariable>(key);
{ if (variable != null)
if (v != null && v.key == key) {
{ variable.value = value;
FloatVariable variable = v as FloatVariable; }
if (variable != null) }
{
variable.value = value;
return;
}
}
}
Debug.LogWarning("Float variable " + key + " not found.");
}
/** /**
* Gets the value of a string variable. * Gets the value of a string variable.
* Returns the empty string if the variable key does not exist. * Returns the empty string if the variable key does not exist.
*/ */
public virtual string GetStringVariable(string key) public virtual string GetStringVariable(string key)
{ {
foreach (Variable v in variables) StringVariable variable = GetVariable<StringVariable>(key);
{
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 "";
}
/** if (variable != null)
{
return GetVariable<StringVariable>(key).value;
}
else
{
return "";
}
}
/**
* Sets the value of a string variable. * Sets the value of a string variable.
* The variable must already be added to the list of variables for this Flowchart. * The variable must already be added to the list of variables for this Flowchart.
*/ */
public virtual void SetStringVariable(string key, string value) public virtual void SetStringVariable(string key, string value)
{ {
foreach (Variable v in variables) StringVariable variable = GetVariable<StringVariable>(key);
{ if (variable != null)
if (v != null && v.key == key) {
{ variable.value = value;
StringVariable variable = v as StringVariable; }
if (variable != null) }
{
variable.value = value;
return;
}
}
}
Debug.LogWarning("String variable " + key + " not found.");
}
/** /**
* Set the block objects to be hidden or visible depending on the hideComponents property. * Set the block objects to be hidden or visible depending on the hideComponents property.
*/ */
public virtual void UpdateHideFlags() public virtual void UpdateHideFlags()
{ {
if (hideComponents) if (hideComponents)
{ {

12
Assets/Fungus/Narrative/Editor/SayEditor.cs

@ -117,11 +117,15 @@ namespace Fungus
serializedObject.Update(); serializedObject.Update();
bool showPortraits = false; bool showPortraits = false;
CommandEditor.ObjectField<Character>(characterProp,
new GUIContent("Character", "Character that is speaking"),
new GUIContent("<None>"),
Character.activeCharacters);
CommandEditor.ObjectField<Character>(characterProp, EditorGUILayout.BeginHorizontal();
new GUIContent("Character", "Character that is speaking"), EditorGUILayout.PrefixLabel(" ");
new GUIContent("<None>"), characterProp.objectReferenceValue = (Character) EditorGUILayout.ObjectField(characterProp.objectReferenceValue, typeof(Character), true);
Character.activeCharacters); EditorGUILayout.EndHorizontal();
Say t = target as Say; Say t = target as Say;

8
Assets/Tests/Scripting/TestInvoke.cs

@ -95,10 +95,10 @@ namespace Fungus
} }
// Check Fungus variables are populated with expected values // Check Fungus variables are populated with expected values
if (flowchart.GetBooleanVariable("BoolVar") != true || if (flowchart.GetVariable<BooleanVariable>("BoolVar").value != true ||
flowchart.GetIntegerVariable("IntVar") != 5 || flowchart.GetVariable<IntegerVariable>("IntVar").value != 5 ||
flowchart.GetFloatVariable("FloatVar") != 22.1f || flowchart.GetVariable<FloatVariable>("FloatVar").value != 22.1f ||
flowchart.GetStringVariable("StringVar") != "a string") flowchart.GetVariable<StringVariable>("StringVar").value != "a string")
{ {
IntegrationTest.Fail("Fungus variables do not match expected values"); IntegrationTest.Fail("Fungus variables do not match expected values");
return; return;

9
Assets/Tests/TestAssets/Animation.meta

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: f5528a125b1c64ce4b4ad7ae57de4989
folderAsset: yes
timeCreated: 1458814143
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

2
ProjectSettings/ProjectVersion.txt

@ -1,2 +1,2 @@
m_EditorVersion: 5.3.4f1 m_EditorVersion: 5.3.2f1
m_StandardAssetsVersion: 0 m_StandardAssetsVersion: 0

Loading…
Cancel
Save