Browse Source

Add variables window

master
chrisgregan 11 years ago
parent
commit
fd26344a19
  1. 10
      Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs
  2. 98
      Assets/Fungus/Editor/FungusScript/VariablesWindow.cs
  3. 8
      Assets/Fungus/Editor/FungusScript/VariablesWindow.cs.meta

10
Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs

@ -14,8 +14,6 @@ namespace Fungus.Script
private List<Sequence> windowSequenceMap = new List<Sequence>();
private GameObject cachedSelection;
[MenuItem("Window/Fungus Editor")]
static void Init()
{
@ -27,7 +25,7 @@ namespace Fungus.Script
Repaint();
}
FungusScript GetFungusScript()
static public FungusScript GetFungusScript()
{
GameObject activeObject = Selection.activeGameObject;
@ -146,6 +144,12 @@ namespace Fungus.Script
{
Selection.activeGameObject = fungusScript.gameObject;
}
GUI.backgroundColor = Color.white;
if (GUILayout.Button("Show Variables"))
{
EditorWindow.GetWindow<VariablesWindow>(true, "Fungus Variables");
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.Space(15);

98
Assets/Fungus/Editor/FungusScript/VariablesWindow.cs

@ -0,0 +1,98 @@
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Fungus.Script
{
public class VariablesWindow : EditorWindow
{
Vector2 scrollPos = new Vector2();
public void OnInspectorUpdate()
{
Repaint();
}
void OnGUI()
{
FungusScript fungusScript = FungusEditorWindow.GetFungusScript();
if (fungusScript == null)
{
GUILayout.Label("No Fungus Script object selected");
return;
}
bool showValues = Application.isPlaying;
float columnWidth = (position.width - 40) / (showValues ? 3 : 2);
scrollPos = GUILayout.BeginScrollView(scrollPos);
GUILayout.BeginHorizontal();
GUILayout.Label("Key", GUILayout.Width(columnWidth));
GUILayout.Label("Type", GUILayout.Width(columnWidth));
if (showValues)
{
GUILayout.Label("Value", GUILayout.Width(columnWidth));
}
GUILayout.EndHorizontal();
GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
boxStyle.margin.left = 0;
boxStyle.margin.right = 0;
boxStyle.margin.top = 0;
boxStyle.margin.bottom = 0;
foreach (Variable variable in fungusScript.variables)
{
GUILayout.BeginHorizontal(boxStyle);
string keyString = variable.key;
string typeString = "";
string valueString = "";
switch (variable.type)
{
case VariableType.Boolean:
typeString = "Boolean";
valueString = variable.booleanValue ? "True" : "False";
break;
case VariableType.Integer:
typeString = "Integer";
valueString = variable.integerValue.ToString();
break;
case VariableType.Float:
typeString = "Float";
valueString = variable.floatValue.ToString();
break;
case VariableType.String:
typeString = "String";
if (variable.stringValue.Length == 0)
{
valueString = "\"\"";
}
else
{
valueString = variable.stringValue;
}
break;
}
GUILayout.Label(keyString, GUILayout.Width(columnWidth));
GUILayout.Label(typeString, GUILayout.Width(columnWidth));
if (showValues)
{
GUILayout.Label(valueString, GUILayout.Width(columnWidth));
}
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
}
}
}

8
Assets/Fungus/Editor/FungusScript/VariablesWindow.cs.meta

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