Browse Source

Add button, insert above / below enabled on command list

master
chrisgregan 11 years ago
parent
commit
c37b884a48
  1. 50
      Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs
  2. 14
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  3. 3
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  4. BIN
      Assets/Shuttle/ShuttleGame.unity

50
Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs

@ -49,18 +49,56 @@ namespace Fungus.Script
}
public void Add() {
FungusCommand newCommand = AddNewCommand();
if (newCommand == null)
{
return;
}
int newIndex = _arrayProperty.arraySize;
++_arrayProperty.arraySize;
ResetValue(_arrayProperty.GetArrayElementAtIndex(newIndex));
_arrayProperty.GetArrayElementAtIndex(newIndex).objectReferenceValue = newCommand;
}
public void Insert(int index) {
FungusCommand newCommand = AddNewCommand();
if (newCommand == null)
{
return;
}
_arrayProperty.InsertArrayElementAtIndex(index);
ResetValue(_arrayProperty.GetArrayElementAtIndex(index));
_arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue = newCommand;
}
FungusCommand AddNewCommand()
{
FungusScript fungusScript = FungusScriptWindow.GetFungusScript();
if (fungusScript == null ||
fungusScript.selectedAddCommandType == null)
{
return null;
}
Sequence sequence = fungusScript.selectedSequence;
if (sequence == null)
{
return null;
}
return sequence.gameObject.AddComponent(fungusScript.selectedAddCommandType) as FungusCommand;
}
public void Duplicate(int index) {
FungusCommand command = _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue as FungusCommand;
// Add the command as a new component
Sequence parentSequence = command.GetComponent<Sequence>();
FungusCommand newCommand = FungusCommandEditor.PasteCommand(command, parentSequence);
_arrayProperty.InsertArrayElementAtIndex(index);
_arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue = newCommand;
}
public void Remove(int index) {
@ -130,15 +168,21 @@ namespace Fungus.Script
buttonRect.y -= 2;
buttonRect.height += 5;
GUI.Box(buttonRect, commandName, commandStyle);
Rect summaryRect = position;
summaryRect.x += buttonWidth + 5;
summaryRect.width -= (buttonWidth + 5);
if (GUI.Button(buttonRect, commandName, commandStyle) && !Application.isPlaying)
if (!Application.isPlaying &&
Event.current.type == EventType.MouseDown &&
Event.current.button == 0 &&
position.Contains(Event.current.mousePosition))
{
fungusScript.selectedCommand = command;
GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus)
}
GUI.backgroundColor = Color.white;
GUIStyle labelStyle = new GUIStyle(EditorStyles.miniLabel);

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

@ -47,7 +47,7 @@ namespace Fungus.Script
SerializedProperty commandListProperty = serializedObject.FindProperty("commandList");
FungusCommandListAdaptor adaptor = new FungusCommandListAdaptor(commandListProperty, 0);
ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableDuplicateCommand | ReorderableListFlags.HideAddButton);
ReorderableListControl.DrawControlFromState(adaptor, null, 0);
if (Application.isPlaying)
{
@ -129,18 +129,12 @@ namespace Fungus.Script
return;
}
fungusScript.selectedAddCommandType = selectedType;
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;
Undo.RecordObject(fungusScript, "Add Command");
fungusScript.selectedSequence.commandList.Add(newCommand);
fungusScript.selectedCommand = newCommand;
}
if (fungusScript.copyCommand != null)
{
if (GUILayout.Button("Paste"))

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

@ -18,6 +18,9 @@ namespace Fungus.Script
[HideInInspector]
public int selectedAddCommandIndex;
[HideInInspector]
public System.Type selectedAddCommandType;
[HideInInspector]
public int selectedCommandCategoryIndex;

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save