Browse Source

Merge pull request #414 from FungusGames/pr/412

Pr/412
master
Chris Gregan 9 years ago
parent
commit
3194fe5821
  1. 6
      Assets/Fungus/Flowchart/Editor/CommandEditor.cs
  2. 16
      Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs
  3. 8
      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. 269
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  8. 14
      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

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

@ -154,6 +154,7 @@ namespace Fungus
serializedObject.ApplyModifiedProperties();
}
static public void ObjectField<T>(SerializedProperty property, GUIContent label, GUIContent nullLabel, List<T> 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.

16
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;
}

8
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()

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

4
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)
{

250
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<ColorVariable>(item.variableKey);
if (color != null)
objValue = color.value;
break;
case "UnityEngine.GameObject":
var gameObject = flowChart.GetVariable<GameObjectVariable>(item.variableKey);
if (gameObject != null)
objValue = gameObject.value;
break;
case "UnityEngine.Material":
var material = flowChart.GetVariable<MaterialVariable>(item.variableKey);
if (material != null)
objValue = material.value;
break;
case "UnityEngine.Sprite":
var sprite = flowChart.GetVariable<SpriteVariable>(item.variableKey);
if (sprite != null)
objValue = sprite.value;
break;
case "UnityEngine.Texture":
var texture = flowChart.GetVariable<TextureVariable>(item.variableKey);
if (texture != null)
objValue = texture.value;
break;
case "UnityEngine.Vector2":
var vector2 = flowChart.GetVariable<Vector2Variable>(item.variableKey);
if (vector2 != null)
objValue = vector2.value;
break;
case "UnityEngine.Vector3":
var vector3 = flowChart.GetVariable<Vector3Variable>(item.variableKey);
if (vector3 != null)
objValue = vector3.value;
break;
default:
var obj = flowChart.GetVariable<ObjectVariable>(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<IntegerVariable>(item.variableKey);
if (intvalue != null)
objValue = intvalue.value;
break;
case "System.Boolean":
var boolean = flowChart.GetVariable<BooleanVariable>(item.variableKey);
if (boolean != null)
objValue = boolean.value;
break;
case "System.Single":
var floatvalue = flowChart.GetVariable<FloatVariable>(item.variableKey);
if (floatvalue != null)
objValue = floatvalue.value;
break;
case "System.String":
var stringvalue = flowChart.GetVariable<StringVariable>(item.variableKey);
if (stringvalue != null)
objValue = stringvalue.value;
break;
case "UnityEngine.Color":
var color = flowChart.GetVariable<ColorVariable>(item.variableKey);
if (color != null)
objValue = color.value;
break;
case "UnityEngine.GameObject":
var gameObject = flowChart.GetVariable<GameObjectVariable>(item.variableKey);
if (gameObject != null)
objValue = gameObject.value;
break;
case "UnityEngine.Material":
var material = flowChart.GetVariable<MaterialVariable>(item.variableKey);
if (material != null)
objValue = material.value;
break;
case "UnityEngine.Sprite":
var sprite = flowChart.GetVariable<SpriteVariable>(item.variableKey);
if (sprite != null)
objValue = sprite.value;
break;
case "UnityEngine.Texture":
var texture = flowChart.GetVariable<TextureVariable>(item.variableKey);
if (texture != null)
objValue = texture.value;
break;
case "UnityEngine.Vector2":
var vector2 = flowChart.GetVariable<Vector2Variable>(item.variableKey);
if (vector2 != null)
objValue = vector2.value;
break;
case "UnityEngine.Vector3":
var vector3 = flowChart.GetVariable<Vector3Variable>(item.variableKey);
if (vector3 != null)
objValue = vector3.value;
break;
default:
var obj = flowChart.GetVariable<ObjectVariable>(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<ColorVariable>(key).value = (UnityEngine.Color)value;
break;
case "UnityEngine.GameObject":
flowChart.GetVariable<GameObjectVariable>(key).value = (UnityEngine.GameObject)value;
break;
case "UnityEngine.Material":
flowChart.GetVariable<MaterialVariable>(key).value = (UnityEngine.Material)value;
break;
case "UnityEngine.Sprite":
flowChart.GetVariable<SpriteVariable>(key).value = (UnityEngine.Sprite)value;
break;
case "UnityEngine.Texture":
flowChart.GetVariable<TextureVariable>(key).value = (UnityEngine.Texture)value;
break;
case "UnityEngine.Vector2":
flowChart.GetVariable<Vector2Variable>(key).value = (UnityEngine.Vector2)value;
break;
case "UnityEngine.Vector3":
flowChart.GetVariable<Vector3Variable>(key).value = (UnityEngine.Vector3)value;
break;
default:
flowChart.GetVariable<ObjectVariable>(key).value = (UnityEngine.Object)value;
break;
}
}
{
var flowChart = GetFlowchart();
switch (returnType)
{
case "System.Int32":
flowChart.GetVariable<IntegerVariable>(key).value = (int)value;
break;
case "System.Boolean":
flowChart.GetVariable<BooleanVariable>(key).value = (bool)value;
break;
case "System.Single":
flowChart.GetVariable<FloatVariable>(key).value = (float)value;
break;
case "System.String":
flowChart.GetVariable<StringVariable>(key).value = (string)value;
break;
case "UnityEngine.Color":
flowChart.GetVariable<ColorVariable>(key).value = (UnityEngine.Color)value;
break;
case "UnityEngine.GameObject":
flowChart.GetVariable<GameObjectVariable>(key).value = (UnityEngine.GameObject)value;
break;
case "UnityEngine.Material":
flowChart.GetVariable<MaterialVariable>(key).value = (UnityEngine.Material)value;
break;
case "UnityEngine.Sprite":
flowChart.GetVariable<SpriteVariable>(key).value = (UnityEngine.Sprite)value;
break;
case "UnityEngine.Texture":
flowChart.GetVariable<TextureVariable>(key).value = (UnityEngine.Texture)value;
break;
case "UnityEngine.Vector2":
flowChart.GetVariable<Vector2Variable>(key).value = (UnityEngine.Vector2)value;
break;
case "UnityEngine.Vector3":
flowChart.GetVariable<Vector3Variable>(key).value = (UnityEngine.Vector3)value;
break;
default:
flowChart.GetVariable<ObjectVariable>(key).value = (UnityEngine.Object)value;
break;
}
}
}
[System.Serializable]

269
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<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.
*/
public virtual List<Variable> GetPublicVariables()
public virtual List<Variable> GetPublicVariables()
{
List<Variable> publicVariables = new List<Variable>();
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<BooleanVariable>(key);
if(variable != null)
{
return GetVariable<BooleanVariable>(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<BooleanVariable>(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<IntegerVariable>(key);
/**
if (variable != null)
{
return GetVariable<IntegerVariable>(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<IntegerVariable>(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<FloatVariable>(key);
if (variable != null)
{
return GetVariable<FloatVariable>(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<FloatVariable>(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<StringVariable>(key);
/**
if (variable != null)
{
return GetVariable<StringVariable>(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<StringVariable>(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)
{

14
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<Character>(characterProp,
new GUIContent("Character", "Character that is speaking"),
new GUIContent("<None>"),
Character.activeCharacters);
CommandEditor.ObjectField<Character>(characterProp,
new GUIContent("Character", "Character that is speaking"),
new GUIContent("<None>"),
Character.activeCharacters);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(" ");
characterProp.objectReferenceValue = (Character) EditorGUILayout.ObjectField(characterProp.objectReferenceValue, typeof(Character), true);
EditorGUILayout.EndHorizontal();
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
if (flowchart.GetBooleanVariable("BoolVar") != true ||
flowchart.GetIntegerVariable("IntVar") != 5 ||
flowchart.GetFloatVariable("FloatVar") != 22.1f ||
flowchart.GetStringVariable("StringVar") != "a string")
if (flowchart.GetVariable<BooleanVariable>("BoolVar").value != true ||
flowchart.GetVariable<IntegerVariable>("IntVar").value != 5 ||
flowchart.GetVariable<FloatVariable>("FloatVar").value != 22.1f ||
flowchart.GetVariable<StringVariable>("StringVar").value != "a string")
{
IntegrationTest.Fail("Fungus variables do not match expected values");
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

Loading…
Cancel
Save