Browse Source

Change #66 User extendible variables system

Added Other category for non-core variable types.
Wider variable window to fit long type names.
Use internal editor component paste instead of reflection to paste
commands
SetVariable only supports 4 basic variable types.
Simplified definition for new variable types.
Added new variable types to support core Unity types.
master
chrisgregan 10 years ago
parent
commit
e07a227aa0
  1. 78
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  2. 2
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs
  3. 26
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  4. 7
      Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs
  5. 275
      Assets/Fungus/FungusScript/Editor/VariableEditor.cs
  6. 22
      Assets/Fungus/FungusScript/Editor/VariableListAdaptor.cs
  7. 2
      Assets/Fungus/FungusScript/Scripts/Commands/SetVariable.cs
  8. 3
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  9. 52
      Assets/Fungus/FungusScript/Scripts/Variable.cs
  10. 5
      Assets/Fungus/FungusScript/Scripts/VariableTypes.meta
  11. 26
      Assets/Fungus/FungusScript/Scripts/VariableTypes/BooleanVariable.cs
  12. 0
      Assets/Fungus/FungusScript/Scripts/VariableTypes/BooleanVariable.cs.meta
  13. 38
      Assets/Fungus/FungusScript/Scripts/VariableTypes/ColorVariable.cs
  14. 8
      Assets/Fungus/FungusScript/Scripts/VariableTypes/ColorVariable.cs.meta
  15. 27
      Assets/Fungus/FungusScript/Scripts/VariableTypes/FloatVariable.cs
  16. 0
      Assets/Fungus/FungusScript/Scripts/VariableTypes/FloatVariable.cs.meta
  17. 38
      Assets/Fungus/FungusScript/Scripts/VariableTypes/GameObjectVariable.cs
  18. 8
      Assets/Fungus/FungusScript/Scripts/VariableTypes/GameObjectVariable.cs.meta
  19. 27
      Assets/Fungus/FungusScript/Scripts/VariableTypes/IntegerVariable.cs
  20. 0
      Assets/Fungus/FungusScript/Scripts/VariableTypes/IntegerVariable.cs.meta
  21. 38
      Assets/Fungus/FungusScript/Scripts/VariableTypes/MaterialVariable.cs
  22. 8
      Assets/Fungus/FungusScript/Scripts/VariableTypes/MaterialVariable.cs.meta
  23. 38
      Assets/Fungus/FungusScript/Scripts/VariableTypes/ObjectVariable.cs
  24. 8
      Assets/Fungus/FungusScript/Scripts/VariableTypes/ObjectVariable.cs.meta
  25. 38
      Assets/Fungus/FungusScript/Scripts/VariableTypes/SpriteVariable.cs
  26. 8
      Assets/Fungus/FungusScript/Scripts/VariableTypes/SpriteVariable.cs.meta
  27. 26
      Assets/Fungus/FungusScript/Scripts/VariableTypes/StringVariable.cs
  28. 0
      Assets/Fungus/FungusScript/Scripts/VariableTypes/StringVariable.cs.meta
  29. 38
      Assets/Fungus/FungusScript/Scripts/VariableTypes/TextureVariable.cs
  30. 8
      Assets/Fungus/FungusScript/Scripts/VariableTypes/TextureVariable.cs.meta
  31. 38
      Assets/Fungus/FungusScript/Scripts/VariableTypes/Vector2Variable.cs
  32. 8
      Assets/Fungus/FungusScript/Scripts/VariableTypes/Vector2Variable.cs.meta
  33. 38
      Assets/Fungus/FungusScript/Scripts/VariableTypes/Vector3Variable.cs
  34. 8
      Assets/Fungus/FungusScript/Scripts/VariableTypes/Vector3Variable.cs.meta

78
Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs

@ -4,12 +4,19 @@ using System.Collections;
using System.Collections.Generic;
using Rotorz.ReorderableList;
using System.Linq;
using System.Reflection;
namespace Fungus
{
[CustomEditor (typeof(FungusScript))]
public class FungusScriptEditor : Editor
{
protected class AddVariableInfo
{
public FungusScript fungusScript;
public System.Type variableType;
}
protected SerializedProperty descriptionProp;
protected SerializedProperty colorCommandsProp;
protected SerializedProperty hideComponentsProp;
@ -118,10 +125,45 @@ namespace Fungus
{
GenericMenu menu = new GenericMenu ();
menu.AddItem(new GUIContent ("Boolean"), false, AddVariable<BooleanVariable>, t);
menu.AddItem (new GUIContent ("Integer"), false, AddVariable<IntegerVariable>, t);
menu.AddItem (new GUIContent ("Float"), false, AddVariable<FloatVariable>, t);
menu.AddItem (new GUIContent ("String"), false, AddVariable<StringVariable>, t);
List<System.Type> types = FindAllDerivedTypes<Variable>();
// Add variable types without a category
foreach (System.Type type in types)
{
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
if (variableInfo == null ||
variableInfo.Category != "")
{
continue;
}
AddVariableInfo addVariableInfo = new AddVariableInfo();
addVariableInfo.fungusScript = t;
addVariableInfo.variableType = type;
GUIContent typeName = new GUIContent(variableInfo.VariableType);
menu.AddItem(typeName, false, AddVariable, addVariableInfo);
}
// Add types with a category
foreach (System.Type type in types)
{
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
if (variableInfo == null ||
variableInfo.Category == "")
{
continue;
}
AddVariableInfo info = new AddVariableInfo();
info.fungusScript = t;
info.variableType = type;
GUIContent typeName = new GUIContent(variableInfo.Category + "/" + variableInfo.VariableType);
menu.AddItem(typeName, false, AddVariable, info);
}
menu.ShowAsContext ();
}
@ -130,19 +172,39 @@ namespace Fungus
serializedObject.ApplyModifiedProperties();
}
protected virtual void AddVariable<T>(object obj) where T : Variable
protected virtual void AddVariable(object obj)
{
FungusScript fungusScript = obj as FungusScript;
if (fungusScript == null)
AddVariableInfo addVariableInfo = obj as AddVariableInfo;
if (addVariableInfo == null)
{
return;
}
FungusScript fungusScript = addVariableInfo.fungusScript;
System.Type variableType = addVariableInfo.variableType;
Undo.RecordObject(fungusScript, "Add Variable");
T newVariable = fungusScript.gameObject.AddComponent<T>();
Variable newVariable = fungusScript.gameObject.AddComponent(variableType) as Variable;
newVariable.key = fungusScript.GetUniqueVariableKey("");
fungusScript.variables.Add(newVariable);
}
public static List<System.Type> FindAllDerivedTypes<T>()
{
return FindAllDerivedTypes<T>(Assembly.GetAssembly(typeof(T)));
}
public static List<System.Type> FindAllDerivedTypes<T>(Assembly assembly)
{
var derivedType = typeof(T);
return assembly
.GetTypes()
.Where(t =>
t != derivedType &&
derivedType.IsAssignableFrom(t)
).ToList();
}
}
}

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

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

26
Assets/Fungus/FungusScript/Editor/SequenceEditor.cs

@ -1,4 +1,5 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System;
using System.Collections;
@ -580,18 +581,23 @@ namespace Fungus
foreach (Command command in commandCopyBuffer.GetCommands())
{
System.Type type = command.GetType();
Command newCommand = Undo.AddComponent(fungusScript.selectedSequence.gameObject, type) as Command;
newCommand.parentSequence = fungusScript.selectedSequence;
System.Reflection.FieldInfo[] fields = type.GetFields();
foreach (System.Reflection.FieldInfo field in fields)
// Using the Editor copy / paste functionality instead instead of reflection
// because this does a deep copy of the command properties.
if (ComponentUtility.CopyComponent(command))
{
field.SetValue(newCommand, field.GetValue(command));
}
if (ComponentUtility.PasteComponentAsNew(fungusScript.gameObject))
{
Command[] commands = fungusScript.GetComponents<Command>();
Command pastedCommand = commands.Last<Command>();
if (pastedCommand != null)
{
fungusScript.selectedSequence.commandList.Insert(pasteIndex++, pastedCommand);
}
}
Undo.RecordObject(fungusScript.selectedSequence, "Paste");
fungusScript.selectedSequence.commandList.Insert(pasteIndex++, newCommand);
// This stops the user pasting the command manually into another game object.
ComponentUtility.CopyComponent(fungusScript.transform);
}
}
Repaint();

7
Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs

@ -40,8 +40,11 @@ namespace Fungus
VariableEditor.VariableField(variableProp,
new GUIContent("Set Variable", "Variable to set"),
fungusScript);
fungusScript,
(v) => (v.GetType() == typeof(BooleanVariable) ||
v.GetType() == typeof(IntegerVariable) ||
v.GetType() == typeof(FloatVariable) ||
v.GetType() == typeof(StringVariable)));
if (variableProp.objectReferenceValue == null)
{

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

@ -17,6 +17,21 @@ namespace Fungus
t.hideFlags = HideFlags.HideInInspector;
}
public static VariableInfoAttribute GetVariableInfo(System.Type variableType)
{
object[] attributes = variableType.GetCustomAttributes(typeof(VariableInfoAttribute), false);
foreach (object obj in attributes)
{
VariableInfoAttribute variableInfoAttr = obj as VariableInfoAttribute;
if (variableInfoAttr != null)
{
return variableInfoAttr;
}
}
return null;
}
static public void VariableField(SerializedProperty property, GUIContent label, FungusScript fungusScript, Func<Variable, bool> filter = null)
{
List<string> variableKeys = new List<string>();
@ -81,166 +96,32 @@ namespace Fungus
}
}
[CustomPropertyDrawer (typeof(BooleanData))]
public class BooleanDataDrawer : PropertyDrawer
public class VariableDataDrawer<T> : PropertyDrawer where T : Variable
{
protected enum BooleanState
{
True,
False
}
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
SerializedProperty referenceProp = property.FindPropertyRelative("booleanRef");
SerializedProperty valueProp = property.FindPropertyRelative("booleanVal");
const int popupWidth = 65;
// The variable reference and data properties must follow the naming convention 'typeRef', 'typeVal'
Rect controlRect = EditorGUI.PrefixLabel(position, label);
Rect valueRect = controlRect;
valueRect.width = controlRect.width - popupWidth - 5;
Rect popupRect = controlRect;
if (referenceProp.objectReferenceValue == null)
VariableInfoAttribute typeInfo = VariableEditor.GetVariableInfo(typeof(T));
if (typeInfo == null)
{
valueProp.boolValue = ((BooleanState)EditorGUI.EnumPopup(valueRect, valueProp.boolValue ? BooleanState.True : BooleanState.False) == BooleanState.True);
popupRect.x += valueRect.width + 5;
popupRect.width = popupWidth;
return;
}
FungusScript fungusScript = property.serializedObject.targetObject as FungusScript;
if (fungusScript == null)
{
Command command = property.serializedObject.targetObject as Command;
if (command != null)
{
fungusScript = command.GetFungusScript();
}
}
if (fungusScript != null)
{
BooleanVariable selectedBooleanVariable = referenceProp.objectReferenceValue as BooleanVariable;
List<string> variableKeys = new List<string>();
List<Variable> variableObjects = new List<Variable>();
variableKeys.Add("<Value>");
variableObjects.Add(null);
int index = 0;
int selectedIndex = 0;
foreach (Variable v in fungusScript.variables)
{
if (v.GetType() != typeof(BooleanVariable))
{
continue;
}
string propNameBase = typeInfo.VariableType;
propNameBase = Char.ToLowerInvariant(propNameBase[0]) + propNameBase.Substring(1);
variableKeys.Add(v.key);
variableObjects.Add(v);
SerializedProperty referenceProp = property.FindPropertyRelative(propNameBase + "Ref");
SerializedProperty valueProp = property.FindPropertyRelative(propNameBase + "Val");
index++;
if (v == selectedBooleanVariable)
{
selectedIndex = index;
}
}
selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray());
referenceProp.objectReferenceValue = variableObjects[selectedIndex];
}
EditorGUI.EndProperty();
}
}
[CustomPropertyDrawer (typeof(IntegerData))]
public class IntegerDataDrawer : PropertyDrawer
{
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
SerializedProperty referenceProp = property.FindPropertyRelative("integerRef");
SerializedProperty valueProp = property.FindPropertyRelative("integerVal");
const int popupWidth = 65;
Rect controlRect = EditorGUI.PrefixLabel(position, label);
Rect valueRect = controlRect;
valueRect.width = controlRect.width - popupWidth - 5;
Rect popupRect = controlRect;
if (referenceProp.objectReferenceValue == null)
{
valueProp.intValue = EditorGUI.IntField(valueRect, valueProp.intValue);
popupRect.x += valueRect.width + 5;
popupRect.width = popupWidth;
}
FungusScript fungusScript = property.serializedObject.targetObject as FungusScript;
if (fungusScript == null)
if (referenceProp == null || valueProp == null)
{
Command command = property.serializedObject.targetObject as Command;
if (command != null)
{
fungusScript = command.GetFungusScript();
}
return;
}
if (fungusScript != null)
{
IntegerVariable selectedVariable = referenceProp.objectReferenceValue as IntegerVariable;
List<string> variableKeys = new List<string>();
List<Variable> variableObjects = new List<Variable>();
variableKeys.Add("<Value>");
variableObjects.Add(null);
int index = 0;
int selectedIndex = 0;
foreach (Variable v in fungusScript.variables)
{
if (v.GetType() != typeof(IntegerVariable))
{
continue;
}
variableKeys.Add(v.key);
variableObjects.Add(v);
index++;
if (v == selectedVariable)
{
selectedIndex = index;
}
}
selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray());
referenceProp.objectReferenceValue = variableObjects[selectedIndex];
}
EditorGUI.EndProperty();
}
}
[CustomPropertyDrawer (typeof(FloatData))]
public class FloatDataDrawer : PropertyDrawer
{
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
SerializedProperty referenceProp = property.FindPropertyRelative("floatRef");
SerializedProperty valueProp = property.FindPropertyRelative("floatVal");
const int popupWidth = 65;
Rect controlRect = EditorGUI.PrefixLabel(position, label);
@ -250,7 +131,7 @@ namespace Fungus
if (referenceProp.objectReferenceValue == null)
{
valueProp.floatValue = EditorGUI.FloatField(valueRect, valueProp.floatValue);
EditorGUI.PropertyField(valueRect, valueProp, new GUIContent(""));
popupRect.x += valueRect.width + 5;
popupRect.width = popupWidth;
}
@ -267,7 +148,7 @@ namespace Fungus
if (fungusScript != null)
{
FloatVariable selectedVariable = referenceProp.objectReferenceValue as FloatVariable;
T selectedVariable = referenceProp.objectReferenceValue as T;
List<string> variableKeys = new List<string>();
List<Variable> variableObjects = new List<Variable>();
@ -279,7 +160,7 @@ namespace Fungus
int selectedIndex = 0;
foreach (Variable v in fungusScript.variables)
{
if (v.GetType() != typeof(FloatVariable))
if (v.GetType() != typeof(T))
{
continue;
}
@ -303,77 +184,51 @@ namespace Fungus
}
}
[CustomPropertyDrawer (typeof(StringData))]
public class StringDataDrawer : PropertyDrawer
{
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
SerializedProperty referenceProp = property.FindPropertyRelative("stringRef");
SerializedProperty valueProp = property.FindPropertyRelative("stringVal");
const int popupWidth = 65;
Rect controlRect = EditorGUI.PrefixLabel(position, label);
Rect valueRect = controlRect;
valueRect.width = controlRect.width - popupWidth - 5;
Rect popupRect = controlRect;
if (referenceProp.objectReferenceValue == null)
{
// StringData stringData = valueProp.serializedObject
valueProp.stringValue = EditorGUI.TextField(valueRect, valueProp.stringValue);
popupRect.x += valueRect.width + 5;
popupRect.width = popupWidth;
}
[CustomPropertyDrawer (typeof(BooleanData))]
public class BooleanDataDrawer : VariableDataDrawer<BooleanVariable>
{}
FungusScript fungusScript = property.serializedObject.targetObject as FungusScript;
if (fungusScript == null)
{
Command command = property.serializedObject.targetObject as Command;
if (command != null)
{
fungusScript = command.GetFungusScript();
}
}
[CustomPropertyDrawer (typeof(IntegerData))]
public class IntegerDataDrawer : VariableDataDrawer<IntegerVariable>
{}
if (fungusScript != null)
{
StringVariable selectedVariable = referenceProp.objectReferenceValue as StringVariable;
[CustomPropertyDrawer (typeof(FloatData))]
public class FloatDataDrawer : VariableDataDrawer<FloatVariable>
{}
List<string> variableKeys = new List<string>();
List<Variable> variableObjects = new List<Variable>();
[CustomPropertyDrawer (typeof(StringData))]
public class StringDataDrawer : VariableDataDrawer<StringVariable>
{}
variableKeys.Add("<Value>");
variableObjects.Add(null);
[CustomPropertyDrawer (typeof(ColorData))]
public class ColorDataDrawer : VariableDataDrawer<ColorVariable>
{}
int index = 0;
int selectedIndex = 0;
foreach (Variable v in fungusScript.variables)
{
if (v.GetType() != typeof(StringVariable))
{
continue;
}
[CustomPropertyDrawer (typeof(Vector2Data))]
public class Vector2DataDrawer : VariableDataDrawer<Vector2Variable>
{}
variableKeys.Add(v.key);
variableObjects.Add(v);
[CustomPropertyDrawer (typeof(Vector3Data))]
public class Vector3DataDrawer : VariableDataDrawer<Vector3Variable>
{}
index++;
[CustomPropertyDrawer (typeof(MaterialData))]
public class MaterialDataDrawer : VariableDataDrawer<MaterialVariable>
{}
if (v == selectedVariable)
{
selectedIndex = index;
}
}
[CustomPropertyDrawer (typeof(TextureData))]
public class TextureDataDrawer : VariableDataDrawer<TextureVariable>
{}
selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray());
referenceProp.objectReferenceValue = variableObjects[selectedIndex];
}
[CustomPropertyDrawer (typeof(SpriteData))]
public class SpriteDataDrawer : VariableDataDrawer<SpriteVariable>
{}
EditorGUI.EndProperty();
}
}
[CustomPropertyDrawer (typeof(GameObjectData))]
public class GameObjectDataDrawer : VariableDataDrawer<GameObjectVariable>
{}
[CustomPropertyDrawer (typeof(ObjectData))]
public class ObjectDataDrawer : VariableDataDrawer<ObjectVariable>
{}
}

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

@ -91,7 +91,7 @@ namespace Fungus
return;
}
float[] widths = { 50, 100, 130, 60 };
float[] widths = { 80, 100, 140, 60 };
Rect[] rects = new Rect[4];
for (int i = 0; i < 4; ++i)
@ -105,22 +105,10 @@ namespace Fungus
}
}
string type = "";
if (variable.GetType() == typeof(BooleanVariable))
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(variable.GetType());
if (variableInfo == null)
{
type = "Boolean";
}
else if (variable.GetType() == typeof(IntegerVariable))
{
type = "Integer";
}
else if (variable.GetType() == typeof(FloatVariable))
{
type = "Float";
}
else if (variable.GetType() == typeof(StringVariable))
{
type = "String";
return;
}
FungusScript fungusScript = FungusScriptWindow.GetFungusScript();
@ -165,7 +153,7 @@ namespace Fungus
variableObject.Update();
GUI.Label(rects[0], type);
GUI.Label(rects[0], variableInfo.VariableType);
key = EditorGUI.TextField(rects[1], variable.key);
SerializedProperty keyProp = variableObject.FindProperty("key");

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

@ -5,7 +5,7 @@ namespace Fungus
{
[CommandInfo("Scripting",
"Set Variable",
"Sets a variable to a new value using simple arithmetic operations. The value can be a constant or another variable.")]
"Sets a Boolean, Integer, Float or String variable to a new value using a simple arithmetic operation. The value can be a constant or reference another variable of the same type.")]
public class SetVariable : Command
{
public enum SetOperator

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

@ -200,7 +200,8 @@ namespace Fungus
bool collision = false;
foreach(Variable variable in variables)
{
if (variable == ignoreVariable ||
if (variable == null ||
variable == ignoreVariable ||
variable.key == null)
{
continue;

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

@ -1,30 +1,60 @@
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Fungus
{
public enum VariableType
{
Boolean,
Integer,
Float,
String
}
public enum VariableScope
{
Private,
Public
}
public class VariableInfoAttribute : Attribute
{
public VariableInfoAttribute(string category, string variableType, int order = 0)
{
this.Category = category;
this.VariableType = variableType;
this.Order = order;
}
public string Category { get; set; }
public string VariableType { get; set; }
public int Order { get; set; }
}
[RequireComponent(typeof(FungusScript))]
public class Variable : MonoBehaviour
public abstract class Variable : MonoBehaviour
{
public VariableScope scope;
public string key = "";
public virtual void OnReset()
{}
public abstract void OnReset();
}
public abstract class VariableBase<T> : Variable
{
public T value;
protected T startValue;
public override void OnReset()
{
value = startValue;
}
public override string ToString()
{
return value.ToString();
}
protected virtual void Start()
{
// Remember the initial value so we can reset later on
startValue = value;
}
}
}

5
Assets/Fungus/FungusScript/Scripts/VariableTypes.meta

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

26
Assets/Fungus/FungusScript/Scripts/BooleanVariable.cs → Assets/Fungus/FungusScript/Scripts/VariableTypes/BooleanVariable.cs

@ -5,30 +5,12 @@ using System.Collections;
namespace Fungus
{
public class BooleanVariable : Variable
{
public bool value;
protected bool startValue;
public override void OnReset()
{
value = startValue;
}
public override string ToString()
{
return value.ToString();
}
protected virtual void Start()
{
startValue = value;
}
}
[VariableInfo("", "Boolean")]
public class BooleanVariable : VariableBase<bool>
{}
[System.Serializable]
public struct BooleanData
public class BooleanData
{
[SerializeField]
public BooleanVariable booleanRef;

0
Assets/Fungus/FungusScript/Scripts/BooleanVariable.cs.meta → Assets/Fungus/FungusScript/Scripts/VariableTypes/BooleanVariable.cs.meta

38
Assets/Fungus/FungusScript/Scripts/VariableTypes/ColorVariable.cs

@ -0,0 +1,38 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
[VariableInfo("Other", "Color")]
public class ColorVariable : VariableBase<Color>
{}
[System.Serializable]
public class ColorData
{
[SerializeField]
public ColorVariable colorRef;
[SerializeField]
public Color colorVal;
public Color Value
{
get { return (colorRef == null) ? colorVal : colorRef.value; }
set { if (colorRef == null) { colorVal = value; } else { colorRef.value = value; } }
}
public string GetDescription()
{
if (colorRef == null)
{
return colorVal.ToString();
}
else
{
return colorRef.key;
}
}
}
}

8
Assets/Fungus/FungusScript/Scripts/VariableTypes/ColorVariable.cs.meta

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

27
Assets/Fungus/FungusScript/Scripts/FloatVariable.cs → Assets/Fungus/FungusScript/Scripts/VariableTypes/FloatVariable.cs

@ -3,31 +3,12 @@ using System.Collections;
namespace Fungus
{
public class FloatVariable : Variable
{
public float value;
protected float startValue;
public override void OnReset()
{
value = startValue;
}
public override string ToString()
{
return value.ToString();
}
protected virtual void Start()
{
startValue = value;
}
}
[VariableInfo("", "Float")]
public class FloatVariable : VariableBase<float>
{}
[System.Serializable]
public struct FloatData
public class FloatData
{
[SerializeField]
public FloatVariable floatRef;

0
Assets/Fungus/FungusScript/Scripts/FloatVariable.cs.meta → Assets/Fungus/FungusScript/Scripts/VariableTypes/FloatVariable.cs.meta

38
Assets/Fungus/FungusScript/Scripts/VariableTypes/GameObjectVariable.cs

@ -0,0 +1,38 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
[VariableInfo("Other", "GameObject")]
public class GameObjectVariable : VariableBase<GameObject>
{}
[System.Serializable]
public class GameObjectData
{
[SerializeField]
public GameObjectVariable gameObjectRef;
[SerializeField]
public GameObject gameObjectVal;
public GameObject Value
{
get { return (gameObjectRef == null) ? gameObjectVal : gameObjectRef.value; }
set { if (gameObjectRef == null) { gameObjectVal = value; } else { gameObjectRef.value = value; } }
}
public string GetDescription()
{
if (gameObjectRef == null)
{
return gameObjectVal.ToString();
}
else
{
return gameObjectRef.key;
}
}
}
}

8
Assets/Fungus/FungusScript/Scripts/VariableTypes/GameObjectVariable.cs.meta

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

27
Assets/Fungus/FungusScript/Scripts/IntegerVariable.cs → Assets/Fungus/FungusScript/Scripts/VariableTypes/IntegerVariable.cs

@ -3,31 +3,12 @@ using System.Collections;
namespace Fungus
{
public class IntegerVariable : Variable
{
public int value;
protected int startValue;
public override void OnReset()
{
value = startValue;
}
public override string ToString()
{
return value.ToString();
}
protected virtual void Start()
{
startValue = value;
}
}
[VariableInfo("", "Integer")]
public class IntegerVariable : VariableBase<int>
{}
[System.Serializable]
public struct IntegerData
public class IntegerData
{
[SerializeField]
public IntegerVariable integerRef;

0
Assets/Fungus/FungusScript/Scripts/IntegerVariable.cs.meta → Assets/Fungus/FungusScript/Scripts/VariableTypes/IntegerVariable.cs.meta

38
Assets/Fungus/FungusScript/Scripts/VariableTypes/MaterialVariable.cs

@ -0,0 +1,38 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
[VariableInfo("Other", "Material")]
public class MaterialVariable : VariableBase<Material>
{}
[System.Serializable]
public class MaterialData
{
[SerializeField]
public MaterialVariable materialRef;
[SerializeField]
public Material materialVal;
public Material Value
{
get { return (materialRef == null) ? materialVal : materialRef.value; }
set { if (materialRef == null) { materialVal = value; } else { materialRef.value = value; } }
}
public string GetDescription()
{
if (materialRef == null)
{
return materialVal.ToString();
}
else
{
return materialRef.key;
}
}
}
}

8
Assets/Fungus/FungusScript/Scripts/VariableTypes/MaterialVariable.cs.meta

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

38
Assets/Fungus/FungusScript/Scripts/VariableTypes/ObjectVariable.cs

@ -0,0 +1,38 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
[VariableInfo("Other", "Object")]
public class ObjectVariable : VariableBase<Object>
{}
[System.Serializable]
public class ObjectData
{
[SerializeField]
public ObjectVariable objectRef;
[SerializeField]
public Object objectVal;
public Object Value
{
get { return (objectRef == null) ? objectVal : objectRef.value; }
set { if (objectRef == null) { objectVal = value; } else { objectRef.value = value; } }
}
public string GetDescription()
{
if (objectRef == null)
{
return objectVal.ToString();
}
else
{
return objectRef.key;
}
}
}
}

8
Assets/Fungus/FungusScript/Scripts/VariableTypes/ObjectVariable.cs.meta

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

38
Assets/Fungus/FungusScript/Scripts/VariableTypes/SpriteVariable.cs

@ -0,0 +1,38 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
[VariableInfo("Other", "Sprite")]
public class SpriteVariable : VariableBase<Sprite>
{}
[System.Serializable]
public class SpriteData
{
[SerializeField]
public SpriteVariable spriteRef;
[SerializeField]
public Sprite spriteVal;
public Sprite Value
{
get { return (spriteRef == null) ? spriteVal : spriteRef.value; }
set { if (spriteRef == null) { spriteVal = value; } else { spriteRef.value = value; } }
}
public string GetDescription()
{
if (spriteRef == null)
{
return spriteVal.ToString();
}
else
{
return spriteRef.key;
}
}
}
}

8
Assets/Fungus/FungusScript/Scripts/VariableTypes/SpriteVariable.cs.meta

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

26
Assets/Fungus/FungusScript/Scripts/StringVariable.cs → Assets/Fungus/FungusScript/Scripts/VariableTypes/StringVariable.cs

@ -4,30 +4,12 @@ using System.Collections;
namespace Fungus
{
public class StringVariable : Variable
{
public string value = "";
protected string startValue = "";
public override void OnReset()
{
value = startValue;
}
public override string ToString()
{
return value.ToString();
}
protected virtual void Start()
{
startValue = value;
}
}
[VariableInfo("", "String")]
public class StringVariable : VariableBase<string>
{}
[System.Serializable]
public struct StringData
public class StringData
{
[SerializeField]
public StringVariable stringRef;

0
Assets/Fungus/FungusScript/Scripts/StringVariable.cs.meta → Assets/Fungus/FungusScript/Scripts/VariableTypes/StringVariable.cs.meta

38
Assets/Fungus/FungusScript/Scripts/VariableTypes/TextureVariable.cs

@ -0,0 +1,38 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
[VariableInfo("Other", "Texture")]
public class TextureVariable : VariableBase<Texture>
{}
[System.Serializable]
public class TextureData
{
[SerializeField]
public TextureVariable textureRef;
[SerializeField]
public Texture textureVal;
public Texture Value
{
get { return (textureRef == null) ? textureVal : textureRef.value; }
set { if (textureRef == null) { textureVal = value; } else { textureRef.value = value; } }
}
public string GetDescription()
{
if (textureRef == null)
{
return textureVal.ToString();
}
else
{
return textureRef.key;
}
}
}
}

8
Assets/Fungus/FungusScript/Scripts/VariableTypes/TextureVariable.cs.meta

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

38
Assets/Fungus/FungusScript/Scripts/VariableTypes/Vector2Variable.cs

@ -0,0 +1,38 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
[VariableInfo("Other", "Vector2")]
public class Vector2Variable : VariableBase<Vector2>
{}
[System.Serializable]
public class Vector2Data
{
[SerializeField]
public Vector2Variable vector2Ref;
[SerializeField]
public Vector2 vector2Val;
public Vector2 Value
{
get { return (vector2Ref == null) ? vector2Val : vector2Ref.value; }
set { if (vector2Ref == null) { vector2Val = value; } else { vector2Ref.value = value; } }
}
public string GetDescription()
{
if (vector2Ref == null)
{
return vector2Val.ToString();
}
else
{
return vector2Ref.key;
}
}
}
}

8
Assets/Fungus/FungusScript/Scripts/VariableTypes/Vector2Variable.cs.meta

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

38
Assets/Fungus/FungusScript/Scripts/VariableTypes/Vector3Variable.cs

@ -0,0 +1,38 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
[VariableInfo("Other", "Vector3")]
public class Vector3Variable : VariableBase<Vector3>
{}
[System.Serializable]
public class Vector3Data
{
[SerializeField]
public Vector3Variable vector3Ref;
[SerializeField]
public Vector3 vector3Val;
public Vector3 Value
{
get { return (vector3Ref == null) ? vector3Val : vector3Ref.value; }
set { if (vector3Ref == null) { vector3Val = value; } else { vector3Ref.value = value; } }
}
public string GetDescription()
{
if (vector3Ref == null)
{
return vector3Val.ToString();
}
else
{
return vector3Ref.key;
}
}
}
}

8
Assets/Fungus/FungusScript/Scripts/VariableTypes/Vector3Variable.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4d769ea3513ad47aabf805db5252341d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
Loading…
Cancel
Save