chrisgregan
10 years ago
10 changed files with 3 additions and 427 deletions
@ -1,139 +0,0 @@ |
|||||||
using UnityEngine; |
|
||||||
using System; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
|
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
[CommandInfo("Dialog", |
|
||||||
"Choose", |
|
||||||
"Presents a list of options for the player to choose from using a Choose Dialog. " + |
|
||||||
"Place Option commands after the Choose Option command to specify the player options, and terminate with an End command.")] |
|
||||||
[AddComponentMenu("")] |
|
||||||
public class ChooseOption : Command |
|
||||||
{ |
|
||||||
[Tooltip("Story text to display to prompt player to choose an option")] |
|
||||||
[TextArea(5,10)] |
|
||||||
public string chooseText = ""; |
|
||||||
|
|
||||||
[Tooltip("Speaking character to use when prompting the player to choose an option")] |
|
||||||
public Character character; |
|
||||||
|
|
||||||
[Tooltip("Choose Dialog object to use to display the player options")] |
|
||||||
public ChooseDialog chooseDialog; |
|
||||||
|
|
||||||
[Tooltip("Portrait that represents speaking character")] |
|
||||||
public Sprite portrait; |
|
||||||
|
|
||||||
[Tooltip("Voiceover audio to play when prompting the player to choose an option")] |
|
||||||
public AudioClip voiceOverClip; |
|
||||||
|
|
||||||
[Tooltip("Time limit for player to choose an option. Set to 0 for no time limit.")] |
|
||||||
public float timeoutDuration; |
|
||||||
|
|
||||||
public override void OnEnter() |
|
||||||
{ |
|
||||||
if (chooseDialog == null) |
|
||||||
{ |
|
||||||
if (chooseDialog == null) |
|
||||||
{ |
|
||||||
// Try to get any ChooseDialog in the scene |
|
||||||
chooseDialog = GameObject.FindObjectOfType<ChooseDialog>(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Build list of Option commands |
|
||||||
End endCommand = null; |
|
||||||
List<Option> options = new List<Option>(); |
|
||||||
for (int i = commandIndex + 1; i < parentSequence.commandList.Count; ++i) |
|
||||||
{ |
|
||||||
Command command = parentSequence.commandList[i]; |
|
||||||
|
|
||||||
// Check for closing End command |
|
||||||
if (command.GetType() == typeof(End) && |
|
||||||
command.indentLevel == indentLevel) |
|
||||||
{ |
|
||||||
endCommand = command as End; |
|
||||||
|
|
||||||
// Jump to End if no dialog is set |
|
||||||
if (chooseDialog == null) |
|
||||||
{ |
|
||||||
Continue (endCommand.commandIndex + 1); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
Option option = command as Option; |
|
||||||
if (option != null && |
|
||||||
option.indentLevel == indentLevel && |
|
||||||
!option.IsHidden()) |
|
||||||
{ |
|
||||||
options.Add(command as Option); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (options.Count == 0) |
|
||||||
{ |
|
||||||
Continue(); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
FungusScript fungusScript = GetFungusScript(); |
|
||||||
|
|
||||||
chooseDialog.ShowDialog(true); |
|
||||||
chooseDialog.SetCharacter(character, fungusScript); |
|
||||||
chooseDialog.SetCharacterImage(portrait); |
|
||||||
|
|
||||||
List<ChooseDialog.Option> dialogOptions = new List<ChooseDialog.Option>(); |
|
||||||
foreach (Option option in options) |
|
||||||
{ |
|
||||||
ChooseDialog.Option dialogOption = new ChooseDialog.Option(); |
|
||||||
dialogOption.text = fungusScript.SubstituteVariables(option.optionText); |
|
||||||
|
|
||||||
Option theOption = option; // Needed to close over the option object in the delegate |
|
||||||
|
|
||||||
dialogOption.onSelect = delegate { |
|
||||||
chooseDialog.ShowDialog(false); |
|
||||||
theOption.wasSelected = true; |
|
||||||
Continue(theOption.commandIndex + 1); |
|
||||||
}; |
|
||||||
|
|
||||||
dialogOptions.Add(dialogOption); |
|
||||||
} |
|
||||||
|
|
||||||
options.Clear(); |
|
||||||
|
|
||||||
if (voiceOverClip != null) |
|
||||||
{ |
|
||||||
chooseDialog.PlayVoiceOver(voiceOverClip); |
|
||||||
} |
|
||||||
|
|
||||||
string subbedText = fungusScript.SubstituteVariables(chooseText); |
|
||||||
|
|
||||||
chooseDialog.Choose(subbedText, dialogOptions, timeoutDuration, delegate { |
|
||||||
// Timeout will execute the commands listed immediately after the Choose Option command |
|
||||||
chooseDialog.ShowDialog(false); |
|
||||||
Continue(); |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override bool OpenBlock() |
|
||||||
{ |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
public override string GetSummary() |
|
||||||
{ |
|
||||||
return "\"" + chooseText + "\""; |
|
||||||
} |
|
||||||
|
|
||||||
public override Color GetButtonColor() |
|
||||||
{ |
|
||||||
return new Color32(253, 253, 150, 255); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,8 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 14d1bf29d0098422daf85e7bfd9896cc |
|
||||||
MonoImporter: |
|
||||||
serializedVersion: 2 |
|
||||||
defaultReferences: [] |
|
||||||
executionOrder: 0 |
|
||||||
icon: {instanceID: 0} |
|
||||||
userData: |
|
@ -1,110 +0,0 @@ |
|||||||
using UnityEditor; |
|
||||||
using UnityEditorInternal; |
|
||||||
using UnityEngine; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
using Rotorz.ReorderableList; |
|
||||||
|
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
|
|
||||||
[CustomEditor (typeof(ChooseOption))] |
|
||||||
public class ChooseOptionEditor : CommandEditor |
|
||||||
{ |
|
||||||
static public bool showTagHelp; |
|
||||||
|
|
||||||
protected SerializedProperty chooseTextProp; |
|
||||||
protected SerializedProperty characterProp; |
|
||||||
protected SerializedProperty chooseDialogProp; |
|
||||||
protected SerializedProperty portraitProp; |
|
||||||
protected SerializedProperty voiceOverClipProp; |
|
||||||
protected SerializedProperty timeoutDurationProp; |
|
||||||
|
|
||||||
protected virtual void OnEnable() |
|
||||||
{ |
|
||||||
chooseTextProp = serializedObject.FindProperty("chooseText"); |
|
||||||
characterProp = serializedObject.FindProperty("character"); |
|
||||||
portraitProp = serializedObject.FindProperty("portrait"); |
|
||||||
chooseDialogProp = serializedObject.FindProperty("chooseDialog"); |
|
||||||
voiceOverClipProp = serializedObject.FindProperty("voiceOverClip"); |
|
||||||
timeoutDurationProp = serializedObject.FindProperty("timeoutDuration"); |
|
||||||
} |
|
||||||
|
|
||||||
public override void DrawCommandGUI() |
|
||||||
{ |
|
||||||
serializedObject.Update(); |
|
||||||
|
|
||||||
ChooseOption t = target as ChooseOption; |
|
||||||
|
|
||||||
CommandEditor.ObjectField<Character>(characterProp, |
|
||||||
new GUIContent("Character", "Character to display in dialog"), |
|
||||||
new GUIContent("<None>"), |
|
||||||
Character.activeCharacters); |
|
||||||
|
|
||||||
CommandEditor.ObjectField<ChooseDialog>(chooseDialogProp, |
|
||||||
new GUIContent("Choose Dialog", "Choose Dialog object to use to display the multiple player choices"), |
|
||||||
new GUIContent("<Default>"), |
|
||||||
ChooseDialog.activeDialogs); |
|
||||||
|
|
||||||
bool showPortraits = false; |
|
||||||
// Only show portrait selection if... |
|
||||||
if (t.character != null && // Character is selected |
|
||||||
t.character.portraits != null && // Character has a portraits field |
|
||||||
t.character.portraits.Count > 0 ) // Selected Character has at least 1 portrait |
|
||||||
{ |
|
||||||
showPortraits = true; |
|
||||||
} |
|
||||||
|
|
||||||
if (showPortraits) |
|
||||||
{ |
|
||||||
CommandEditor.ObjectField<Sprite>(portraitProp, |
|
||||||
new GUIContent("Portrait", "Portrait representing speaking character"), |
|
||||||
new GUIContent("<None>"), |
|
||||||
t.character.portraits); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
t.portrait = null; |
|
||||||
} |
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(chooseTextProp); |
|
||||||
|
|
||||||
EditorGUILayout.BeginHorizontal(); |
|
||||||
|
|
||||||
GUILayout.FlexibleSpace(); |
|
||||||
if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) |
|
||||||
{ |
|
||||||
showTagHelp = !showTagHelp; |
|
||||||
} |
|
||||||
EditorGUILayout.EndHorizontal(); |
|
||||||
|
|
||||||
if (showTagHelp) |
|
||||||
{ |
|
||||||
SayEditor.DrawTagHelpLabel(); |
|
||||||
} |
|
||||||
|
|
||||||
EditorGUILayout.Separator(); |
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed")); |
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(timeoutDurationProp, new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit.")); |
|
||||||
|
|
||||||
/* |
|
||||||
if (showPortraits && t.portrait != null) |
|
||||||
{ |
|
||||||
Texture2D characterTexture = t.portrait.texture; |
|
||||||
|
|
||||||
float aspect = (float)characterTexture.width / (float)characterTexture.height; |
|
||||||
|
|
||||||
Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true)); |
|
||||||
CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor; |
|
||||||
characterEditor.DrawPreview(previewRect, characterTexture); |
|
||||||
DestroyImmediate(characterEditor); |
|
||||||
} |
|
||||||
*/ |
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,8 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 92f79083287204bfcbfe02069f0ec4d2 |
|
||||||
MonoImporter: |
|
||||||
serializedVersion: 2 |
|
||||||
defaultReferences: [] |
|
||||||
executionOrder: 0 |
|
||||||
icon: {instanceID: 0} |
|
||||||
userData: |
|
@ -1,45 +0,0 @@ |
|||||||
using UnityEditor; |
|
||||||
using UnityEditorInternal; |
|
||||||
using UnityEngine; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
using Rotorz.ReorderableList; |
|
||||||
|
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
|
|
||||||
[CustomEditor (typeof(Option))] |
|
||||||
public class OptionEditor : IfEditor |
|
||||||
{ |
|
||||||
protected SerializedProperty optionTextProp; |
|
||||||
protected SerializedProperty hideOnSelectedProp; |
|
||||||
protected SerializedProperty hideOnConditionProp; |
|
||||||
|
|
||||||
protected override void OnEnable() |
|
||||||
{ |
|
||||||
base.OnEnable(); |
|
||||||
optionTextProp = serializedObject.FindProperty("optionText"); |
|
||||||
hideOnSelectedProp = serializedObject.FindProperty("hideOnSelected"); |
|
||||||
hideOnConditionProp = serializedObject.FindProperty("hideOnCondition"); |
|
||||||
} |
|
||||||
|
|
||||||
public override void DrawCommandGUI() |
|
||||||
{ |
|
||||||
serializedObject.Update(); |
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(optionTextProp); |
|
||||||
EditorGUILayout.PropertyField(hideOnSelectedProp); |
|
||||||
EditorGUILayout.PropertyField(hideOnConditionProp); |
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties(); |
|
||||||
|
|
||||||
if (hideOnConditionProp.boolValue) |
|
||||||
{ |
|
||||||
EditorGUI.indentLevel++; |
|
||||||
base.DrawCommandGUI(); |
|
||||||
EditorGUI.indentLevel--; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,8 +0,0 @@ |
|||||||
fileFormatVersion: 2 |
|
||||||
guid: 7d495a449ea3144118349a7c5d989c52 |
|
||||||
MonoImporter: |
|
||||||
serializedVersion: 2 |
|
||||||
defaultReferences: [] |
|
||||||
executionOrder: 0 |
|
||||||
icon: {instanceID: 0} |
|
||||||
userData: |
|
@ -1,98 +0,0 @@ |
|||||||
using UnityEngine; |
|
||||||
using System; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
|
|
||||||
namespace Fungus |
|
||||||
{ |
|
||||||
[CommandInfo("Dialog", |
|
||||||
"Option", |
|
||||||
"Adds an option for the player to select. When the option is selected all commands in the following block are executed.")] |
|
||||||
[AddComponentMenu("")] |
|
||||||
public class Option : If |
|
||||||
{ |
|
||||||
[Tooltip("Option text to display when presenting the option to the player")] |
|
||||||
public string optionText = ""; |
|
||||||
|
|
||||||
[Tooltip("Hide this option once it has been selected so that it won't appear again even if executed again")] |
|
||||||
public bool hideOnSelected; |
|
||||||
|
|
||||||
[Tooltip("Hide if a variable condition evaluates to true.")] |
|
||||||
public bool hideOnCondition; |
|
||||||
|
|
||||||
[NonSerialized] |
|
||||||
public bool wasSelected; |
|
||||||
|
|
||||||
public virtual bool IsHidden() |
|
||||||
{ |
|
||||||
if (hideOnSelected && wasSelected) |
|
||||||
{ |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
if (hideOnCondition) |
|
||||||
{ |
|
||||||
// If no variable is selected then assume the option is visible |
|
||||||
if (variable == null) |
|
||||||
{ |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
return EvaluateCondition(); |
|
||||||
} |
|
||||||
|
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
public override void OnEnter() |
|
||||||
{ |
|
||||||
// Find next End statement at same indent level |
|
||||||
for (int i = commandIndex + 1; i < parentSequence.commandList.Count; ++i) |
|
||||||
{ |
|
||||||
End endCommand = parentSequence.commandList[i] as End; |
|
||||||
|
|
||||||
if (endCommand != null && |
|
||||||
endCommand.indentLevel == indentLevel) |
|
||||||
{ |
|
||||||
// Continue at next command after End |
|
||||||
Continue (endCommand.commandIndex + 1); |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
Continue(); |
|
||||||
} |
|
||||||
|
|
||||||
public override string GetSummary() |
|
||||||
{ |
|
||||||
if (optionText == "") |
|
||||||
{ |
|
||||||
return "Error: Option text is blank"; |
|
||||||
} |
|
||||||
|
|
||||||
return optionText; |
|
||||||
} |
|
||||||
|
|
||||||
public override bool OpenBlock() |
|
||||||
{ |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public override bool CloseBlock () |
|
||||||
{ |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
public override Color GetButtonColor() |
|
||||||
{ |
|
||||||
return new Color32(253, 253, 150, 255); |
|
||||||
} |
|
||||||
|
|
||||||
public override void OnReset() |
|
||||||
{ |
|
||||||
wasSelected = false; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Loading…
Reference in new issue