Browse Source

Show character image in Say command. Basic fallback GUI.

master
chrisgregan 10 years ago
parent
commit
d1117cccf5
  1. 49
      Assets/Fungus/Dialog/Commands/Choose.cs
  2. 44
      Assets/Fungus/Dialog/Commands/Say.cs
  3. 20
      Assets/Fungus/Dialog/Editor/CharacterEditor.cs
  4. 26
      Assets/Fungus/Dialog/Editor/SayEditor.cs
  5. BIN
      Assets/Shuttle/ShuttleGame.unity

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

@ -24,6 +24,8 @@ namespace Fungus.Script
public Character character;
public float timeoutDuration;
bool showBasicGUI;
public override void OnEnter()
{
// Remember active dialog between Choose calls
@ -31,7 +33,7 @@ namespace Fungus.Script
{
if (Choose.activeDialog == null)
{
Continue();
showBasicGUI = true;
return;
}
else
@ -109,6 +111,51 @@ namespace Fungus.Script
}
}
}
void OnGUI()
{
if (!showBasicGUI)
{
return;
}
// Draw a basic GUI to use when no uGUI dialog has been set
// Does not support drawing character images
GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical(GUILayout.Height(Screen.height));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical(new GUIStyle(GUI.skin.box));
if (character != null)
{
GUILayout.Label(character.characterName);
GUILayout.Space(10);
}
GUILayout.Label(chooseText);
foreach (Option option in options)
{
if (GUILayout.Button(option.optionText))
{
options.Clear();
showBasicGUI = false;
ExecuteSequence(option.targetSequence);
}
}
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
}
}

44
Assets/Fungus/Dialog/Commands/Say.cs

@ -18,6 +18,8 @@ namespace Fungus.Script
public bool showOnce;
int executionCount;
bool showBasicGUI;
public override void OnEnter()
{
if (showOnce && executionCount > 0)
@ -33,7 +35,7 @@ namespace Fungus.Script
{
if (activeDialog == null)
{
Continue();
showBasicGUI = true;
return;
}
else
@ -68,6 +70,46 @@ namespace Fungus.Script
return summary;
}
void OnGUI()
{
if (!showBasicGUI)
{
return;
}
// Draw a basic GUI to use when no uGUI dialog has been set
// Does not support drawing character images
GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical(GUILayout.Height(Screen.height));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical(new GUIStyle(GUI.skin.box));
if (character != null)
{
GUILayout.Label(character.characterName);
GUILayout.Space(10);
}
GUILayout.Label(storyText);
if (GUILayout.Button("Continue"))
{
showBasicGUI = false;
Continue();
}
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
}
}

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

@ -50,16 +50,15 @@ namespace Fungus.Script
if (characterImage != null &&
spriteMaterial != null)
{
float aspect = (float)characterImage.texture.width / (float)characterImage.texture.height;
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
float aspect = (float)characterImage.texture.width / (float)characterImage.texture.height;
Rect imagePreviewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(150), GUILayout.ExpandWidth(false));
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
EditorGUI.DrawPreviewTexture(imagePreviewRect,
characterImage.texture,
spriteMaterial);
DrawPreview(imagePreviewRect,
characterImage.texture);
}
if (EditorGUI.EndChangeCheck())
@ -72,6 +71,17 @@ namespace Fungus.Script
t.dialogSide = dialogSide;
}
}
public void DrawPreview(Rect previewRect, Texture2D texture)
{
if (texture == null)
{
return;
}
EditorGUI.DrawPreviewTexture(previewRect,
texture,
spriteMaterial);
}
}
}

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

@ -17,11 +17,33 @@ namespace Fungus.Script
EditorGUI.BeginChangeCheck();
EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog"));
GUIStyle sayStyle = new GUIStyle(EditorStyles.textArea);
sayStyle.wordWrap = true;
string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(30));
EditorGUILayout.BeginHorizontal();
string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(40));
if (t.character != null &&
t.character.characterImage != null &&
t.character.characterImage.texture != null)
{
Texture2D characterTexture = t.character.characterImage.texture;
float aspect = (float)characterTexture.width / (float)characterTexture.height;
Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(40), GUILayout.ExpandWidth(false));
CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor;
if (characterEditor != null)
{
characterEditor.DrawPreview(previewRect, characterTexture);
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
Character character = FungusCommandEditor.ObjectField<Character>(new GUIContent("Character", "Character to display in dialog"),
new GUIContent("<None>"),

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save