Browse Source

Fix #67 Replaced global variables with public / private variables

Changed layout of Variables window to support editable value
Public variables in other FungusScripts appear in the variable picker
popup menu.
Variables now have a public value property and remember their starting
value for when they are reset.
Disabled LoadGlobals / SaveGlobals commands.
Changed all variable classes to use simple public value variable.
Added FungusScript.GetPublicVariables()
Deleted GlobalVariables class.
Added Variables test scene
master
chrisgregan 10 years ago
parent
commit
e21ce0a0e0
  1. 2
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs
  2. 25
      Assets/Fungus/FungusScript/Editor/VariableEditor.cs
  3. 90
      Assets/Fungus/FungusScript/Editor/VariableListAdaptor.cs
  4. 21
      Assets/Fungus/FungusScript/Scripts/BooleanVariable.cs
  5. 8
      Assets/Fungus/FungusScript/Scripts/Commands/If.cs
  6. 2
      Assets/Fungus/FungusScript/Scripts/Commands/LoadGlobals.cs
  7. 2
      Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs
  8. 2
      Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs
  9. 2
      Assets/Fungus/FungusScript/Scripts/Commands/SaveGlobals.cs
  10. 26
      Assets/Fungus/FungusScript/Scripts/Commands/SetVariable.cs
  11. 21
      Assets/Fungus/FungusScript/Scripts/FloatVariable.cs
  12. 37
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  13. 289
      Assets/Fungus/FungusScript/Scripts/GlobalVariables.cs
  14. 8
      Assets/Fungus/FungusScript/Scripts/GlobalVariables.cs.meta
  15. 21
      Assets/Fungus/FungusScript/Scripts/IntegerVariable.cs
  16. 21
      Assets/Fungus/FungusScript/Scripts/StringVariable.cs
  17. 3
      Assets/Fungus/FungusScript/Scripts/StringsParser.cs
  18. 4
      Assets/Fungus/FungusScript/Scripts/Variable.cs
  19. 5
      Assets/FungusExamples/Variables.meta
  20. 5
      Assets/FungusExamples/Variables/Scenes.meta
  21. 574
      Assets/FungusExamples/Variables/Scenes/Variables.unity
  22. 4
      Assets/FungusExamples/Variables/Scenes/Variables.unity.meta

2
Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

@ -161,7 +161,7 @@ namespace Fungus
GUILayout.BeginHorizontal();
GUILayout.BeginVertical(GUILayout.Width(300));
GUILayout.BeginVertical(GUILayout.Width(400));
GUILayout.FlexibleSpace();

25
Assets/Fungus/FungusScript/Editor/VariableEditor.cs

@ -51,7 +51,30 @@ namespace Fungus
selectedIndex = index;
}
}
FungusScript[] fsList = GameObject.FindObjectsOfType<FungusScript>();
foreach (FungusScript fs in fsList)
{
if (fs == fungusScript)
{
continue;
}
List<Variable> publicVars = fs.GetPublicVariables();
foreach (Variable v in publicVars)
{
variableKeys.Add(fs.name + " / " + v.key);
variableObjects.Add(v);
index++;
if (v == selectedVariable)
{
selectedIndex = index;
}
}
}
selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray());
property.objectReferenceValue = variableObjects[selectedIndex];

90
Assets/Fungus/FungusScript/Editor/VariableListAdaptor.cs

@ -91,21 +91,20 @@ namespace Fungus
return;
}
float width1 = 100;
float width3 = 50;
float width2 = Mathf.Max(position.width - width1 - width3, 60);
Rect keyRect = position;
keyRect.width = width1;
Rect valueRect = position;
valueRect.x += width1 + 5;
valueRect.width = width2 - 5;
float[] widths = { 50, 100, 130, 60 };
Rect[] rects = new Rect[4];
for (int i = 0; i < 4; ++i)
{
rects[i] = position;
rects[i].width = widths[i] - 5;
for (int j = 0; j < i; ++j)
{
rects[i].x += widths[j];
}
}
Rect scopeRect = position;
scopeRect.x += width1 + width2 + 5;
scopeRect.width = width3 - 5;
string type = "";
if (variable.GetType() == typeof(BooleanVariable))
{
@ -160,57 +159,26 @@ namespace Fungus
string key = variable.key;
VariableScope scope = variable.scope;
if (Application.isPlaying)
{
GUI.Label(keyRect, variable.key);
// To access properties in a monobehavior, you have to new a SerializedObject
// http://answers.unity3d.com/questions/629803/findrelativeproperty-never-worked-for-me-how-does.html
SerializedObject variableObject = new SerializedObject(this[index].objectReferenceValue);
if (variable.GetType() == typeof(BooleanVariable))
{
BooleanVariable v = variable as BooleanVariable;
v.Value = EditorGUI.Toggle(valueRect, v.Value);
}
else if (variable.GetType() == typeof(IntegerVariable))
{
IntegerVariable v = variable as IntegerVariable;
v.Value = EditorGUI.IntField(valueRect, v.Value);
}
else if (variable.GetType() == typeof(FloatVariable))
{
FloatVariable v = variable as FloatVariable;
v.Value = EditorGUI.FloatField(valueRect, v.Value);
}
else if (variable.GetType() == typeof(StringVariable))
{
StringVariable v = variable as StringVariable;
v.Value = EditorGUI.TextField(valueRect, v.Value);
}
variableObject.Update();
if (scope == VariableScope.Local)
{
GUI.Label(scopeRect, "Local");
}
else if (scope == VariableScope.Global)
{
GUI.Label(scopeRect, "Global");
}
}
else
{
key = EditorGUI.TextField(keyRect, variable.key);
GUI.Label(valueRect, type);
scope = (VariableScope)EditorGUI.EnumPopup(scopeRect, variable.scope);
GUI.Label(rects[0], type);
// To access properties in a monobehavior, you have to new a SerializedObject
// http://answers.unity3d.com/questions/629803/findrelativeproperty-never-worked-for-me-how-does.html
SerializedObject variableObject = new SerializedObject(this[index].objectReferenceValue);
SerializedProperty keyProp = variableObject.FindProperty("key");
SerializedProperty scopeProp = variableObject.FindProperty("scope");
key = EditorGUI.TextField(rects[1], variable.key);
SerializedProperty keyProp = variableObject.FindProperty("key");
keyProp.stringValue = fungusScript.GetUniqueVariableKey(key, variable);
variableObject.Update();
keyProp.stringValue = fungusScript.GetUniqueVariableKey(key, variable);
scopeProp.enumValueIndex = (int)scope;
variableObject.ApplyModifiedProperties();
}
SerializedProperty defaultProp = variableObject.FindProperty("value");
EditorGUI.PropertyField(rects[2], defaultProp, new GUIContent(""));
SerializedProperty scopeProp = variableObject.FindProperty("scope");
scope = (VariableScope)EditorGUI.EnumPopup(rects[3], variable.scope);
scopeProp.enumValueIndex = (int)scope;
variableObject.ApplyModifiedProperties();
GUI.backgroundColor = Color.white;
}

21
Assets/Fungus/FungusScript/Scripts/BooleanVariable.cs

@ -7,22 +7,23 @@ namespace Fungus
public class BooleanVariable : Variable
{
protected bool booleanVal;
public bool value;
public bool Value
{
get { return (scope == VariableScope.Local) ? booleanVal : GlobalVariables.GetBoolean(key); }
set { if (scope == VariableScope.Local) { booleanVal = value; } else { GlobalVariables.SetBoolean(key, value); } }
}
protected bool startValue;
public override void OnReset()
{
Value = false;
value = startValue;
}
public override string ToString()
{
return Value.ToString();
return value.ToString();
}
protected virtual void Start()
{
startValue = value;
}
}
@ -37,8 +38,8 @@ namespace Fungus
public bool Value
{
get { return (booleanRef == null) ? booleanVal : booleanRef.Value; }
set { if (booleanRef == null) { booleanVal = value; } else { booleanRef.Value = value; } }
get { return (booleanRef == null) ? booleanVal : booleanRef.value; }
set { if (booleanRef == null) { booleanVal = value; } else { booleanRef.value = value; } }
}
public string GetDescription()

8
Assets/Fungus/FungusScript/Scripts/Commands/If.cs

@ -54,7 +54,7 @@ namespace Fungus
if (variable.GetType() == typeof(BooleanVariable))
{
bool lhs = (variable as BooleanVariable).Value;
bool lhs = (variable as BooleanVariable).value;
bool rhs = booleanData.Value;
switch (compareOperator)
@ -70,7 +70,7 @@ namespace Fungus
}
else if (variable.GetType() == typeof(IntegerVariable))
{
int lhs = (variable as IntegerVariable).Value;
int lhs = (variable as IntegerVariable).value;
int rhs = integerData.Value;
switch (compareOperator)
@ -97,7 +97,7 @@ namespace Fungus
}
else if (variable.GetType() == typeof(FloatVariable))
{
float lhs = (variable as FloatVariable).Value;
float lhs = (variable as FloatVariable).value;
float rhs = floatData.Value;
switch (compareOperator)
@ -124,7 +124,7 @@ namespace Fungus
}
else if (variable.GetType() == typeof(StringVariable))
{
string lhs = (variable as StringVariable).Value;
string lhs = (variable as StringVariable).value;
string rhs = stringData.Value;
switch (compareOperator)

2
Assets/Fungus/FungusScript/Scripts/Commands/LoadGlobals.cs

@ -14,7 +14,7 @@ namespace Fungus
public override void OnEnter()
{
GlobalVariables.Load(saveName);
//GlobalVariables.Load(saveName);
Continue();
}

2
Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs

@ -21,7 +21,7 @@ namespace Fungus
{
if (variable != null)
{
variable.Value = Random.Range(minValue.Value, maxValue.Value);
variable.value = Random.Range(minValue.Value, maxValue.Value);
}
Continue();

2
Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs

@ -21,7 +21,7 @@ namespace Fungus
{
if (variable != null)
{
variable.Value = Random.Range(minValue.Value, maxValue.Value);
variable.value = Random.Range(minValue.Value, maxValue.Value);
}
Continue();

2
Assets/Fungus/FungusScript/Scripts/Commands/SaveGlobals.cs

@ -14,7 +14,7 @@ namespace Fungus
public override void OnEnter()
{
GlobalVariables.Save(saveName);
//GlobalVariables.Save(saveName);
Continue();
}

26
Assets/Fungus/FungusScript/Scripts/Commands/SetVariable.cs

@ -121,10 +121,10 @@ namespace Fungus
{
default:
case SetOperator.Assign:
lhs.Value = rhs;
lhs.value = rhs;
break;
case SetOperator.Negate:
lhs.Value = !rhs;
lhs.value = !rhs;
break;
}
}
@ -137,19 +137,19 @@ namespace Fungus
{
default:
case SetOperator.Assign:
lhs.Value = rhs;
lhs.value = rhs;
break;
case SetOperator.Add:
lhs.Value += rhs;
lhs.value += rhs;
break;
case SetOperator.Subtract:
lhs.Value -= rhs;
lhs.value -= rhs;
break;
case SetOperator.Multiply:
lhs.Value *= rhs;
lhs.value *= rhs;
break;
case SetOperator.Divide:
lhs.Value /= rhs;
lhs.value /= rhs;
break;
}
}
@ -162,19 +162,19 @@ namespace Fungus
{
default:
case SetOperator.Assign:
lhs.Value = rhs;
lhs.value = rhs;
break;
case SetOperator.Add:
lhs.Value += rhs;
lhs.value += rhs;
break;
case SetOperator.Subtract:
lhs.Value -= rhs;
lhs.value -= rhs;
break;
case SetOperator.Multiply:
lhs.Value *= rhs;
lhs.value *= rhs;
break;
case SetOperator.Divide:
lhs.Value /= rhs;
lhs.value /= rhs;
break;
}
}
@ -187,7 +187,7 @@ namespace Fungus
{
default:
case SetOperator.Assign:
lhs.Value = rhs;
lhs.value = rhs;
break;
}
}

21
Assets/Fungus/FungusScript/Scripts/FloatVariable.cs

@ -6,22 +6,23 @@ namespace Fungus
public class FloatVariable : Variable
{
protected float floatVal;
public float value;
public float Value
{
get { return (scope == VariableScope.Local) ? floatVal : GlobalVariables.GetFloat(key); }
set { if (scope == VariableScope.Local) { floatVal = value; } else { GlobalVariables.SetFloat(key, value); } }
}
protected float startValue;
public override void OnReset()
{
Value = 0;
value = startValue;
}
public override string ToString()
{
return Value.ToString();
return value.ToString();
}
protected virtual void Start()
{
startValue = value;
}
}
@ -36,8 +37,8 @@ namespace Fungus
public float Value
{
get { return (floatRef == null) ? floatVal : floatRef.Value; }
set { if (floatRef == null) { floatVal = value; } else { floatRef.Value = value; } }
get { return (floatRef == null) ? floatVal : floatRef.value; }
set { if (floatRef == null) { floatVal = value; } else { floatRef.value = value; } }
}
public string GetDescription()

37
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -264,6 +264,23 @@ namespace Fungus
}
}
/**
* Gets a list of all variables with public scope in this Fungus Script.
*/
public virtual List<Variable> GetPublicVariables()
{
List<Variable> publicVariables = new List<Variable>();
foreach (Variable v in variables)
{
if (v.scope == VariableScope.Public)
{
publicVariables.Add(v);
}
}
return publicVariables;
}
/**
* Gets the value of a boolean variable.
* Returns false if the variable key does not exist.
@ -277,7 +294,7 @@ namespace Fungus
BooleanVariable variable = v as BooleanVariable;
if (variable != null)
{
return variable.Value;
return variable.value;
}
}
}
@ -298,7 +315,7 @@ namespace Fungus
BooleanVariable variable = v as BooleanVariable;
if (variable != null)
{
variable.Value = value;
variable.value = value;
return;
}
}
@ -319,7 +336,7 @@ namespace Fungus
IntegerVariable variable = v as IntegerVariable;
if (variable != null)
{
return variable.Value;
return variable.value;
}
}
}
@ -340,7 +357,7 @@ namespace Fungus
IntegerVariable variable = v as IntegerVariable;
if (variable != null)
{
variable.Value = value;
variable.value = value;
return;
}
}
@ -361,7 +378,7 @@ namespace Fungus
FloatVariable variable = v as FloatVariable;
if (variable != null)
{
return variable.Value;
return variable.value;
}
}
}
@ -382,7 +399,7 @@ namespace Fungus
FloatVariable variable = v as FloatVariable;
if (variable != null)
{
variable.Value = value;
variable.value = value;
return;
}
}
@ -403,7 +420,7 @@ namespace Fungus
StringVariable variable = v as StringVariable;
if (variable != null)
{
return variable.Value;
return variable.value;
}
}
}
@ -424,7 +441,7 @@ namespace Fungus
StringVariable variable = v as StringVariable;
if (variable != null)
{
variable.Value = value;
variable.value = value;
return;
}
}
@ -505,12 +522,12 @@ namespace Fungus
foreach (Variable variable in variables)
{
if (resetLocalVariables &&
variable.scope == VariableScope.Local)
variable.scope == VariableScope.Private)
{
variable.OnReset();
}
else if (resetGlobalVariables &&
variable.scope == VariableScope.Global)
variable.scope == VariableScope.Public)
{
variable.OnReset();
}

289
Assets/Fungus/FungusScript/Scripts/GlobalVariables.cs

@ -1,289 +0,0 @@
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
#if !UNITY_WINRT
using System.Runtime.Serialization.Formatters.Binary;
#endif
using System.IO;
namespace Fungus
{
/**
* Static data storage class for managing global game variables.
* Provides save and load functionality for persistent storage between game sessions.
*/
public class GlobalVariables
{
protected static Dictionary<string, string> stringDict = new Dictionary<string, string>();
protected static Dictionary<string, int> intDict = new Dictionary<string, int>();
protected static Dictionary<string, float> floatDict = new Dictionary<string, float>();
protected static Dictionary<string, bool> boolDict = new Dictionary<string, bool>();
/**
* Save the variable dictionaries to persistent storage using a name tag.
*/
public static void Save(string saveName)
{
#if !UNITY_WINRT
// Save strings
{
var b = new BinaryFormatter();
var m = new MemoryStream();
b.Serialize(m, stringDict);
PlayerPrefs.SetString(saveName + "." + "stringDict", Convert.ToBase64String(m.GetBuffer()));
}
// Save ints
{
var b = new BinaryFormatter();
var m = new MemoryStream();
b.Serialize(m, intDict);
PlayerPrefs.SetString(saveName + "." + "intDict", Convert.ToBase64String(m.GetBuffer()));
}
// Save floats
{
var b = new BinaryFormatter();
var m = new MemoryStream();
b.Serialize(m, floatDict);
PlayerPrefs.SetString(saveName + "." + "floatDict", Convert.ToBase64String(m.GetBuffer()));
}
// Save bools
{
var b = new BinaryFormatter();
var m = new MemoryStream();
b.Serialize(m, boolDict);
PlayerPrefs.SetString(saveName + "." + "boolDict", Convert.ToBase64String(m.GetBuffer()));
}
PlayerPrefs.Save();
#endif
}
/**
* Loads the variable dictionaries from persistent storage using a name tag.
*/
public static void Load(string saveName)
{
#if !UNITY_WINRT
var stringData = PlayerPrefs.GetString(saveName + "." + "stringDict");
if (string.IsNullOrEmpty(stringData))
{
stringDict.Clear();
}
else
{
var b = new BinaryFormatter();
var m = new MemoryStream(Convert.FromBase64String(stringData));
stringDict = (Dictionary<string, string>)b.Deserialize(m);
}
var floatData = PlayerPrefs.GetString(saveName + "." + "floatDict");
if (!string.IsNullOrEmpty(floatData))
{
var b = new BinaryFormatter();
var m = new MemoryStream(Convert.FromBase64String(floatData));
floatDict = b.Deserialize(m) as Dictionary<string, float>;
}
var intData = PlayerPrefs.GetString(saveName + "." + "intDict");
if (!string.IsNullOrEmpty(intData))
{
var b = new BinaryFormatter();
var m = new MemoryStream(Convert.FromBase64String(intData));
intDict = b.Deserialize(m) as Dictionary<string, int>;
}
var boolData = PlayerPrefs.GetString(saveName + "." + "boolDict");
if (!string.IsNullOrEmpty(boolData))
{
var b = new BinaryFormatter();
var m = new MemoryStream(Convert.FromBase64String(boolData));
boolDict = b.Deserialize(m) as Dictionary<string, bool>;
}
#endif
}
/**
* Clears all stored variables.
*/
public static void ClearAll()
{
stringDict.Clear();
intDict.Clear();
floatDict.Clear();
boolDict.Clear();
}
/**
* Returns the float variable associated with the key.
*/
public static float GetFloat(string key)
{
if (String.IsNullOrEmpty(key) ||
!floatDict.ContainsKey(key))
{
return 0;
}
return floatDict[key];
}
/**
* Returns the integer variable associated with the key.
*/
public static int GetInteger(string key)
{
if (intDict == null)
{
Debug.Log ("Dict is null somehow");
}
if (String.IsNullOrEmpty(key) ||
!intDict.ContainsKey(key))
{
return 0;
}
return intDict[key];
}
/**
* Returns the boolean variable associated with the key.
*/
public static bool GetBoolean(string key)
{
if (String.IsNullOrEmpty(key) ||
!boolDict.ContainsKey(key))
{
return false;
}
return boolDict[key];
}
/**
* Returns the string variable associated with the key.
*/
public static string GetString(string key)
{
if (String.IsNullOrEmpty(key) ||
!stringDict.ContainsKey(key))
{
return "";
}
return stringDict[key];
}
/**
* Stores a float variable using the key.
*/
public static void SetFloat(string key, float value)
{
if (stringDict.ContainsKey(key) ||
intDict.ContainsKey(key) ||
boolDict.ContainsKey(key))
{
Debug.LogError("Key already in use with a string, integer or boolean variable");
return;
}
floatDict[key] = value;
}
/**
* Stores an integer variable using the key.
*/
public static void SetInteger(string key, int value)
{
if (stringDict.ContainsKey(key) ||
floatDict.ContainsKey(key) ||
boolDict.ContainsKey(key))
{
Debug.LogError("Key already in use with a string, float or boolean variable");
return;
}
intDict[key] = value;
}
/**
* Stores a boolean variable using the key.
*/
public static void SetBoolean(string key, bool value)
{
if (stringDict.ContainsKey(key) ||
floatDict.ContainsKey(key) ||
intDict.ContainsKey(key))
{
Debug.LogError("Key already in use with a string, float or integer variable");
return;
}
boolDict[key] = value;
}
/**
* Stores a string variable using the key.
*/
public static void SetString(string key, string value)
{
if (boolDict.ContainsKey(key) ||
floatDict.ContainsKey(key) ||
intDict.ContainsKey(key))
{
Debug.LogError("Key already in use with a boolean, float or integer variable");
return;
}
stringDict[key] = value;
}
/**
* Replace keys in the input string with the string table entry.
* Example format: "This {string_key} string"
*/
public static string SubstituteStrings(string text)
{
string subbedText = text;
// Instantiate the regular expression object.
Regex r = new Regex("{.*?}");
// Match the regular expression pattern against a text string.
var results = r.Matches(text);
foreach (Match match in results)
{
string stringKey = match.Value.Substring(1, match.Value.Length - 2);
string stringValue = GetString(stringKey);
subbedText = subbedText.Replace(match.Value, stringValue);
}
return subbedText;
}
/**
* Chops a string at the first new line character encountered.
* This is useful for link / button strings that must fit on a single line.
*/
public static string FormatLinkText(string text)
{
string trimmed;
if (text.Contains("\n"))
{
trimmed = text.Substring(0, text.IndexOf("\n"));
}
else
{
trimmed = text;
}
return trimmed;
}
}
}

8
Assets/Fungus/FungusScript/Scripts/GlobalVariables.cs.meta

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 718be5f6f7dc04ff48fa0232673c89c7
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

21
Assets/Fungus/FungusScript/Scripts/IntegerVariable.cs

@ -6,22 +6,23 @@ namespace Fungus
public class IntegerVariable : Variable
{
protected int integerVal;
public int value;
public int Value
{
get { return (scope == VariableScope.Local) ? integerVal : GlobalVariables.GetInteger(key); }
set { if (scope == VariableScope.Local) { integerVal = value; } else { GlobalVariables.SetInteger(key, value); } }
}
protected int startValue;
public override void OnReset()
{
Value = 0;
value = startValue;
}
public override string ToString()
{
return Value.ToString();
return value.ToString();
}
protected virtual void Start()
{
startValue = value;
}
}
@ -36,8 +37,8 @@ namespace Fungus
public int Value
{
get { return (integerRef == null) ? integerVal : integerRef.Value; }
set { if (integerRef == null) { integerVal = value; } else { integerRef.Value = value; } }
get { return (integerRef == null) ? integerVal : integerRef.value; }
set { if (integerRef == null) { integerVal = value; } else { integerRef.value = value; } }
}
public string GetDescription()

21
Assets/Fungus/FungusScript/Scripts/StringVariable.cs

@ -6,22 +6,23 @@ namespace Fungus
public class StringVariable : Variable
{
protected string stringVal;
public string value = "";
public string Value
{
get { return (scope == VariableScope.Local) ? stringVal : GlobalVariables.GetString(key); }
set { if (scope == VariableScope.Local) { stringVal = value; } else { GlobalVariables.SetString(key, value); } }
}
protected string startValue = "";
public override void OnReset()
{
Value = "";
value = startValue;
}
public override string ToString()
{
return Value.ToString();
return value.ToString();
}
protected virtual void Start()
{
startValue = value;
}
}
@ -36,8 +37,8 @@ namespace Fungus
public string Value
{
get { return (stringRef == null) ? stringVal : stringRef.Value; }
set { if (stringRef == null) { stringVal = value; } else { stringRef.Value = value; } }
get { return (stringRef == null) ? stringVal : stringRef.value; }
set { if (stringRef == null) { stringVal = value; } else { stringRef.value = value; } }
}
public string GetDescription()

3
Assets/Fungus/FungusScript/Scripts/StringsParser.cs

@ -89,7 +89,8 @@ namespace Fungus
// Trim off last newline
blockBuffer = blockBuffer.TrimEnd( '\r', '\n', ' ', '\t');
GlobalVariables.SetString(blockTag, blockBuffer);
// TODO: Store in a string table class
// GlobalVariables.SetString(blockTag, blockBuffer);
}
// Prepare to parse next block

4
Assets/Fungus/FungusScript/Scripts/Variable.cs

@ -14,8 +14,8 @@ namespace Fungus
public enum VariableScope
{
Local,
Global
Private,
Public
}
[RequireComponent(typeof(FungusScript))]

5
Assets/FungusExamples/Variables.meta

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 7edcd635d94d54fbfba3e0857c28711a
folderAsset: yes
DefaultImporter:
userData:

5
Assets/FungusExamples/Variables/Scenes.meta

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 7d99893813a4041129252f25633996f9
folderAsset: yes
DefaultImporter:
userData:

574
Assets/FungusExamples/Variables/Scenes/Variables.unity

@ -0,0 +1,574 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
SceneSettings:
m_ObjectHideFlags: 0
m_PVSData:
m_PVSObjectsArray: []
m_PVSPortalsArray: []
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: .25
backfaceThreshold: 100
--- !u!104 &2
RenderSettings:
m_Fog: 0
m_FogColor: {r: .5, g: .5, b: .5, a: 1}
m_FogMode: 3
m_FogDensity: .00999999978
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientLight: {r: .200000003, g: .200000003, b: .200000003, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: .5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 0}
m_ObjectHideFlags: 0
--- !u!127 &3
LevelGameManager:
m_ObjectHideFlags: 0
--- !u!157 &4
LightmapSettings:
m_ObjectHideFlags: 0
m_LightProbes: {fileID: 0}
m_Lightmaps: []
m_LightmapsMode: 1
m_BakedColorSpace: 0
m_UseDualLightmapsInForward: 0
m_LightmapEditorSettings:
m_Resolution: 50
m_LastUsedResolution: 0
m_TextureWidth: 1024
m_TextureHeight: 1024
m_BounceBoost: 1
m_BounceIntensity: 1
m_SkyLightColor: {r: .860000014, g: .930000007, b: 1, a: 1}
m_SkyLightIntensity: 0
m_Quality: 0
m_Bounces: 1
m_FinalGatherRays: 1000
m_FinalGatherContrastThreshold: .0500000007
m_FinalGatherGradientThreshold: 0
m_FinalGatherInterpolationPoints: 15
m_AOAmount: 0
m_AOMaxDistance: .100000001
m_AOContrast: 1
m_LODSurfaceMappingDistance: 1
m_Padding: 0
m_TextureCompression: 0
m_LockAtlas: 0
--- !u!196 &5
NavMeshSettings:
m_ObjectHideFlags: 0
m_BuildSettings:
agentRadius: .5
agentHeight: 2
agentSlope: 45
agentClimb: .400000006
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
accuratePlacement: 0
minRegionArea: 2
widthInaccuracy: 16.666666
heightInaccuracy: 10
m_NavMesh: {fileID: 0}
--- !u!1 &614879915
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 614879920}
- 20: {fileID: 614879919}
- 92: {fileID: 614879918}
- 124: {fileID: 614879917}
- 81: {fileID: 614879916}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &614879916
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 614879915}
m_Enabled: 1
--- !u!124 &614879917
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 614879915}
m_Enabled: 1
--- !u!92 &614879918
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 614879915}
m_Enabled: 1
--- !u!20 &614879919
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 614879915}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: .300000012
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_HDR: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: .0219999999
--- !u!4 &614879920
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 614879915}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!1 &1092127452
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 1092127458}
- 114: {fileID: 1092127457}
- 114: {fileID: 1092127456}
- 114: {fileID: 1092127455}
- 114: {fileID: 1092127454}
- 114: {fileID: 1092127453}
m_Layer: 0
m_Name: BlueScript
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1092127453
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1092127452}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70c5622b8a80845c980954170295f292, type: 3}
m_Name:
m_EditorClassIdentifier:
errorMessage:
indentLevel: 0
variable: {fileID: 1269704317}
compareOperator: 0
booleanData:
booleanRef: {fileID: 0}
booleanVal: 0
integerData:
integerRef: {fileID: 0}
integerVal: 0
floatData:
floatRef: {fileID: 0}
floatVal: 0
stringData:
stringRef: {fileID: 0}
stringVal:
--- !u!114 &1092127454
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1092127452}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fb77d0ce495044f6e9feb91b31798e8c, type: 3}
m_Name:
m_EditorClassIdentifier:
errorMessage:
indentLevel: 0
variable: {fileID: 1269704325}
setOperator: 0
booleanData:
booleanRef: {fileID: 0}
booleanVal: 0
integerData:
integerRef: {fileID: 0}
integerVal: 0
floatData:
floatRef: {fileID: 0}
floatVal: 0
stringData:
stringRef: {fileID: 0}
stringVal:
--- !u!114 &1092127455
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1092127452}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d2f6487d21a03404cb21b245f0242e79, type: 3}
m_Name:
m_EditorClassIdentifier:
parentSequence: {fileID: 1092127456}
--- !u!114 &1092127456
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1092127452}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3d3d73aef2cfc4f51abf34ac00241f60, type: 3}
m_Name:
m_EditorClassIdentifier:
nodeRect:
serializedVersion: 2
x: 233
y: -64
width: 121
height: 40
sequenceName: Sequence
description:
runSlowInEditor: 1
eventHandler: {fileID: 1092127455}
commandList:
- {fileID: 1092127454}
- {fileID: 1092127453}
--- !u!114 &1092127457
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1092127452}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a334fe2ffb574b3583ff3b18b4792d3, type: 3}
m_Name:
m_EditorClassIdentifier:
scrollPos: {x: 174, y: 126}
variablesScrollPos: {x: 0, y: 0}
variablesExpanded: 1
zoom: 1
scrollViewRect:
serializedVersion: 2
x: -340
y: -464
width: 1213
height: 999
selectedSequence: {fileID: 1092127456}
selectedCommands:
- {fileID: 1092127453}
variables: []
description:
runSlowDuration: .25
colorCommands: 1
hideComponents: 1
--- !u!4 &1092127458
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1092127452}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
--- !u!1 &1269704314
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 1269704320}
- 114: {fileID: 1269704319}
- 114: {fileID: 1269704318}
- 114: {fileID: 1269704317}
- 114: {fileID: 1269704316}
- 114: {fileID: 1269704315}
- 114: {fileID: 1269704323}
- 114: {fileID: 1269704322}
- 114: {fileID: 1269704321}
- 114: {fileID: 1269704324}
- 114: {fileID: 1269704325}
m_Layer: 0
m_Name: RedScript
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1269704315
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4580f28dd8581476b810b38eea2f1316, type: 3}
m_Name:
m_EditorClassIdentifier:
scope: 1
key: MyString
value: I'm happy
--- !u!114 &1269704316
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 705fa1ac97df74e3a84ff952ffd923f1, type: 3}
m_Name:
m_EditorClassIdentifier:
scope: 0
key: MyFloat
value: 10
--- !u!114 &1269704317
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5d02d9822eec54c98afe95bb497211b3, type: 3}
m_Name:
m_EditorClassIdentifier:
scope: 1
key: MyBool
value: 1
--- !u!114 &1269704318
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3d3d73aef2cfc4f51abf34ac00241f60, type: 3}
m_Name:
m_EditorClassIdentifier:
nodeRect:
serializedVersion: 2
x: 349
y: 4
width: 121
height: 40
sequenceName: Sequence
description:
runSlowInEditor: 1
eventHandler: {fileID: 1269704323}
commandList:
- {fileID: 1269704324}
- {fileID: 1269704322}
- {fileID: 1269704321}
--- !u!114 &1269704319
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a334fe2ffb574b3583ff3b18b4792d3, type: 3}
m_Name:
m_EditorClassIdentifier:
scrollPos: {x: 145, y: 93}
variablesScrollPos: {x: 0, y: 0}
variablesExpanded: 1
zoom: 1
scrollViewRect:
serializedVersion: 2
x: -340
y: -396
width: 1213
height: 931
selectedSequence: {fileID: 0}
selectedCommands: []
variables:
- {fileID: 1269704317}
- {fileID: 1269704316}
- {fileID: 1269704315}
- {fileID: 1269704325}
description:
runSlowDuration: .25
colorCommands: 1
hideComponents: 1
--- !u!4 &1269704320
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
--- !u!114 &1269704321
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2fab8abf0343545abbfebd9a7b7b34bd, type: 3}
m_Name:
m_EditorClassIdentifier:
errorMessage:
indentLevel: 0
logType: 0
logMessage:
stringRef: {fileID: 0}
stringVal: Float {$MyFloat}
--- !u!114 &1269704322
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2fab8abf0343545abbfebd9a7b7b34bd, type: 3}
m_Name:
m_EditorClassIdentifier:
errorMessage:
indentLevel: 0
logType: 0
logMessage:
stringRef: {fileID: 0}
stringVal: Bool {$MyBool}
--- !u!114 &1269704323
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d2f6487d21a03404cb21b245f0242e79, type: 3}
m_Name:
m_EditorClassIdentifier:
parentSequence: {fileID: 1269704318}
--- !u!114 &1269704324
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fb77d0ce495044f6e9feb91b31798e8c, type: 3}
m_Name:
m_EditorClassIdentifier:
errorMessage:
indentLevel: 0
variable: {fileID: 1269704317}
setOperator: 0
booleanData:
booleanRef: {fileID: 0}
booleanVal: 0
integerData:
integerRef: {fileID: 0}
integerVal: 0
floatData:
floatRef: {fileID: 0}
floatVal: 0
stringData:
stringRef: {fileID: 0}
stringVal:
--- !u!114 &1269704325
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1269704314}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: afb91b566ceda411bad1e9d3c3243ecc, type: 3}
m_Name:
m_EditorClassIdentifier:
scope: 1
key: Var
value: 0
--- !u!1 &1671111970
GameObject:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 1671111972}
- 114: {fileID: 1671111971}
m_Layer: 0
m_Name: _FungusState
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1671111971
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1671111970}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 61dddfdc5e0e44ca298d8f46f7f5a915, type: 3}
m_Name:
m_EditorClassIdentifier:
selectedFungusScript: {fileID: 1269704319}
--- !u!4 &1671111972
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1671111970}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0

4
Assets/FungusExamples/Variables/Scenes/Variables.unity.meta

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 67781f5c55aad43f7b31def1ca85efb4
DefaultImporter:
userData:
Loading…
Cancel
Save