Add audio to dialogues

This commit is contained in:
Michal Pikulski
2025-10-17 15:20:29 +02:00
parent 2fe872d8dc
commit c3c9fd95a4
14 changed files with 322 additions and 46 deletions

View File

@@ -26,6 +26,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: 4728896231509914993, guid: 27419b0e3639a3e4184d676890da073a, type: 3}
_audio: {fileID: 8300000, guid: 975d8d57c80dbbd478eff9545f015f8f, type: 3}
- rid: 4008004961021984848
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -33,6 +34,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -1125559343802010594, guid: 46b2fe6896b27cc4c8bd9f0da3f0de50, type: 3}
_audio: {fileID: 8300000, guid: 975d8d57c80dbbd478eff9545f015f8f, type: 3}
- rid: 4008004961021984849
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -40,6 +42,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -642587728066523507, guid: 95d6dbee5cb1f694c971791ee60cad14, type: 3}
_audio: {fileID: 8300000, guid: 975d8d57c80dbbd478eff9545f015f8f, type: 3}
- rid: 4008004961021984850
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -47,6 +50,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -8438005379329254897, guid: fe735eb4f8856904caec179520dcb92f, type: 3}
_audio: {fileID: 8300000, guid: 975d8d57c80dbbd478eff9545f015f8f, type: 3}
- rid: 4008004961021984866
type: {class: UserNodeModelImp, ns: Unity.GraphToolkit.Editor.Implementation, asm: Unity.GraphToolkit.Editor}
data:

View File

@@ -424,6 +424,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -454384845472657506, guid: bbfabe7e36be4f341a775b4323900b5b, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799721
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -435,6 +436,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -5941552768301239376, guid: 300528d856c15824989bade57a7e04e4, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799723
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -446,6 +448,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -5941552768301239376, guid: 300528d856c15824989bade57a7e04e4, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799725
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:

View File

@@ -479,6 +479,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -3811075571101519331, guid: cf5af87e6a25e9442b89f069b894a5fd, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799811
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -490,6 +491,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -5941552768301239376, guid: 300528d856c15824989bade57a7e04e4, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799813
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -501,6 +503,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -5941552768301239376, guid: 300528d856c15824989bade57a7e04e4, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799815
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:

View File

@@ -479,6 +479,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: 21300000, guid: 34b9ddb77aae2df4ab489b7bb8f16cff, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799855
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -490,6 +491,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -5941552768301239376, guid: 300528d856c15824989bade57a7e04e4, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799857
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -501,6 +503,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -5941552768301239376, guid: 300528d856c15824989bade57a7e04e4, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799859
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:

View File

@@ -479,6 +479,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -8203946286166492161, guid: 6cb19dd8ad625c543abe9aa233cd676d, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799899
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -490,6 +491,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -5941552768301239376, guid: 300528d856c15824989bade57a7e04e4, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799901
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -501,6 +503,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -5941552768301239376, guid: 300528d856c15824989bade57a7e04e4, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799903
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:

View File

@@ -89,6 +89,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: 1487011052474782424, guid: f489e2c9ce64ff34aa3c7a91a4edbd77, type: 3}
_audio: {fileID: 0}
- rid: 4008004961314799763
type: {class: 'Constant`1[[System.Boolean, mscorlib]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -167,6 +168,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: 1487011052474782424, guid: f489e2c9ce64ff34aa3c7a91a4edbd77, type: 3}
_audio: {fileID: 0}
- rid: 7772910664224079994
type: {class: GraphModelImp, ns: Unity.GraphToolkit.Editor.Implementation, asm: Unity.GraphToolkit.Editor}
data:

View File

@@ -1123,6 +1123,7 @@ MonoBehaviour:
_contentType: 0
_text: Hey boy, go on and pick up that ass over there!
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976304
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1130,6 +1131,7 @@ MonoBehaviour:
_contentType: 0
_text: "Go on, it's right there!\t\t"
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976305
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1137,6 +1139,7 @@ MonoBehaviour:
_contentType: 0
_text: I need ASS!
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976306
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1144,6 +1147,7 @@ MonoBehaviour:
_contentType: 0
_text: C'mon, don't be like this!
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976307
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1151,6 +1155,7 @@ MonoBehaviour:
_contentType: 0
_text: Yessss, that's the stuff, now chop it!
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976308
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1158,6 +1163,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: 6282751622250221668, guid: 204325ac88be74d4d882a078c64cf5e1, type: 3}
_audio: {fileID: 0}
- rid: 7545629632211976309
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1165,6 +1171,7 @@ MonoBehaviour:
_contentType: 0
_text: Chop it!!
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976310
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1172,6 +1179,7 @@ MonoBehaviour:
_contentType: 0
_text: Good, shit now cook!
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976311
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1179,6 +1187,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: 6282751622250221668, guid: 204325ac88be74d4d882a078c64cf5e1, type: 3}
_audio: {fileID: 0}
- rid: 7545629632211976312
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1186,6 +1195,7 @@ MonoBehaviour:
_contentType: 0
_text: What exactly are you cooking?!
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976313
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1193,6 +1203,7 @@ MonoBehaviour:
_contentType: 0
_text: What exactly are you cooking?!
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976314
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -1200,3 +1211,4 @@ MonoBehaviour:
_contentType: 0
_text: Yessssss, thanks!
_image: {fileID: 0}
_audio: {fileID: 0}

View File

@@ -656,6 +656,7 @@ MonoBehaviour:
_contentType: 0
_text: Some other test
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976295
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -663,6 +664,7 @@ MonoBehaviour:
_contentType: 0
_text: Some much longer text in here etc.
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976296
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -670,6 +672,7 @@ MonoBehaviour:
_contentType: 0
_text: Some oooother text
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976297
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -677,6 +680,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -765527507412255412, guid: f70246e6148769846aaea223ec0c2a55, type: 3}
_audio: {fileID: 0}
- rid: 7545629632211976298
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -684,6 +688,7 @@ MonoBehaviour:
_contentType: 0
_text: Now it's text
_image: {fileID: -9213056636207805707, guid: 00354ded9d8f8d643acc14837a229544, type: 3}
_audio: {fileID: 0}
- rid: 7545629632211976301
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -691,6 +696,7 @@ MonoBehaviour:
_contentType: 0
_text: Psst, I'm just testing some stuff df
_image: {fileID: 0}
_audio: {fileID: 0}
- rid: 7545629632211976302
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -698,6 +704,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -9213056636207805707, guid: 00354ded9d8f8d643acc14837a229544, type: 3}
_audio: {fileID: 0}
- rid: 7545629632211976322
type: {class: WireModel, ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -737,6 +744,7 @@ MonoBehaviour:
_contentType: 1
_text:
_image: {fileID: -9213056636207805707, guid: 00354ded9d8f8d643acc14837a229544, type: 3}
_audio: {fileID: 0}
- rid: 7545629632211976324
type: {class: 'Constant`1[[Dialogue.DialogueContent, AppleHillsScripts]]', ns: Unity.GraphToolkit.Editor, asm: Unity.GraphToolkit.Internal.Editor}
data:
@@ -744,3 +752,4 @@ MonoBehaviour:
_contentType: 0
_text: Now it's text again and it should loop!
_image: {fileID: -9213056636207805707, guid: 00354ded9d8f8d643acc14837a229544, type: 3}
_audio: {fileID: 0}

View File

@@ -11,33 +11,44 @@ namespace Dialogue.Editor
{
// Height constants
private const float TypeSelectorHeight = 20f;
private const float PropertySpacing = 2f;
private const float PropertySpacing = 2f; // Reduced spacing for tighter layout
private const float TextFieldHeight = 40f; // Taller for multi-line text
private const float ImageFieldHeight = 18f;
private const float AudioFieldHeight = 18f;
private const float PreviewHeight = 64f;
// Track the last assigned sprite to detect changes
private static Sprite lastAssignedSprite;
private static string lastAssignedPropertyPath;
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var contentTypeProperty = property.FindPropertyRelative("_contentType");
var imageProperty = property.FindPropertyRelative("_image");
// Start with base height for type selector
var height = TypeSelectorHeight + PropertySpacing;
// Add height based on content type
if (contentTypeProperty.enumValueIndex == (int)DialogueContentType.Text)
{
height += TextFieldHeight;
height += TextFieldHeight + PropertySpacing;
}
else // Image
{
height += ImageFieldHeight;
height += ImageFieldHeight + PropertySpacing;
// Add preview height if an image is assigned
var imageProperty = property.FindPropertyRelative("_image");
// Add preview height if an image is assigned - make sure it's AFTER the image field
// but BEFORE the audio field
if (imageProperty.objectReferenceValue != null)
{
height += PropertySpacing + PreviewHeight;
height += PreviewHeight + PropertySpacing;
}
}
// Add height for audio field (always displayed)
height += AudioFieldHeight;
return height;
}
@@ -54,15 +65,58 @@ namespace Dialogue.Editor
var contentTypeProperty = property.FindPropertyRelative("_contentType");
var textProperty = property.FindPropertyRelative("_text");
var imageProperty = property.FindPropertyRelative("_image");
var audioProperty = property.FindPropertyRelative("_audio");
// Calculate rects
var typeRect = new Rect(contentRect.x, contentRect.y, contentRect.width, TypeSelectorHeight);
// Check for sprite changes and force repaint if needed
var currentSprite = imageProperty.objectReferenceValue as Sprite;
if (currentSprite != lastAssignedSprite && property.propertyPath == lastAssignedPropertyPath)
{
// Sprite changed, force a layout recalculation
EditorUtility.SetDirty(property.serializedObject.targetObject);
GUI.changed = true;
}
// Track current y position as we add controls
float currentY = contentRect.y;
// Calculate type rect
var typeRect = new Rect(contentRect.x, currentY, contentRect.width, TypeSelectorHeight);
currentY += TypeSelectorHeight + PropertySpacing;
// Calculate content field rect based on the content type
var contentHeight = contentTypeProperty.enumValueIndex == (int)DialogueContentType.Text ?
TextFieldHeight : ImageFieldHeight;
var contentFieldRect = new Rect(
contentRect.x,
contentRect.y + TypeSelectorHeight + PropertySpacing,
currentY,
contentRect.width,
contentTypeProperty.enumValueIndex == (int)DialogueContentType.Text ? TextFieldHeight : ImageFieldHeight);
contentHeight);
currentY += contentHeight + PropertySpacing;
// If we have an image and it's selected, calculate preview rect
Rect previewRect = Rect.zero;
if (contentTypeProperty.enumValueIndex == (int)DialogueContentType.Image &&
imageProperty.objectReferenceValue != null)
{
previewRect = new Rect(
contentRect.x,
currentY,
contentRect.width,
PreviewHeight);
currentY += PreviewHeight + PropertySpacing;
}
// Calculate audio field rect
var audioFieldRect = new Rect(
contentRect.x,
currentY,
contentRect.width,
AudioFieldHeight);
// Now draw all the controls
// Draw the content type dropdown
EditorGUI.PropertyField(typeRect, contentTypeProperty, GUIContent.none);
@@ -78,8 +132,27 @@ namespace Dialogue.Editor
}
else // Image
{
// Store the sprite before drawing the field to detect changes
var previousSprite = imageProperty.objectReferenceValue as Sprite;
// Draw the image field
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(contentFieldRect, imageProperty, GUIContent.none);
if (EditorGUI.EndChangeCheck())
{
// Image changed, store the property path so we can detect which property changed
lastAssignedPropertyPath = property.propertyPath;
lastAssignedSprite = imageProperty.objectReferenceValue as Sprite;
// Force an inspector update to recalculate layout
EditorUtility.SetDirty(property.serializedObject.targetObject);
// Mark the scene as dirty to ensure serialization and proper layout refresh
if (!EditorApplication.isPlaying)
{
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(
UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
}
}
// Draw a preview if an image is assigned
if (imageProperty.objectReferenceValue != null)
@@ -87,44 +160,58 @@ namespace Dialogue.Editor
var sprite = imageProperty.objectReferenceValue as Sprite;
if (sprite != null)
{
var previewRect = new Rect(
contentRect.x,
contentFieldRect.y + contentFieldRect.height + PropertySpacing,
contentRect.width,
PreviewHeight);
// Draw the preview with preserved aspect ratio
DrawSpritePreview(previewRect, sprite);
}
}
}
// Draw the audio field (always displayed regardless of content type)
EditorGUI.PropertyField(audioFieldRect, audioProperty, new GUIContent("Audio"));
// Restore indent
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
private void DrawSpritePreview(Rect position, Sprite sprite)
// Helper method to draw a sprite preview with preserved aspect ratio
private void DrawSpritePreview(Rect rect, Sprite sprite)
{
if (sprite == null || sprite.texture == null) return;
if (sprite == null || sprite.texture == null)
return;
var texture = sprite.texture;
var spriteRect = sprite.rect;
var aspectRatio = spriteRect.width / spriteRect.height;
// Calculate aspect-preserved rect
float aspectRatio = sprite.rect.width / sprite.rect.height;
float targetWidth = Mathf.Min(position.width, position.height * aspectRatio);
float targetHeight = targetWidth / aspectRatio;
// Calculate preview rect while preserving aspect ratio within our fixed area
Rect previewRect = rect;
// Center the preview
Rect previewRect = new Rect(
position.x + (position.width - targetWidth) * 0.5f,
position.y + (position.height - targetHeight) * 0.5f,
targetWidth,
targetHeight
);
// Limit the display size to the allocated space while maintaining aspect ratio
if (aspectRatio > 1f) // Wider than tall
{
previewRect.height = Mathf.Min(rect.width / aspectRatio, rect.height);
previewRect.y += (rect.height - previewRect.height) * 0.5f;
}
else // Taller than wide or square
{
previewRect.width = Mathf.Min(rect.height * aspectRatio, rect.width);
previewRect.x += (rect.width - previewRect.width) * 0.5f;
}
// Draw the sprite preview
EditorGUI.DrawPreviewTexture(previewRect, sprite.texture, null, ScaleMode.ScaleToFit);
// Constrain the preview to the allocated space
previewRect.height = Mathf.Min(previewRect.height, rect.height);
previewRect.width = Mathf.Min(previewRect.width, rect.width);
// Draw a border around the preview
GUI.Box(previewRect, GUIContent.none);
// Draw preview with a dark background for better visibility
EditorGUI.DrawRect(rect, new Color(0.1f, 0.1f, 0.1f, 1f));
GUI.DrawTexture(previewRect, texture, ScaleMode.ScaleToFit);
// Draw sprite bounds
EditorGUI.DrawRect(new Rect(previewRect.x, previewRect.y, previewRect.width, 1), Color.gray);
EditorGUI.DrawRect(new Rect(previewRect.x, previewRect.y + previewRect.height - 1, previewRect.width, 1), Color.gray);
EditorGUI.DrawRect(new Rect(previewRect.x, previewRect.y, 1, previewRect.height), Color.gray);
EditorGUI.DrawRect(new Rect(previewRect.x + previewRect.width - 1, previewRect.y, 1, previewRect.height), Color.gray);
}
}
}

View File

@@ -427,6 +427,10 @@ PrefabInstance:
propertyPath: m_Name
value: FootballBird
objectReference: {fileID: 0}
- target: {fileID: 1972611059221495588, guid: 9b2d5618c8cc81743b982c6cc8d95871, type: 3}
propertyPath: stepData
value:
objectReference: {fileID: 0}
- target: {fileID: 7465517589433942351, guid: 9b2d5618c8cc81743b982c6cc8d95871, type: 3}
propertyPath: m_LocalPosition.x
value: 0.15

View File

@@ -518,6 +518,10 @@ PrefabInstance:
propertyPath: m_Name
value: HammerBird
objectReference: {fileID: 0}
- target: {fileID: 1972611059221495588, guid: e3d6494020df3a34f88a89f0ee9a3527, type: 3}
propertyPath: stepData
value:
objectReference: {fileID: 0}
- target: {fileID: 7465517589433942351, guid: e3d6494020df3a34f88a89f0ee9a3527, type: 3}
propertyPath: m_LocalPosition.x
value: 1.25

View File

@@ -466944,6 +466944,9 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 5172497182660285677, guid: 0c2275f0a1451a142b686a049a2ebcec, type: 3}
insertIndex: -1
addedObject: {fileID: 2117822313}
- targetCorrespondingSourceObject: {fileID: 5172497182660285677, guid: 0c2275f0a1451a142b686a049a2ebcec, type: 3}
insertIndex: -1
addedObject: {fileID: 2117822314}
m_SourcePrefab: {fileID: 100100000, guid: 0c2275f0a1451a142b686a049a2ebcec, type: 3}
--- !u!4 &2117822311 stripped
Transform:
@@ -466968,6 +466971,103 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier: AppleHillsScripts::Dialogue.DialogueComponent
dialogueGraph: {fileID: 3965311268370046156, guid: ef08ef9a5b2f5064a889414ba2244a62, type: 3}
--- !u!82 &2117822314
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2117822312}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_Resource: {fileID: 0}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1001 &2122075105
PrefabInstance:
m_ObjectHideFlags: 0

View File

@@ -9,6 +9,7 @@ using PuzzleS;
namespace Dialogue
{
[AddComponentMenu("AppleHills/Dialogue/Dialogue Component")]
[RequireComponent(typeof(AudioSource))]
public class DialogueComponent : MonoBehaviour
{
[SerializeField] private RuntimeDialogueGraph dialogueGraph;
@@ -17,6 +18,7 @@ namespace Dialogue
private int currentLineIndex;
private bool initialized = false;
private SpeechBubble speechBubble;
private AudioSource audioSource;
// Flag to track when a condition has been met but dialogue hasn't advanced yet
private bool _conditionSatisfiedPendingAdvance = false;
@@ -35,6 +37,15 @@ namespace Dialogue
private void Start()
{
// Get required components
audioSource = GetComponent<AudioSource>();
speechBubble = GetComponentInChildren<SpeechBubble>();
if (speechBubble == null)
{
Debug.LogError("SpeechBubble component is missing on Dialogue Component");
}
// Register for global events
if (PuzzleManager.Instance != null)
PuzzleManager.Instance.OnStepCompleted += OnAnyPuzzleStepCompleted;
@@ -49,13 +60,6 @@ namespace Dialogue
ItemManager.Instance.OnItemsCombined += OnAnyItemsCombined;
}
speechBubble = GetComponentInChildren<SpeechBubble>();
if (speechBubble == null)
{
Debug.LogError("SpeechBubble component is missing on Dialogue Component");
}
// Auto-start the dialogue
// StartDialogue();
@@ -88,6 +92,9 @@ namespace Dialogue
// and pass whether there are more lines available for prompt display
speechBubble.DisplayDialogueContent(content, HasAnyLines());
// Play audio if available
PlayDialogueAudio(content.Audio);
// Log the content type for debugging
Logging.Debug($"Displaying content type: {content.ContentType} - {(content.ContentType == DialogueContentType.Text ? content.Text : content.Image?.name)}");
}
@@ -101,7 +108,28 @@ namespace Dialogue
Logging.Debug($"Displaying legacy text: {line}");
}
}
/// <summary>
/// Play the audio clip for the current dialogue content
/// </summary>
/// <param name="clip">Audio clip to play</param>
private void PlayDialogueAudio(AudioClip clip)
{
// Stop any currently playing audio
if (audioSource.isPlaying)
{
audioSource.Stop();
}
// Play the new clip if it exists
if (clip != null)
{
audioSource.clip = clip;
audioSource.Play();
Logging.Debug($"Playing dialogue audio: {clip.name}");
}
}
/// <summary>
/// Get the current dialogue content (text or image)
/// </summary>

View File

@@ -21,6 +21,7 @@ namespace Dialogue
[SerializeField] private DialogueContentType _contentType = DialogueContentType.Text;
[SerializeField] private string _text = string.Empty;
[SerializeField] private Sprite _image = null;
[SerializeField] private AudioClip _audio = null;
/// <summary>
/// The type of content this entry contains
@@ -37,16 +38,23 @@ namespace Dialogue
/// </summary>
public Sprite Image => _image;
/// <summary>
/// The audio clip to play with this content
/// </summary>
public AudioClip Audio => _audio;
/// <summary>
/// Create text content
/// </summary>
/// <param name="text">The text to display</param>
public static DialogueContent CreateText(string text)
/// <param name="audio">Optional audio clip to play</param>
public static DialogueContent CreateText(string text, AudioClip audio = null)
{
return new DialogueContent
{
_contentType = DialogueContentType.Text,
_text = text
_text = text,
_audio = audio
};
}
@@ -54,12 +62,14 @@ namespace Dialogue
/// Create image content
/// </summary>
/// <param name="image">The image to display</param>
public static DialogueContent CreateImage(Sprite image)
/// <param name="audio">Optional audio clip to play</param>
public static DialogueContent CreateImage(Sprite image, AudioClip audio = null)
{
return new DialogueContent
{
_contentType = DialogueContentType.Image,
_image = image
_image = image,
_audio = audio
};
}
@@ -68,9 +78,13 @@ namespace Dialogue
/// </summary>
public override string ToString()
{
return ContentType == DialogueContentType.Text
string contentDesc = ContentType == DialogueContentType.Text
? $"Text: {_text}"
: $"Image: {_image?.name ?? "None"}";
return _audio != null
? $"{contentDesc} (with audio: {_audio.name})"
: contentDesc;
}
}
}