Browse Source

Variables are displayed in inspector window

master
chrisgregan 11 years ago
parent
commit
f1a17299ed
  1. 4
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  2. 71
      Assets/Fungus/FungusScript/Editor/FungusVariableListAdaptor.cs
  3. 71
      Assets/Fungus/FungusScript/Editor/SplitViewWindow.cs
  4. 8
      Assets/Fungus/FungusScript/Editor/SplitViewWindow.cs.meta
  5. 62
      Assets/Fungus/FungusScript/Editor/VariablesWindow.cs
  6. 8
      Assets/Fungus/FungusScript/Editor/VariablesWindow.cs.meta
  7. BIN
      Assets/Shuttle/ShuttleGame.unity

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

@ -60,6 +60,10 @@ namespace Fungus.Script
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
EditorGUILayout.Separator();
DrawVariablesGUI();
}
public void DrawSequenceGUI(FungusScript fungusScript)

71
Assets/Fungus/FungusScript/Editor/FungusVariableListAdaptor.cs

@ -86,20 +86,20 @@ namespace Fungus.Script
{
FungusVariable variable = this[index].objectReferenceValue as FungusVariable;
float width1 = 60;
float width1 = 100;
float width3 = 50;
float width2 = Mathf.Max(position.width - width1 - width3, 100);
Rect typeRect = position;
typeRect.width = width1;
float width2 = Mathf.Max(position.width - width1 - width3, 60);
Rect keyRect = position;
keyRect.x += width1;
keyRect.width = width2;
keyRect.width = width1;
Rect valueRect = position;
valueRect.x += width1 + 5;
valueRect.width = width2 - 5;
Rect scopeRect = position;
scopeRect.x += width1 + width2;
scopeRect.width = width3;
scopeRect.x += width1 + width2 + 5;
scopeRect.width = width3 - 5;
string type = "";
if (variable.GetType() == typeof(BooleanVariable))
@ -118,21 +118,16 @@ namespace Fungus.Script
{
type = "String";
}
GUI.Label(typeRect, type);
EditorGUI.BeginChangeCheck();
FungusScript fungusScript = FungusScriptWindow.GetFungusScript();
string key = variable.key;
VariableScope scope = variable.scope;
if (Application.isPlaying)
{
const float w = 100;
Rect valueRect = keyRect;
keyRect.width = w - 5;
valueRect.x += w;
valueRect.width -= (w + 5);
key = EditorGUI.TextField(keyRect, variable.key);
GUI.Label(keyRect, variable.key);
if (variable.GetType() == typeof(BooleanVariable))
{
BooleanVariable v = variable as BooleanVariable;
@ -153,24 +148,32 @@ namespace Fungus.Script
StringVariable v = variable as StringVariable;
v.Value = EditorGUI.TextField(valueRect, v.Value);
}
if (scope == VariableScope.Local)
{
GUI.Label(scopeRect, "Local");
}
else if (scope == VariableScope.Global)
{
GUI.Label(scopeRect, "Global");
}
}
else
{
keyRect.width -= 5;
key = EditorGUI.TextField(keyRect, variable.key);
}
VariableScope scope = (VariableScope)EditorGUI.EnumPopup(scopeRect, variable.scope);
EditorGUI.BeginChangeCheck();
FungusScript fungusScript = FungusScriptWindow.GetFungusScript();
if (EditorGUI.EndChangeCheck ())
{
Undo.RecordObject(variable, "Set Variable");
key = EditorGUI.TextField(keyRect, variable.key);
GUI.Label(valueRect, type);
scope = (VariableScope)EditorGUI.EnumPopup(scopeRect, variable.scope);
// Modify the key if it clashes with an existing variable key
variable.key = fungusScript.GetUniqueVariableKey(key, variable);
variable.scope = scope;
if (EditorGUI.EndChangeCheck ())
{
Undo.RecordObject(variable, "Set Variable");
// Modify the key if it clashes with an existing variable key
variable.key = fungusScript.GetUniqueVariableKey(key, variable);
variable.scope = scope;
}
}
if (fungusScript != null)

71
Assets/Fungus/FungusScript/Editor/SplitViewWindow.cs

@ -1,71 +0,0 @@
using UnityEngine;
using UnityEditor;
public class SplitViewWindow : EditorWindow
{
private Vector2 scrollPos = Vector2.zero;
float commandViewWidth;
bool resize = false;
Rect cursorChangeRect;
public float minViewWidth = 150;
[MenuItem("MyWindows/SplitView")]
public static void Init(){
GetWindow<SplitViewWindow>();
}
void OnEnable()
{
commandViewWidth = minViewWidth;
cursorChangeRect = new Rect(this.position.width - commandViewWidth, 0, 4f, this.position.height);
}
void OnGUI()
{
GUILayout.BeginHorizontal();
DrawScriptView();
ResizeViews();
GUILayout.EndHorizontal();
Repaint();
}
void DrawScriptView()
{
Rect scriptViewRect = new Rect(0, 0, this.position.width - commandViewWidth, this.position.height);
scrollPos = GUI.BeginScrollView(scriptViewRect, scrollPos, scriptViewRect);
GUI.EndScrollView();
}
void ResizeViews()
{
cursorChangeRect.x = this.position.width - commandViewWidth;
cursorChangeRect.height = this.position.height;
GUI.color = Color.grey;
GUI.DrawTexture(cursorChangeRect, EditorGUIUtility.whiteTexture);
EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeHorizontal);
if (Event.current.type == EventType.mouseDown && cursorChangeRect.Contains(Event.current.mousePosition))
{
resize = true;
}
if (resize)
{
commandViewWidth = this.position.width - Event.current.mousePosition.x;
commandViewWidth = Mathf.Max(minViewWidth, commandViewWidth);
commandViewWidth = Mathf.Min(this.position.width - minViewWidth, commandViewWidth);
}
if(Event.current.type == EventType.MouseUp)
{
resize = false;
}
}
void DrawCommandView()
{
}
}

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

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

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

@ -1,62 +0,0 @@
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 = FungusScriptWindow.GetFungusScript();
if (fungusScript == null)
{
GUILayout.Label("No Fungus Script object selected");
return;
}
// Warn about conflicting global variable types
Dictionary<string, FungusVariable> globals = new Dictionary<string, FungusVariable>();
FungusScript[] fungusScripts = GameObject.FindObjectsOfType<FungusScript>();
foreach (FungusScript fs in fungusScripts)
{
FungusVariable[] variables = fs.GetComponents<FungusVariable>();
foreach (FungusVariable v in variables)
{
if (v.scope == VariableScope.Global)
{
if (globals.ContainsKey(v.key))
{
if (globals[v.key].GetType() != v.GetType())
{
GUIStyle errorStyle = new GUIStyle(GUI.skin.label);
errorStyle.normal.textColor = new Color(1,0,0);
GUILayout.Label("Error: Global '" + v.key + "' must use the same type in all scripts.", errorStyle);
}
}
globals[v.key] = v;
}
}
}
scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.MinWidth(Mathf.Max(position.width, 300)));
FungusScriptEditor fungusScriptEditor = Editor.CreateEditor(fungusScript) as FungusScriptEditor;
fungusScriptEditor.DrawVariablesGUI();
GUILayout.EndScrollView();
}
}
}

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

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

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save