Browse Source

Changed dialog command to use serializedProperty

master
chrisgregan 11 years ago
parent
commit
99a0fd5d6d
  1. BIN
      Assets/Example/Scenes/Example.unity
  2. 2
      Assets/Fungus/Dialog/Commands/Choose.cs
  3. 8
      Assets/Fungus/Dialog/Commands/SetChooseDialog.cs
  4. 8
      Assets/Fungus/Dialog/Commands/SetSayDialog.cs
  5. 2
      Assets/Fungus/Dialog/Editor/AddOptionEditor.cs
  6. 2
      Assets/Fungus/Dialog/Editor/CharacterEditor.cs
  7. 46
      Assets/Fungus/Dialog/Editor/ChooseEditor.cs
  8. 49
      Assets/Fungus/Dialog/Editor/SayEditor.cs
  9. 25
      Assets/Fungus/Dialog/Editor/SetChooseDialogEditor.cs
  10. 24
      Assets/Fungus/Dialog/Editor/SetSayDialogEditor.cs
  11. 15
      Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs

BIN
Assets/Example/Scenes/Example.unity

Binary file not shown.

2
Assets/Fungus/Dialog/Commands/Choose.cs

@ -18,7 +18,9 @@ namespace Fungus.Script
static public List<Option> options = new List<Option>(); static public List<Option> options = new List<Option>();
[TextArea(5,10)]
public string chooseText; public string chooseText;
public Character character; public Character character;
public AudioClip voiceOverClip; public AudioClip voiceOverClip;
public float timeoutDuration; public float timeoutDuration;

8
Assets/Fungus/Dialog/Commands/SetChooseDialog.cs

@ -10,23 +10,23 @@ namespace Fungus.Script
"Sets the active dialog to use for displaying story text with the Choose command.")] "Sets the active dialog to use for displaying story text with the Choose command.")]
public class SetChooseDialog : FungusCommand public class SetChooseDialog : FungusCommand
{ {
public ChooseDialog dialog; public ChooseDialog chooseDialog;
static public ChooseDialog activeDialog; static public ChooseDialog activeDialog;
public override void OnEnter() public override void OnEnter()
{ {
activeDialog = dialog; activeDialog = chooseDialog;
Continue(); Continue();
} }
public override string GetSummary() public override string GetSummary()
{ {
if (dialog == null) if (chooseDialog == null)
{ {
return "Error: No dialog selected"; return "Error: No dialog selected";
} }
return dialog.name; return chooseDialog.name;
} }
public override Color GetButtonColor() public override Color GetButtonColor()

8
Assets/Fungus/Dialog/Commands/SetSayDialog.cs

@ -10,23 +10,23 @@ namespace Fungus.Script
"Sets the active dialog to use for displaying story text with the Say command.")] "Sets the active dialog to use for displaying story text with the Say command.")]
public class SetSayDialog : FungusCommand public class SetSayDialog : FungusCommand
{ {
public SayDialog dialog; public SayDialog sayDialog;
static public SayDialog activeDialog; static public SayDialog activeDialog;
public override void OnEnter() public override void OnEnter()
{ {
activeDialog = dialog; activeDialog = sayDialog;
Continue(); Continue();
} }
public override string GetSummary() public override string GetSummary()
{ {
if (dialog == null) if (sayDialog == null)
{ {
return "Error: No dialog selected"; return "Error: No dialog selected";
} }
return dialog.name; return sayDialog.name;
} }
public override Color GetButtonColor() public override Color GetButtonColor()

2
Assets/Fungus/Dialog/Editor/AddOptionEditor.cs

@ -28,8 +28,6 @@ namespace Fungus.Script
AddOption t = target as AddOption; AddOption t = target as AddOption;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(optionTextProp, new GUIContent("Option Text", "Text to display on the option button.")); EditorGUILayout.PropertyField(optionTextProp, new GUIContent("Option Text", "Text to display on the option button."));
SequenceEditor.SequenceField(targetSequenceProp, SequenceEditor.SequenceField(targetSequenceProp,

2
Assets/Fungus/Dialog/Editor/CharacterEditor.cs

@ -39,8 +39,6 @@ namespace Fungus.Script
{ {
serializedObject.Update(); serializedObject.Update();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(nameTextProp, new GUIContent("Name Text", "Name of the character display in the dialog")); EditorGUILayout.PropertyField(nameTextProp, new GUIContent("Name Text", "Name of the character display in the dialog"));
EditorGUILayout.PropertyField(nameColorProp, new GUIContent("Name Color", "Color of name text display in the dialog")); EditorGUILayout.PropertyField(nameColorProp, new GUIContent("Name Color", "Color of name text display in the dialog"));

46
Assets/Fungus/Dialog/Editor/ChooseEditor.cs

@ -13,14 +13,24 @@ namespace Fungus.Script
{ {
static public bool showTagHelp; static public bool showTagHelp;
public override void DrawCommandGUI() SerializedProperty chooseTextProp;
SerializedProperty characterProp;
SerializedProperty voiceOverClipProp;
SerializedProperty timeoutDurationProp;
void OnEnable()
{ {
Choose t = target as Choose; chooseTextProp = serializedObject.FindProperty("chooseText");
characterProp = serializedObject.FindProperty("character");
voiceOverClipProp = serializedObject.FindProperty("voiceOverClip");
timeoutDurationProp = serializedObject.FindProperty("timeoutDuration");
}
EditorGUI.BeginChangeCheck(); public override void DrawCommandGUI()
{
serializedObject.Update();
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(new GUIContent("Choose Text", "Text to display in dialog"));
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton)))
{ {
@ -33,30 +43,18 @@ namespace Fungus.Script
SayEditor.DrawTagHelpLabel(); SayEditor.DrawTagHelpLabel();
} }
GUIStyle sayStyle = new GUIStyle(EditorStyles.textArea); EditorGUILayout.PropertyField(chooseTextProp);
sayStyle.wordWrap = true;
string chooseText = EditorGUILayout.TextArea(t.chooseText, sayStyle, GUILayout.MinHeight(30));
Character character = FungusCommandEditor.ObjectField<Character>(new GUIContent("Character", "Character to display in dialog"), FungusCommandEditor.ObjectField<Character>(characterProp,
new GUIContent("<None>"), new GUIContent("Character", "Character to display in dialog"),
t.character, new GUIContent("<None>"),
Character.activeCharacters); Character.activeCharacters);
AudioClip voiceOverClip = EditorGUILayout.ObjectField(new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed"), EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed"));
t.voiceOverClip,
typeof(AudioClip),
true) as AudioClip;
float timeoutDuration = EditorGUILayout.FloatField(new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit."), t.timeoutDuration); EditorGUILayout.PropertyField(timeoutDurationProp, new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit."));
if (EditorGUI.EndChangeCheck()) serializedObject.ApplyModifiedProperties();
{
Undo.RecordObject(t, "Set Choose");
t.chooseText = chooseText;
t.character = character;
t.voiceOverClip = voiceOverClip;
t.timeoutDuration = timeoutDuration;
}
} }
} }

49
Assets/Fungus/Dialog/Editor/SayEditor.cs

@ -30,11 +30,22 @@ namespace Fungus.Script
EditorGUILayout.SelectableLabel(tagsText, EditorStyles.miniLabel, GUILayout.MinHeight(pixelHeight)); EditorGUILayout.SelectableLabel(tagsText, EditorStyles.miniLabel, GUILayout.MinHeight(pixelHeight));
} }
public override void DrawCommandGUI() SerializedProperty storyTextProp;
SerializedProperty characterProp;
SerializedProperty voiceOverClipProp;
SerializedProperty showOnceProp;
void OnEnable()
{ {
Say t = target as Say; storyTextProp = serializedObject.FindProperty("storyText");
characterProp = serializedObject.FindProperty("character");
voiceOverClipProp = serializedObject.FindProperty("voiceOverClip");
showOnceProp = serializedObject.FindProperty("showOnce");
}
EditorGUI.BeginChangeCheck(); public override void DrawCommandGUI()
{
serializedObject.Update();
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog")); EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog"));
@ -50,12 +61,11 @@ namespace Fungus.Script
DrawTagHelpLabel(); DrawTagHelpLabel();
} }
GUIStyle sayStyle = new GUIStyle(EditorStyles.textArea);
sayStyle.wordWrap = true;
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(60)); EditorGUILayout.PropertyField(storyTextProp);
Say t = target as Say;
if (t.character != null && if (t.character != null &&
t.character.profileSprite != null && t.character.profileSprite != null &&
@ -76,26 +86,17 @@ namespace Fungus.Script
EditorGUILayout.Separator(); EditorGUILayout.Separator();
Character character = FungusCommandEditor.ObjectField<Character>(new GUIContent("Character", "Character to display in dialog"), FungusCommandEditor.ObjectField<Character>(characterProp,
new GUIContent("<None>"), new GUIContent("Character", "Character to display in dialog"),
t.character, new GUIContent("<None>"),
Character.activeCharacters); Character.activeCharacters);
AudioClip voiceOverClip = EditorGUILayout.ObjectField(new GUIContent("Voice Over Clip", "Voice over audio to play when the say text is displayed"), EditorGUILayout.PropertyField(voiceOverClipProp,
t.voiceOverClip, new GUIContent("Voice Over Clip", "Voice over audio to play when the say text is displayed"));
typeof(AudioClip),
true) as AudioClip;
bool showOnce = EditorGUILayout.Toggle(new GUIContent("Show Once", "Show this text once and never show it again."), t.showOnce); EditorGUILayout.PropertyField(showOnceProp, new GUIContent("Show Once", "Show this text once and never show it again."));
if (EditorGUI.EndChangeCheck()) serializedObject.ApplyModifiedProperties();
{
Undo.RecordObject(t, "Set Say");
t.storyText = text;
t.character = character;
t.voiceOverClip = voiceOverClip;
t.showOnce = showOnce;
}
} }
} }

25
Assets/Fungus/Dialog/Editor/SetChooseDialogEditor.cs

@ -11,21 +11,22 @@ namespace Fungus.Script
[CustomEditor (typeof(SetChooseDialog))] [CustomEditor (typeof(SetChooseDialog))]
public class SetChooseDialogEditor : FungusCommandEditor public class SetChooseDialogEditor : FungusCommandEditor
{ {
public override void DrawCommandGUI() SerializedProperty chooseDialogProp;
void OnEnable()
{ {
SetChooseDialog t = target as SetChooseDialog; chooseDialogProp = serializedObject.FindProperty("chooseDialog");
}
EditorGUI.BeginChangeCheck(); public override void DrawCommandGUI()
{
serializedObject.Update();
ChooseDialog dialog = FungusCommandEditor.ObjectField<ChooseDialog>(new GUIContent("Choose Dialog", "Dialog to use when displaying options with the Choose command."), FungusCommandEditor.ObjectField<ChooseDialog>(chooseDialogProp,
new GUIContent("<None>"), new GUIContent("Choose Dialog", "Dialog to use when displaying options with the Choose command."),
t.dialog, new GUIContent("<None>"),
ChooseDialog.activeDialogs); ChooseDialog.activeDialogs);
if (EditorGUI.EndChangeCheck()) serializedObject.ApplyModifiedProperties();
{
Undo.RecordObject(t, "Set Choose Dialog");
t.dialog = dialog;
}
} }
} }

24
Assets/Fungus/Dialog/Editor/SetSayDialogEditor.cs

@ -11,21 +11,23 @@ namespace Fungus.Script
[CustomEditor (typeof(SetSayDialog))] [CustomEditor (typeof(SetSayDialog))]
public class SetSayDialogEditor : FungusCommandEditor public class SetSayDialogEditor : FungusCommandEditor
{ {
SerializedProperty sayDialogProp;
void OnEnable()
{
sayDialogProp = serializedObject.FindProperty("sayDialog");
}
public override void DrawCommandGUI() public override void DrawCommandGUI()
{ {
SetSayDialog t = target as SetSayDialog; serializedObject.Update();
EditorGUI.BeginChangeCheck(); FungusCommandEditor.ObjectField<SayDialog>(sayDialogProp,
new GUIContent("Say Dialog", "Dialog to use when displaying Say command story text"),
new GUIContent("<None>"),
SayDialog.activeDialogs);
SayDialog dialog = FungusCommandEditor.ObjectField<SayDialog>(new GUIContent("Say Dialog", "Dialog to use when displaying Say command story text"), serializedObject.ApplyModifiedProperties();
new GUIContent("<None>"),
t.dialog,
SayDialog.activeDialogs);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(t, "Set Say Dialog");
t.dialog = dialog;
}
} }
} }

15
Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs

@ -143,10 +143,17 @@ namespace Fungus.Script
return newCommand; return newCommand;
} }
static public T ObjectField<T>(GUIContent label, GUIContent nullLabel, T selectedObject, List<T> objectList) where T : MonoBehaviour static public void ObjectField<T>(SerializedProperty property, GUIContent label, GUIContent nullLabel, List<T> objectList) where T : MonoBehaviour
{ {
if (property == null)
{
return;
}
List<GUIContent> objectNames = new List<GUIContent>(); List<GUIContent> objectNames = new List<GUIContent>();
T selectedObject = property.objectReferenceValue as T;
int selectedIndex = 0; int selectedIndex = 0;
objectNames.Add(nullLabel); objectNames.Add(nullLabel);
for (int i = 0; i < objectList.Count; ++i) for (int i = 0; i < objectList.Count; ++i)
@ -170,8 +177,8 @@ namespace Fungus.Script
{ {
result = objectList[selectedIndex - 1]; result = objectList[selectedIndex - 1];
} }
return result; property.objectReferenceValue = result;
} }
} }

Loading…
Cancel
Save