Browse Source

Reverted to 2 popup method for Add Command

master
chrisgregan 10 years ago
parent
commit
c37ada3da5
  1. 64
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  2. 3
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  3. BIN
      Assets/Shuttle/ShuttleGame.unity

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

@ -42,7 +42,6 @@ namespace Fungus.Script
Undo.RecordObject(sequence, "Set Sequence Description"); Undo.RecordObject(sequence, "Set Sequence Description");
sequence.description = desc; sequence.description = desc;
} }
ReorderableListGUI.Title("Command Sequence"); ReorderableListGUI.Title("Command Sequence");
@ -57,14 +56,37 @@ namespace Fungus.Script
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
EditorGUILayout.Separator();
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
// Build list of categories
List<string> categories = new List<string>();
List<System.Type> subTypes = EditorExtensions.FindDerivedTypes(typeof(FungusCommand)).ToList();
foreach(System.Type type in subTypes)
{
object[] attributes = type.GetCustomAttributes(false);
foreach (object obj in attributes)
{
CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute;
if (categoryAttr != null)
{
if (!categories.Contains(categoryAttr.Category))
{
categories.Add(categoryAttr.Category);
}
}
}
}
categories.Sort();
GUILayout.Label("New Command");
GUILayout.FlexibleSpace();
int selectedCategoryIndex = EditorGUILayout.Popup(fungusScript.selectedCommandCategoryIndex, categories.ToArray());
List<string> commandNames = new List<string>(); List<string> commandNames = new List<string>();
List<System.Type> commandTypes = EditorExtensions.FindDerivedTypes(typeof(FungusCommand)).ToList(); List<System.Type> commandTypes = new List<System.Type>();
foreach (System.Type type in commandTypes) string categoryName = categories[selectedCategoryIndex];
foreach (System.Type type in subTypes)
{ {
object[] attributes = type.GetCustomAttributes(false); object[] attributes = type.GetCustomAttributes(false);
foreach (object obj in attributes) foreach (object obj in attributes)
@ -72,24 +94,33 @@ namespace Fungus.Script
CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute; CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute;
if (categoryAttr != null) if (categoryAttr != null)
{ {
string commandItem = categoryAttr.Category + " - " + FungusScriptEditor.GetCommandName(type); if (categoryAttr.Category == categoryName)
commandNames.Add(commandItem); {
break; commandNames.Add(FungusScriptEditor.GetCommandName(type));
commandTypes.Add(type);
}
} }
} }
} }
int selectedCommandIndex = EditorGUILayout.Popup(fungusScript.selectedAddCommandIndex, commandNames.ToArray());
int selectedCommandIndex = EditorGUILayout.Popup(fungusScript.selectedAddCommandIndex, commandNames.ToArray());
if (selectedCategoryIndex != fungusScript.selectedCommandCategoryIndex)
{
// Default to first item in list if category has changed
selectedCommandIndex = 0;
}
EditorGUILayout.EndHorizontal();
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
{ {
Undo.RecordObject(fungusScript, "Select Command"); Undo.RecordObject(fungusScript, "Select Command");
fungusScript.selectedCommandCategoryIndex = selectedCategoryIndex;
fungusScript.selectedAddCommandIndex = selectedCommandIndex; fungusScript.selectedAddCommandIndex = selectedCommandIndex;
} }
if (selectedCommandIndex >= commandTypes.Count) if (selectedCommandIndex >= commandTypes.Count)
{ {
EditorGUILayout.EndHorizontal();
return; return;
} }
@ -97,11 +128,14 @@ namespace Fungus.Script
if (fungusScript.selectedSequence == null || if (fungusScript.selectedSequence == null ||
selectedType == null) selectedType == null)
{ {
EditorGUILayout.EndHorizontal();
return; return;
} }
if (GUILayout.Button(new GUIContent("Add Command", "Add the selected command to the sequence"), EditorStyles.miniButton)) EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button(new GUIContent("Add Command", "Add the selected command to the sequence")))
{ {
FungusCommand newCommand = Undo.AddComponent(fungusScript.selectedSequence.gameObject, selectedType) as FungusCommand; FungusCommand newCommand = Undo.AddComponent(fungusScript.selectedSequence.gameObject, selectedType) as FungusCommand;
Undo.RecordObject(fungusScript, "Add Command"); Undo.RecordObject(fungusScript, "Add Command");
@ -110,7 +144,7 @@ namespace Fungus.Script
if (fungusScript.copyCommand != null) if (fungusScript.copyCommand != null)
{ {
if (GUILayout.Button("Paste", EditorStyles.miniButton)) if (GUILayout.Button("Paste"))
{ {
FungusCommandEditor.PasteCommand(fungusScript.copyCommand, fungusScript.selectedSequence); FungusCommandEditor.PasteCommand(fungusScript.copyCommand, fungusScript.selectedSequence);
} }

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

@ -18,6 +18,9 @@ namespace Fungus.Script
[HideInInspector] [HideInInspector]
public int selectedAddCommandIndex; public int selectedAddCommandIndex;
[HideInInspector]
public int selectedCommandCategoryIndex;
[HideInInspector] [HideInInspector]
public Vector2 scriptScrollPos; public Vector2 scriptScrollPos;

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save