Browse Source

Pick character from drop down list

master
chrisgregan 11 years ago
parent
commit
45b7c79195
  1. 3
      Assets/Fungus/Dialog/Commands/Say.cs
  2. 8
      Assets/Fungus/Dialog/Editor/SayEditor.cs
  3. 11
      Assets/Fungus/Dialog/Scripts/DialogController.cs
  4. 32
      Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs
  5. BIN
      Assets/Shuttle/NewDialog.unity

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

@ -46,10 +46,7 @@ namespace Fungus.Script
dialogController.ShowDialog(true); dialogController.ShowDialog(true);
if (character != null)
{
dialogController.SetCharacter(character); dialogController.SetCharacter(character);
}
if (options.Count > 0) if (options.Count > 0)
{ {

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

@ -21,15 +21,15 @@ namespace Fungus.Script
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
Character character = FungusCommandEditor.ObjectField<Character>(new GUIContent("Character", "Character to display in dialog"),
new GUIContent("<None>"),
t.character);
EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog")); EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog"));
GUIStyle sayStyle = new GUIStyle(EditorStyles.textArea); GUIStyle sayStyle = new GUIStyle(EditorStyles.textArea);
sayStyle.wordWrap = true; sayStyle.wordWrap = true;
string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(30)); string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(30));
Character character = EditorGUILayout.ObjectField(new GUIContent("Character", "Character to display in dialog"),
t.character,
typeof(Character), true) as Character;
bool displayOnce = EditorGUILayout.Toggle(new GUIContent("Display Once", "Display this text once and never show it again."), t.displayOnce); bool displayOnce = EditorGUILayout.Toggle(new GUIContent("Display Once", "Display this text once and never show it again."), t.displayOnce);
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())

11
Assets/Fungus/Dialog/Scripts/DialogController.cs

@ -44,12 +44,19 @@ namespace Fungus.Script
{ {
if (character == null) if (character == null)
{ {
return; if (leftImage != null)
leftImage.enabled = false;
if (rightImage != null)
rightImage.enabled = false;
if (nameText != null)
nameText.text = "";
} }
else
{
SetCharacterImage(character.characterImage, character.dialogSide); SetCharacterImage(character.characterImage, character.dialogSide);
SetCharacterName(character.name, character.characterColor); SetCharacterName(character.name, character.characterColor);
} }
}
public void SetCharacterImage(Sprite image, DialogSide side) public void SetCharacterImage(Sprite image, DialogSide side)
{ {

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

@ -168,6 +168,38 @@ namespace Fungus.Script
} }
return copy as T; return copy as T;
} }
static public T ObjectField<T>(GUIContent label, GUIContent nullLabel, T selectedObject) where T : MonoBehaviour
{
List<GUIContent> objectNames = new List<GUIContent>();
int selectedIndex = 0;
objectNames.Add(nullLabel);
T[] objects = GameObject.FindObjectsOfType<T>();
for (int i = 0; i < objects.Length; ++i)
{
objectNames.Add(new GUIContent(objects[i].name));
if (selectedObject == objects[i])
{
selectedIndex = i + 1;
}
}
T result;
selectedIndex = EditorGUILayout.Popup(label, selectedIndex, objectNames.ToArray());
if (selectedIndex == 0)
{
result = null; // Null option
}
else
{
result = objects[selectedIndex - 1];
}
return result;
}
} }
} }

BIN
Assets/Shuttle/NewDialog.unity

Binary file not shown.
Loading…
Cancel
Save