Browse Source

Added per-character typing sound effect. Added continue click cool down timer.

master
chrisgregan 10 years ago
parent
commit
f442561d38
  1. 40
      Assets/Examples/TheHunter/TheHunter.unity
  2. 6
      Assets/Fungus/Dialog/Editor/CharacterEditor.cs
  3. 1
      Assets/Fungus/Dialog/Scripts/Character.cs
  4. 32
      Assets/Fungus/Dialog/Scripts/Dialog.cs

40
Assets/Examples/TheHunter/TheHunter.unity

@ -506,6 +506,14 @@ Prefab:
propertyPath: nameColor.b propertyPath: nameColor.b
value: .949019611 value: .949019611
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11400000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
propertyPath: typingSound
value:
objectReference: {fileID: 8300000, guid: 0dc7e509ace954462bc8ab20fcb68d60, type: 3}
- target: {fileID: 11400000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
propertyPath: soundEffect
value:
objectReference: {fileID: 8300000, guid: 0dc7e509ace954462bc8ab20fcb68d60, type: 3}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: b20518d45890e4be59ba82946f88026c, type: 2} m_ParentPrefab: {fileID: 100100000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
m_RootGameObject: {fileID: 339869592} m_RootGameObject: {fileID: 339869592}
@ -575,6 +583,14 @@ Prefab:
propertyPath: nameColor.b propertyPath: nameColor.b
value: .168685108 value: .168685108
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11400000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
propertyPath: typingSound
value:
objectReference: {fileID: 8300000, guid: 9b3be2062b59848a2bd178f5748b386d, type: 3}
- target: {fileID: 11400000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
propertyPath: soundEffect
value:
objectReference: {fileID: 8300000, guid: 9b3be2062b59848a2bd178f5748b386d, type: 3}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: b20518d45890e4be59ba82946f88026c, type: 2} m_ParentPrefab: {fileID: 100100000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
m_RootGameObject: {fileID: 686889651} m_RootGameObject: {fileID: 686889651}
@ -845,6 +861,14 @@ Prefab:
propertyPath: nameColor.b propertyPath: nameColor.b
value: .349019617 value: .349019617
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11400000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
propertyPath: typingSound
value:
objectReference: {fileID: 8300000, guid: 23e52ab29f28743309c85b6d7bdc8ad6, type: 3}
- target: {fileID: 11400000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
propertyPath: soundEffect
value:
objectReference: {fileID: 8300000, guid: 23e52ab29f28743309c85b6d7bdc8ad6, type: 3}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: b20518d45890e4be59ba82946f88026c, type: 2} m_ParentPrefab: {fileID: 100100000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
m_RootGameObject: {fileID: 338947446} m_RootGameObject: {fileID: 338947446}
@ -914,6 +938,14 @@ Prefab:
propertyPath: nameColor.b propertyPath: nameColor.b
value: .196078435 value: .196078435
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11400000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
propertyPath: typingSound
value:
objectReference: {fileID: 8300000, guid: 124184555ec434aa68814be3bd116c26, type: 3}
- target: {fileID: 11400000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
propertyPath: soundEffect
value:
objectReference: {fileID: 8300000, guid: 124184555ec434aa68814be3bd116c26, type: 3}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: b20518d45890e4be59ba82946f88026c, type: 2} m_ParentPrefab: {fileID: 100100000, guid: b20518d45890e4be59ba82946f88026c, type: 2}
m_RootGameObject: {fileID: 1712414753} m_RootGameObject: {fileID: 1712414753}
@ -1086,7 +1118,7 @@ MonoBehaviour:
nameText: Shay nameText: Shay
nameColor: {r: .933333337, g: .772549033, b: .349019617, a: 1} nameColor: {r: .933333337, g: .772549033, b: .349019617, a: 1}
profileSprite: {fileID: 21300000, guid: f7484a661774243b193bebc6e3ae5120, type: 3} profileSprite: {fileID: 21300000, guid: f7484a661774243b193bebc6e3ae5120, type: 3}
typingSound: {fileID: 0} soundEffect: {fileID: 8300000, guid: 23e52ab29f28743309c85b6d7bdc8ad6, type: 3}
notes: notes:
--- !u!1 &339869592 --- !u!1 &339869592
GameObject: GameObject:
@ -1119,7 +1151,7 @@ MonoBehaviour:
nameText: Skipper nameText: Skipper
nameColor: {r: .294117659, g: .650980413, b: .949019611, a: 1} nameColor: {r: .294117659, g: .650980413, b: .949019611, a: 1}
profileSprite: {fileID: 21300000, guid: 3c64e30cbefbe4e768ef68d85c85061e, type: 3} profileSprite: {fileID: 21300000, guid: 3c64e30cbefbe4e768ef68d85c85061e, type: 3}
typingSound: {fileID: 0} soundEffect: {fileID: 8300000, guid: 0dc7e509ace954462bc8ab20fcb68d60, type: 3}
notes: notes:
--- !u!4 &339869594 --- !u!4 &339869594
Transform: Transform:
@ -1999,7 +2031,7 @@ MonoBehaviour:
nameText: Badly Drawn Bear nameText: Badly Drawn Bear
nameColor: {r: .95588237, g: .347840369, b: .168685108, a: 1} nameColor: {r: .95588237, g: .347840369, b: .168685108, a: 1}
profileSprite: {fileID: 21300000, guid: 62955e2782fd34c5ca3e78712625ae50, type: 3} profileSprite: {fileID: 21300000, guid: 62955e2782fd34c5ca3e78712625ae50, type: 3}
typingSound: {fileID: 0} soundEffect: {fileID: 8300000, guid: 9b3be2062b59848a2bd178f5748b386d, type: 3}
notes: notes:
--- !u!4 &686889653 --- !u!4 &686889653
Transform: Transform:
@ -5018,7 +5050,7 @@ MonoBehaviour:
nameText: Ciara nameText: Ciara
nameColor: {r: .925490201, g: .482352942, b: .196078435, a: 1} nameColor: {r: .925490201, g: .482352942, b: .196078435, a: 1}
profileSprite: {fileID: 21300000, guid: 05ccd53483a554ca9b31f685fa76154a, type: 3} profileSprite: {fileID: 21300000, guid: 05ccd53483a554ca9b31f685fa76154a, type: 3}
typingSound: {fileID: 0} soundEffect: {fileID: 8300000, guid: 124184555ec434aa68814be3bd116c26, type: 3}
notes: notes:
--- !u!1001 &1725106525 --- !u!1001 &1725106525
Prefab: Prefab:

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

@ -13,6 +13,7 @@ namespace Fungus
protected SerializedProperty nameTextProp; protected SerializedProperty nameTextProp;
protected SerializedProperty nameColorProp; protected SerializedProperty nameColorProp;
protected SerializedProperty profileSpriteProp; protected SerializedProperty profileSpriteProp;
protected SerializedProperty soundEffectProp;
protected SerializedProperty notesProp; protected SerializedProperty notesProp;
protected virtual void OnEnable() protected virtual void OnEnable()
@ -20,6 +21,7 @@ namespace Fungus
nameTextProp = serializedObject.FindProperty ("nameText"); nameTextProp = serializedObject.FindProperty ("nameText");
nameColorProp = serializedObject.FindProperty ("nameColor"); nameColorProp = serializedObject.FindProperty ("nameColor");
profileSpriteProp = serializedObject.FindProperty ("profileSprite"); profileSpriteProp = serializedObject.FindProperty ("profileSprite");
soundEffectProp = serializedObject.FindProperty ("soundEffect");
notesProp = serializedObject.FindProperty ("notes"); notesProp = serializedObject.FindProperty ("notes");
Shader shader = Shader.Find("Sprites/Default"); Shader shader = Shader.Find("Sprites/Default");
@ -40,11 +42,9 @@ namespace Fungus
serializedObject.Update(); serializedObject.Update();
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"));
EditorGUILayout.PropertyField(profileSpriteProp, new GUIContent("Image", "Character image sprite to display in the dialog")); EditorGUILayout.PropertyField(profileSpriteProp, new GUIContent("Image", "Character image sprite to display in the dialog"));
EditorGUILayout.PropertyField(soundEffectProp, new GUIContent("Sound Effect", "Sound to play when the character is talking. Overrides the setting in the Dialog."));
EditorGUILayout.PropertyField(notesProp, new GUIContent("Notes", "Notes about this story character (personality, attibutes, etc.)")); EditorGUILayout.PropertyField(notesProp, new GUIContent("Notes", "Notes about this story character (personality, attibutes, etc.)"));
EditorGUILayout.Separator(); EditorGUILayout.Separator();

1
Assets/Fungus/Dialog/Scripts/Character.cs

@ -11,6 +11,7 @@ namespace Fungus
public string nameText; // We need a separate name as the object name is used for character variations (e.g. "Smurf Happy", "Smurf Sad") public string nameText; // We need a separate name as the object name is used for character variations (e.g. "Smurf Happy", "Smurf Sad")
public Color nameColor = Color.white; public Color nameColor = Color.white;
public Sprite profileSprite; public Sprite profileSprite;
public AudioClip soundEffect;
[TextArea(5,10)] [TextArea(5,10)]
public string notes; public string notes;

32
Assets/Fungus/Dialog/Scripts/Dialog.cs

@ -23,6 +23,7 @@ namespace Fungus
public Text nameText; public Text nameText;
public Text storyText; public Text storyText;
public Image characterImage; public Image characterImage;
public AudioClip characterTypingSound;
protected float currentSpeed; protected float currentSpeed;
protected float currentPunctuationPause; protected float currentPunctuationPause;
@ -30,6 +31,7 @@ namespace Fungus
protected bool italicActive; protected bool italicActive;
protected bool colorActive; protected bool colorActive;
protected string colorText; protected string colorText;
protected float clickCooldownTimer;
protected bool wasPointerClicked; protected bool wasPointerClicked;
@ -61,10 +63,18 @@ namespace Fungus
{ {
wasPointerClicked = false; wasPointerClicked = false;
if (clickAnywhere && if (clickCooldownTimer > 0f)
{
clickCooldownTimer -= Time.deltaTime;
clickCooldownTimer = Mathf.Max(0, clickCooldownTimer);
}
if (clickCooldownTimer == 0f &&
clickAnywhere &&
Input.GetMouseButtonDown(0)) Input.GetMouseButtonDown(0))
{ {
wasPointerClicked = true; wasPointerClicked = true;
clickCooldownTimer = 0.2f;
} }
} }
@ -84,6 +94,7 @@ namespace Fungus
characterImage.enabled = false; characterImage.enabled = false;
if (nameText != null) if (nameText != null)
nameText.text = ""; nameText.text = "";
characterTypingSound = null;
} }
else else
{ {
@ -96,8 +107,11 @@ namespace Fungus
characterName = character.name; characterName = character.name;
} }
characterTypingSound = character.soundEffect;
SetCharacterName(characterName, character.nameColor); SetCharacterName(characterName, character.nameColor);
} }
} }
public virtual void SetCharacterImage(Sprite image) public virtual void SetCharacterImage(Sprite image)
@ -159,7 +173,14 @@ namespace Fungus
{ {
typingAudio = new GameObject("WritingSound"); typingAudio = new GameObject("WritingSound");
typingAudio.AddComponent<AudioSource>(); typingAudio.AddComponent<AudioSource>();
typingAudio.audio.clip = writingSound; if (characterTypingSound != null)
{
typingAudio.audio.clip = characterTypingSound;
}
else
{
typingAudio.audio.clip = writingSound;
}
typingAudio.audio.loop = loopWritingSound; typingAudio.audio.loop = loopWritingSound;
typingAudio.audio.Play(); typingAudio.audio.Play();
} }
@ -320,6 +341,7 @@ namespace Fungus
typingAudio.audio.Play(); typingAudio.audio.Play();
timeAccumulator = 0f; timeAccumulator = 0f;
currentSpeed = writingSpeed;
OnWaitForInputTag(false); OnWaitForInputTag(false);
break; break;
@ -336,6 +358,7 @@ namespace Fungus
OnWaitForInputTag(false); OnWaitForInputTag(false);
timeAccumulator = 0f; timeAccumulator = 0f;
currentSpeed = writingSpeed;
storyText.text = ""; storyText.text = "";
break; break;
@ -589,7 +612,10 @@ namespace Fungus
public virtual void OnPointerClick() public virtual void OnPointerClick()
{ {
wasPointerClicked = true; if (clickCooldownTimer == 0f)
{
wasPointerClicked = true;
}
} }
} }

Loading…
Cancel
Save