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. 2
      Assets/Fungus/Flowchart/Editor/EditorZoomArea.cs
  4. 3
      Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs
  5. 24
      Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs
  6. 129
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  7. 6
      Assets/Fungus/Narrative/Editor/SayEditor.cs
  8. 8
      Assets/Tests/Scripting/TestInvoke.cs
  9. 9
      Assets/Tests/TestAssets/Animation.meta
  10. 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;
} }

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

@ -66,10 +66,12 @@ 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;
} }

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));

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

@ -191,16 +191,24 @@ namespace Fungus
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);
if (intvalue != null)
objValue = intvalue.value;
break; break;
case "System.Boolean": case "System.Boolean":
objValue = flowChart.GetBooleanVariable(item.variableKey); var boolean = flowChart.GetVariable<BooleanVariable>(item.variableKey);
if (boolean != null)
objValue = boolean.value;
break; break;
case "System.Single": case "System.Single":
objValue = flowChart.GetFloatVariable(item.variableKey); var floatvalue = flowChart.GetVariable<FloatVariable>(item.variableKey);
if (floatvalue != null)
objValue = floatvalue.value;
break; break;
case "System.String": case "System.String":
objValue = flowChart.GetStringVariable(item.variableKey); var stringvalue = flowChart.GetVariable<StringVariable>(item.variableKey);
if (stringvalue != null)
objValue = stringvalue.value;
break; break;
case "UnityEngine.Color": case "UnityEngine.Color":
var color = flowChart.GetVariable<ColorVariable>(item.variableKey); var color = flowChart.GetVariable<ColorVariable>(item.variableKey);
@ -258,16 +266,16 @@ namespace Fungus
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;

129
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,9 +647,32 @@ namespace Fungus
} }
} }
Debug.LogWarning("Variable " + key + " not found.");
return null; 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.
*/ */
@ -667,20 +696,17 @@ namespace Fungus
*/ */
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) if(variable != null)
{ {
return variable.value; return GetVariable<BooleanVariable>(key).value;
}
} }
} else
Debug.LogWarning("Boolean variable " + key + " not found."); {
return false; return false;
} }
}
/** /**
* Sets the value of a boolean variable. * Sets the value of a boolean variable.
@ -688,19 +714,11 @@ namespace Fungus
*/ */
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 (v != null && v.key == key)
{
BooleanVariable variable = v as BooleanVariable;
if(variable != null) if(variable != null)
{ {
variable.value = value; variable.value = value;
return;
}
}
} }
Debug.LogWarning("Boolean variable " + key + " not found.");
} }
/** /**
@ -709,20 +727,17 @@ namespace Fungus
*/ */
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) if (variable != null)
{ {
return variable.value; return GetVariable<IntegerVariable>(key).value;
}
} }
} else
Debug.LogWarning("Integer variable " + key + " not found."); {
return 0; return 0;
} }
}
/** /**
* Sets the value of an integer variable. * Sets the value of an integer variable.
@ -730,19 +745,11 @@ namespace Fungus
*/ */
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 (v != null && v.key == key)
{
IntegerVariable variable = v as IntegerVariable;
if (variable != null) if (variable != null)
{ {
variable.value = value; variable.value = value;
return;
}
}
} }
Debug.LogWarning("Integer variable " + key + " not found.");
} }
/** /**
@ -751,20 +758,17 @@ namespace Fungus
*/ */
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) if (variable != null)
{ {
return variable.value; return GetVariable<FloatVariable>(key).value;
} }
} else
} {
Debug.LogWarning("Float variable " + key + " not found.");
return 0f; return 0f;
} }
}
/** /**
* Sets the value of a float variable. * Sets the value of a float variable.
@ -772,20 +776,12 @@ namespace Fungus
*/ */
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 (v != null && v.key == key)
{
FloatVariable variable = v as FloatVariable;
if (variable != null) if (variable != null)
{ {
variable.value = value; 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.
@ -793,20 +789,17 @@ namespace Fungus
*/ */
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) if (variable != null)
{ {
return variable.value; return GetVariable<StringVariable>(key).value;
}
}
} }
Debug.LogWarning("String variable " + key + " not found."); else
{
return ""; return "";
} }
}
/** /**
* Sets the value of a string variable. * Sets the value of a string variable.
@ -814,19 +807,11 @@ namespace Fungus
*/ */
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 (v != null && v.key == key)
{
StringVariable variable = v as StringVariable;
if (variable != null) if (variable != null)
{ {
variable.value = value; variable.value = value;
return;
}
}
} }
Debug.LogWarning("String variable " + key + " not found.");
} }
/** /**

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

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

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