added sound in color completion

This commit is contained in:
Mausham
2026-07-08 18:36:36 +05:45
parent ecc2dd3dff
commit f6d672995e
167 changed files with 1895 additions and 562 deletions

View File

@@ -7,8 +7,11 @@ using Darkmatter.Core.Contracts.Features.DrawingCatalog;
using Darkmatter.Core.Contracts.Features.GameplayFlow;
using Darkmatter.Core.Contracts.Features.History;
using Darkmatter.Core.Contracts.Services.Assets;
using Darkmatter.Core.Contracts.Services.Audio;
using Darkmatter.Core.Data.Dynamic.Services.Audio;
using Darkmatter.Core.Data.Signals.Features.Coloring;
using Darkmatter.Core.Data.Static.Features.Coloring;
using Darkmatter.Core.Enums.Services.Audio;
using Darkmatter.Features.Coloring.Commands;
using Darkmatter.Features.Coloring.UI;
using Darkmatter.Libs.Observer;
@@ -28,11 +31,14 @@ public class ColoringController : IColoringController, IDisposable
private readonly IUndoStack _history;
private readonly IGameplaySceneRefs _refs;
private readonly ColorPaletteHolderView _paletteHolder;
private readonly IAudioService _audioService;
private GameObject _colorInstance;
private GameObject _colorButtonPrefab;
private GameObject _completionAnimationInstance;
private CompletionAnimationView _completionAnimationView;
private AudioClip _completionSound;
private AudioHandle _completionSoundHandle = AudioHandle.Invalid;
private readonly ColoringPinchZoomController _pinchZoom;
private bool _isPlayingCompletionAnimation;
private readonly List<ColorRegionView> _regions = new();
@@ -47,7 +53,8 @@ public class ColoringController : IColoringController, IDisposable
IAssetProviderService assetProviderService,
IUndoStack history,
IGameplaySceneRefs refs,
ColorPaletteHolderView paletteHolder)
ColorPaletteHolderView paletteHolder,
IAudioService audioService)
{
_repository = repository;
_buttonFactory = buttonFactory;
@@ -57,6 +64,7 @@ public class ColoringController : IColoringController, IDisposable
_pinchZoom = pinchZoom;
_refs = refs;
_paletteHolder = paletteHolder;
_audioService = audioService;
}
public async UniTask InitializeRegionsAsync(IDrawingTemplate template,
@@ -117,6 +125,7 @@ public class ColoringController : IColoringController, IDisposable
_pinchZoom.ResetZoom();
_completionAnimationInstance.SetActive(true);
_isPlayingCompletionAnimation = true;
PlayCompletionSound();
try
{
await _completionAnimationView.PlayAsync(ct);
@@ -129,6 +138,23 @@ public class ColoringController : IColoringController, IDisposable
}
}
// Starts the template's completion sound together with the completion animation.
// A OneShot is left to finish naturally on success; StopCompletionSound() (called from
// Clear) cuts it off if the controller is torn down mid-play.
private void PlayCompletionSound()
{
if (_audioService == null || _completionSound == null) return;
_completionSoundHandle = _audioService.Play(
new AudioRequest(_completionSound, AudioChannel.Sfx, AudioPlayMode.OneShot));
}
private void StopCompletionSound()
{
if (_audioService != null && _completionSoundHandle.IsValid)
_audioService.Stop(_completionSoundHandle);
_completionSoundHandle = AudioHandle.Invalid;
}
public bool HasNonAuthoredColors
{
get
@@ -167,6 +193,7 @@ public class ColoringController : IColoringController, IDisposable
{
_history.Drop();
_isPlayingCompletionAnimation = false;
StopCompletionSound();
foreach (var button in _buttons)
if (button != null)
@@ -182,6 +209,7 @@ public class ColoringController : IColoringController, IDisposable
_completionAnimationInstance = null;
_completionAnimationView = null;
}
_completionSound = null;
if (_colorInstance != null)
{
@@ -205,6 +233,7 @@ public class ColoringController : IColoringController, IDisposable
_completionAnimationView = _completionAnimationInstance.GetComponentInChildren<CompletionAnimationView>(includeInactive: true);
_completionAnimationInstance.SetActive(false);
}
_completionSound = template.CompletionSound;
var views = _colorInstance.GetComponentsInChildren<ColorRegionView>(includeInactive: true);
foreach (var region in views)

View File

@@ -217,6 +217,11 @@ namespace Darkmatter.Features.DrawingTemplates.Editor
: $"{t.Difficulty} (auto: {t.Pieces.Count} pieces + {t.AuthoredRegions.Count} regions)"));
EditorGUILayout.PropertyField(so.FindProperty("defaultThumbnail"));
EditorGUILayout.Space(6);
EditorGUILayout.LabelField("Sound", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(so.FindProperty("completionSound"),
new GUIContent("Completion Sound (MP3)", "Audio clip (e.g. an imported .mp3) played in sync with the completion animation."));
EditorGUILayout.Space(6);
EditorGUILayout.LabelField("Prefabs", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(so.FindProperty("drawingPrefab"), new GUIContent("Drawing Prefab (SlotMarkers)"));
@@ -241,7 +246,7 @@ namespace Darkmatter.Features.DrawingTemplates.Editor
Undo.RecordObject(t, "Clear Pieces");
var emptyPieces = new List<ShapeSO>();
t.EditorSet(t.Id, t.DisplayName, t.DefaultThumbnail, t.DrawingPrefab, t.ColoringPrefab,
t.CompletionAnimationPrefab, emptyPieces, t.AuthoredRegions.ToList(), t.ColorPaletteId);
t.CompletionAnimationPrefab, t.CompletionSound, emptyPieces, t.AuthoredRegions.ToList(), t.ColorPaletteId);
EditorUtility.SetDirty(t);
so.Update();
}
@@ -273,7 +278,7 @@ namespace Darkmatter.Features.DrawingTemplates.Editor
{
Undo.RecordObject(t, "Clear Regions");
t.EditorSet(t.Id, t.DisplayName, t.DefaultThumbnail, t.DrawingPrefab, t.ColoringPrefab,
t.CompletionAnimationPrefab, t.Pieces.ToList(), new List<RegionAuthoring>(), t.ColorPaletteId);
t.CompletionAnimationPrefab, t.CompletionSound, t.Pieces.ToList(), new List<RegionAuthoring>(), t.ColorPaletteId);
EditorUtility.SetDirty(t);
so.Update();
}
@@ -341,7 +346,7 @@ namespace Darkmatter.Features.DrawingTemplates.Editor
}
Undo.RecordObject(t, "Scan Drawing Prefab");
t.EditorSet(t.Id, t.DisplayName, t.DefaultThumbnail, t.DrawingPrefab, t.ColoringPrefab,
t.CompletionAnimationPrefab, pieces, t.AuthoredRegions.ToList(), t.ColorPaletteId);
t.CompletionAnimationPrefab, t.CompletionSound, pieces, t.AuthoredRegions.ToList(), t.ColorPaletteId);
EditorUtility.SetDirty(t);
_lastScanReport = $"Found {markers.Length} SlotMarker(s), {pieces.Count} unique ShapeSO. {missing} marker(s) had no ShapeSO assigned.";
Validate();
@@ -421,7 +426,7 @@ namespace Darkmatter.Features.DrawingTemplates.Editor
Undo.RecordObject(t, "Scan Coloring Prefab");
t.EditorSet(t.Id, t.DisplayName, t.DefaultThumbnail, t.DrawingPrefab, t.ColoringPrefab,
t.CompletionAnimationPrefab, t.Pieces.ToList(), regions, t.ColorPaletteId);
t.CompletionAnimationPrefab, t.CompletionSound, t.Pieces.ToList(), regions, t.ColorPaletteId);
EditorUtility.SetDirty(t);
var report = new System.Text.StringBuilder();
@@ -621,7 +626,7 @@ namespace Darkmatter.Features.DrawingTemplates.Editor
if (string.IsNullOrEmpty(path)) return;
var t = CreateInstance<DrawingTemplateSO>();
var name = Path.GetFileNameWithoutExtension(path);
t.EditorSet(name, name, null, null, null, null, new List<ShapeSO>(), new List<RegionAuthoring>(), "defaultPalette");
t.EditorSet(name, name, null, null, null, null, null, new List<ShapeSO>(), new List<RegionAuthoring>(), "defaultPalette");
AssetDatabase.CreateAsset(t, path);
AssetDatabase.SaveAssets();
Refresh();