Compare commits

...

3 Commits

Author SHA1 Message Date
Savya Bikram Shah
0b22ed6d09 Music and transparent fixes 2026-05-29 18:42:12 +05:45
Savya Bikram Shah
47fb204446 artbook added to drawing 2026-05-29 18:28:06 +05:45
Savya Bikram Shah
676b389244 Artt book tweaks 2026-05-29 18:20:25 +05:45
46 changed files with 4270 additions and 3217 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3d69da96f4ccb4de5910011cfc1e07a1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace Darkmatter.Core.Contracts.Services.Music
{
public interface IMusicService
{
void Play(AudioClip clip, float volume01 = 1f, bool loop = true);
void Stop(float fadeOutSeconds = 0f);
void SetVolume(float volume01);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f851c65abe6f240a894610f67360fe58

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f69d14fcc0bdd4b93aeb1717d030a9ca
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
namespace Darkmatter.Core.Data.Signals.Features.Capture
{
public record struct GallerySaveCompletedSignal(bool Success);
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 04fbdae933fab4011879c232a1041042

View File

@@ -0,0 +1,4 @@
namespace Darkmatter.Core.Data.Signals.Features.Capture
{
public record struct GallerySaveStartedSignal;
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: cff479845a55e4dd0a6d66043c91f661

View File

@@ -1,6 +1,7 @@
using System;
using UnityEngine;
namespace Darkmatter.Core
{
public record struct OpenArtBookSignal;
}
public record struct OpenArtBookSignal(Action OnClose);
}

View File

@@ -26,7 +26,7 @@ namespace Darkmatter.Features.Artbook
private readonly List<ArtbookEntry> _entries = new();
private readonly List<Sprite> _ownedSprites = new();
private readonly List<Texture2D> _ownedTextures = new();
private Action _onClose;
private CancellationTokenSource _cts;
private IDisposable _openSubscription;
private int _currentSpread;
@@ -60,10 +60,12 @@ namespace Darkmatter.Features.Artbook
private void HandleOpenArtbookEvent(OpenArtBookSignal signal)
{
_onClose = null;
_view.Show();
_cts?.Cancel();
_cts?.Dispose();
_cts = new CancellationTokenSource();
_onClose = signal.OnClose;
LoadAndShowAsync(_cts.Token).Forget();
}
@@ -164,7 +166,7 @@ namespace Darkmatter.Features.Artbook
private void HandleBackButtonClicked()
{
_eventBus.Publish(new OpenColorBookSignal());
_onClose?.Invoke();
_view.Hide();
}
@@ -198,4 +200,4 @@ namespace Darkmatter.Features.Artbook
ClearOwnedAssets();
}
}
}
}

View File

@@ -4,6 +4,7 @@
"references": [
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
"GUID:b4c9f7fbf1e144933a1797dc208ece5f",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],

View File

@@ -11,6 +11,7 @@ namespace Darkmatter.Features.Capture
{
[SerializeField, Range(0.1f, 2f)] private float captureScale = 1f;
[SerializeField] private CaptureButtonView captureButtonView;
[SerializeField] private GallerySaveView gallerySaveView;
public void Register(IContainerBuilder builder)
{
@@ -19,6 +20,9 @@ namespace Darkmatter.Features.Capture
if (captureButtonView != null)
builder.RegisterEntryPoint<CaptureButtonPresenter>().WithParameter(captureButtonView);
if (gallerySaveView != null)
builder.RegisterEntryPoint<GallerySavePresenter>().WithParameter(gallerySaveView);
}
}
}

View File

@@ -5,6 +5,8 @@ using Darkmatter.Core.Contracts.Features.Capture;
using Darkmatter.Core.Contracts.Features.GameplayFlow;
using Darkmatter.Core.Contracts.Services.Capture;
using Darkmatter.Core.Contracts.Services.Gallery;
using Darkmatter.Core.Data.Signals.Features.Capture;
using Darkmatter.Libs.Observer;
using UnityEngine;
namespace Darkmatter.Features.Capture
@@ -14,17 +16,20 @@ namespace Darkmatter.Features.Capture
private readonly ICaptureService _captureService;
private readonly IGalleryService _galleryService;
private readonly IGameplaySceneRefs _refs;
private readonly IEventBus _bus;
private readonly CaptureConfig _config;
public CaptureSystem(
ICaptureService captureService,
IGalleryService galleryService,
IGameplaySceneRefs refs,
IEventBus bus,
CaptureConfig config)
{
_captureService = captureService;
_galleryService = galleryService;
_refs = refs;
_bus = bus;
_config = config;
}
@@ -34,15 +39,21 @@ namespace Darkmatter.Features.Capture
if (!saveToGallery || png == null || png.Length == 0) return png;
var tex = new Texture2D(2, 2, TextureFormat.RGBA32, mipChain: false);
var success = false;
try
{
if (tex.LoadImage(png))
{
_bus.Publish(new GallerySaveStartedSignal());
await _galleryService.SaveImageAsync(tex,
$"colorbook_{DateTime.UtcNow:yyyyMMdd_HHmmss}.png", ct);
success = true;
}
}
finally
{
UnityEngine.Object.Destroy(tex);
_bus.Publish(new GallerySaveCompletedSignal(success));
}
return png;
}

View File

@@ -0,0 +1,71 @@
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Data.Signals.Features.Capture;
using Darkmatter.Libs.Observer;
using VContainer.Unity;
namespace Darkmatter.Features.Capture.UI
{
public class GallerySavePresenter : IStartable, IDisposable
{
private readonly GallerySaveView _view;
private readonly IEventBus _bus;
private IDisposable _startedSub;
private IDisposable _completedSub;
private CancellationTokenSource _popupCts;
public GallerySavePresenter(GallerySaveView view, IEventBus bus)
{
_view = view;
_bus = bus;
}
public void Start()
{
_startedSub = _bus.Subscribe<GallerySaveStartedSignal>(OnStarted);
_completedSub = _bus.Subscribe<GallerySaveCompletedSignal>(OnCompleted);
}
private void OnStarted(GallerySaveStartedSignal _)
{
CancelPopup();
_view.ShowSaving();
}
private void OnCompleted(GallerySaveCompletedSignal signal)
{
_view.HideSaving();
if (!signal.Success) return;
CancelPopup();
_popupCts = new CancellationTokenSource();
ShowPopupAsync(_popupCts.Token).Forget();
}
private async UniTaskVoid ShowPopupAsync(CancellationToken ct)
{
_view.ShowSuccess();
try
{
await UniTask.Delay(TimeSpan.FromSeconds(_view.PopupAutoHideSeconds), cancellationToken: ct);
}
catch (OperationCanceledException) { return; }
_view.HideSuccess();
}
private void CancelPopup()
{
_popupCts?.Cancel();
_popupCts?.Dispose();
_popupCts = null;
}
public void Dispose()
{
_startedSub?.Dispose();
_completedSub?.Dispose();
CancelPopup();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 71d8cccc7b3a3436ba83ca3683fbea9f

View File

@@ -0,0 +1,40 @@
using UnityEngine;
namespace Darkmatter.Features.Capture.UI
{
public class GallerySaveView : MonoBehaviour
{
[SerializeField] private GameObject savingIndicator;
[SerializeField] private GameObject successPopup;
[SerializeField, Min(0f)] private float popupAutoHideSeconds = 1.5f;
public float PopupAutoHideSeconds => popupAutoHideSeconds;
private void Awake()
{
if (savingIndicator != null) savingIndicator.SetActive(false);
if (successPopup != null) successPopup.SetActive(false);
}
public void ShowSaving()
{
if (savingIndicator != null) savingIndicator.SetActive(true);
if (successPopup != null) successPopup.SetActive(false);
}
public void HideSaving()
{
if (savingIndicator != null) savingIndicator.SetActive(false);
}
public void ShowSuccess()
{
if (successPopup != null) successPopup.SetActive(true);
}
public void HideSuccess()
{
if (successPopup != null) successPopup.SetActive(false);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bbcc5a579d90f4763a781379f5213d6e

View File

@@ -1,4 +1,5 @@
using System;
using Darkmatter.Core;
using Darkmatter.Core.Data.Signals.Features.ShapeBuilder;
using Darkmatter.Libs.Observer;
using VContainer.Unity;
@@ -22,11 +23,18 @@ namespace Darkmatter.Features.Coloring.UI
{
_view.HideInstant();
_assembledSub = _bus.Subscribe<ShapeAssembledSignal>(_ => _view.Show());
_view.OnArtbookClicked += HandleArtbookClicked;
}
private void HandleArtbookClicked()
{
_bus.Publish(new OpenArtBookSignal());
}
public void Dispose()
{
_assembledSub?.Dispose();
_view.OnArtbookClicked -= HandleArtbookClicked;
}
}
}

View File

@@ -1,5 +1,7 @@
using System;
using PrimeTween;
using UnityEngine;
using UnityEngine.UI;
namespace Darkmatter.Features.Coloring.UI
{
@@ -8,6 +10,7 @@ namespace Darkmatter.Features.Coloring.UI
{
[SerializeField] private RectTransform spawnRoot;
[SerializeField] private RectTransform animatedRoot;
[SerializeField] private Button artbookButton;
[SerializeField] private float showDuration = 0.35f;
[SerializeField] private float hideDuration = 0.25f;
[SerializeField] private Vector2 hiddenOffset = new(1500f, 0f);
@@ -17,9 +20,16 @@ namespace Darkmatter.Features.Coloring.UI
private Sequence _activeSequence;
private bool _refsReady;
public event Action OnArtbookClicked;
public RectTransform SpawnRoot => spawnRoot;
private void Awake() => EnsureRefs();
private void Awake()
{
EnsureRefs();
if (artbookButton != null) artbookButton.onClick.AddListener(HandleArtbookClicked);
}
private void HandleArtbookClicked() => OnArtbookClicked?.Invoke();
private void EnsureRefs()
{
@@ -80,5 +90,10 @@ namespace Darkmatter.Features.Coloring.UI
{
KillActive();
}
private void OnDestroy()
{
if (artbookButton != null) artbookButton.onClick.RemoveListener(HandleArtbookClicked);
}
}
}

View File

@@ -70,7 +70,7 @@ namespace Darkmatter.Features.DrawingCatalog
private void OnArtBookBtnClicked()
{
_eventBus.Publish(new OpenArtBookSignal());
_eventBus.Publish(new OpenArtBookSignal(()=> _view.Show()));
_view.Hide();
}

View File

@@ -43,6 +43,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
private IDisposable _assembledSub;
private IDisposable _colorAppliedSub;
private IDisposable _drawingSelectedSub;
private CancellationTokenSource _autosaveCts;
private CancellationTokenSource _scopeCts;
@@ -89,6 +90,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
_assembledSub = _bus.Subscribe<ShapeAssembledSignal>(OnShapeAssembled);
_colorAppliedSub = _bus.Subscribe<ColorAppliedSignal>(OnColorApplied);
_drawingSelectedSub = _bus.Subscribe<DrawingSelectedSignal>(OnDrawingSelected);
Application.quitting += OnAppQuitting;
Application.focusChanged += OnAppFocusChanged;
@@ -188,6 +190,24 @@ namespace Darkmatter.Features.GameplayFlow.Systems
DebouncedAutosaveAsync(_autosaveCts.Token).Forget();
}
private void OnDrawingSelected(DrawingSelectedSignal signal)
{
if (string.IsNullOrEmpty(signal.TemplateId)) return;
if (signal.TemplateId == _templateId) return;
EditAsync(signal.TemplateId).Forget();
}
private async UniTaskVoid EditAsync(string newTemplateId)
{
await SaveCurrentAsync(CancellationToken.None);
_loadingScreen.Show();
_shapeBuilder.Clear();
_coloring.Clear();
await _scenes.LoadSceneAsync(nameof(GameScene.Colorbook), progress: null, cancellationToken: default);
await _scenes.UnloadSceneAsync(nameof(GameScene.Gameplay), progress: null, cancellationToken: default);
_bus.Publish(new DrawingSelectedSignal(newTemplateId));
}
private async UniTaskVoid DebouncedAutosaveAsync(CancellationToken ct)
{
try
@@ -246,6 +266,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
_assembledSub?.Dispose();
_colorAppliedSub?.Dispose();
_drawingSelectedSub?.Dispose();
_autosaveCts?.Cancel();
_autosaveCts?.Dispose();
_scopeCts?.Cancel();

View File

@@ -1,4 +1,5 @@
using System;
using Darkmatter.Core;
using Darkmatter.Core.Data.Signals.Features.ShapeBuilder;
using Darkmatter.Libs.Observer;
using VContainer.Unity;
@@ -24,12 +25,19 @@ namespace Darkmatter.Features.ShapeBuilder.UI
_view.HideInstant();
_startedSub = _bus.Subscribe<ShapeBuilderStartedSignal>(_ => _view.Show());
_assembledSub = _bus.Subscribe<ShapeAssembledSignal>(_ => _view.Hide());
_view.OnArtbookClicked += HandleArtbookClicked;
}
private void HandleArtbookClicked()
{
_bus.Publish(new OpenArtBookSignal());
}
public void Dispose()
{
_startedSub?.Dispose();
_assembledSub?.Dispose();
_view.OnArtbookClicked -= HandleArtbookClicked;
}
}
}
}

View File

@@ -1,5 +1,8 @@
using System;
using Darkmatter.Features.ShapeBuilder.Systems;
using PrimeTween;
using UnityEngine;
using UnityEngine.UI;
namespace Darkmatter.Features.ShapeBuilder.UI
{
@@ -8,6 +11,7 @@ namespace Darkmatter.Features.ShapeBuilder.UI
{
[SerializeField] private RectTransform spawnRoot;
[SerializeField] private RectTransform animatedRoot;
[SerializeField] private Button artbookButton;
[SerializeField] private float showDuration = 0.35f;
[SerializeField] private float hideDuration = 0.25f;
[SerializeField] private Vector2 hiddenOffset = new(1500f, 0f);
@@ -15,6 +19,7 @@ namespace Darkmatter.Features.ShapeBuilder.UI
private CanvasGroup _canvasGroup;
private Vector2 _shownAnchoredPos;
private Sequence _activeSequence;
public event Action OnArtbookClicked;
public RectTransform SpawnRoot => spawnRoot;
public float SpawnWidth => spawnRoot.rect.width;
@@ -24,6 +29,12 @@ namespace Darkmatter.Features.ShapeBuilder.UI
_canvasGroup = GetComponent<CanvasGroup>();
if (animatedRoot == null) animatedRoot = (RectTransform)transform;
_shownAnchoredPos = animatedRoot.anchoredPosition;
artbookButton.onClick.AddListener(HandleArtbookClicked);
}
private void HandleArtbookClicked()
{
OnArtbookClicked?.Invoke();
}
public Sequence Show()
@@ -73,5 +84,10 @@ namespace Darkmatter.Features.ShapeBuilder.UI
{
KillActive();
}
private void OnDestroy()
{
artbookButton.onClick.RemoveListener(HandleArtbookClicked);
}
}
}
}

View File

@@ -1,73 +1,115 @@
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Contracts.Services.Camera;
using Darkmatter.Core.Contracts.Services.Capture;
using UnityEngine;
using CameraType = Darkmatter.Core.Enums.Services.Camera.CameraType;
namespace Darkmatter.Services.Capture
{
public class CaptureService : ICaptureService
{
private readonly ICameraService _cameraService;
public CaptureService(ICameraService cameraService) => _cameraService = cameraService;
public async UniTask<byte[]> CapturePngAsync(GameObject captureObject, float scale,
CancellationToken cancellationToken = default)
{
if (captureObject == null) return null;
var paperRT = captureObject.transform as RectTransform;
var paperCanvas = GetRootCanvas(captureObject);
var cam = _cameraService.GetCamera(CameraType.CaptureCamera);
if (paperCanvas == null || paperRT == null || cam == null) return null;
int sw = Screen.width;
int sh = Screen.height;
var disabledCanvases = DisableOtherRootCanvases(paperCanvas);
var cam = Camera.main;
CameraClearFlags prevFlags = default;
Color prevBg = default;
if (cam != null)
{
prevFlags = cam.clearFlags;
prevBg = cam.backgroundColor;
cam.clearFlags = CameraClearFlags.SolidColor;
cam.backgroundColor = new Color(0f, 0f, 0f, 0f);
}
var disabledGraphics = HideNonPaperGraphics(paperRT);
await UniTask.WaitForEndOfFrame(cancellationToken);
Rect crop = ComputeCropRect(captureObject, sw, sh);
int cropW = Mathf.Max(1, (int)crop.width);
int cropH = Mathf.Max(1, (int)crop.height);
var prevFlags = cam.clearFlags;
var prevBg = cam.backgroundColor;
var prevTarget = cam.targetTexture;
cam.clearFlags = CameraClearFlags.SolidColor;
cam.backgroundColor = new Color(0f, 0f, 0f, 0f);
var rt = RenderTexture.GetTemporary(sw, sh, 24, RenderTextureFormat.ARGB32);
cam.targetTexture = rt;
var prevMode = paperCanvas.renderMode;
var prevWorldCam = paperCanvas.worldCamera;
var prevPlaneDist = paperCanvas.planeDistance;
paperCanvas.renderMode = RenderMode.ScreenSpaceCamera;
paperCanvas.worldCamera = cam;
paperCanvas.planeDistance = Mathf.Max(0.5f, (cam.nearClipPlane + cam.farClipPlane) * 0.5f);
var fullScreen = ScreenCapture.CaptureScreenshotAsTexture();
try
{
Rect crop = ComputeCropRect(captureObject, fullScreen.width, fullScreen.height);
int cropW = Mathf.Max(1, (int)crop.width);
int cropH = Mathf.Max(1, (int)crop.height);
await UniTask.WaitForEndOfFrame(cancellationToken);
Canvas.ForceUpdateCanvases();
cam.Render();
var prevActive = RenderTexture.active;
RenderTexture.active = rt;
var fullScreen = new Texture2D(sw, sh, TextureFormat.RGBA32, mipChain: false);
fullScreen.ReadPixels(new Rect(0, 0, sw, sh), 0, 0);
fullScreen.Apply();
RenderTexture.active = prevActive;
var cropped = new Texture2D(cropW, cropH, TextureFormat.RGBA32, mipChain: false);
try
{
cropped.SetPixels(fullScreen.GetPixels((int)crop.x, (int)crop.y, cropW, cropH));
cropped.Apply();
int targetW = Mathf.Max(1, Mathf.RoundToInt(cropW * scale));
int targetH = Mathf.Max(1, Mathf.RoundToInt(cropH * scale));
Texture2D output = cropped;
if (output.width != targetW || output.height != targetH)
output = Resize(cropped, targetW, targetH);
var cropped = new Texture2D(cropW, cropH, TextureFormat.RGBA32, mipChain: false);
try
{
return output.EncodeToPNG();
cropped.SetPixels(fullScreen.GetPixels((int)crop.x, (int)crop.y, cropW, cropH));
cropped.Apply();
int targetW = Mathf.Max(1, Mathf.RoundToInt(cropW * scale));
int targetH = Mathf.Max(1, Mathf.RoundToInt(cropH * scale));
Texture2D output = cropped;
if (output.width != targetW || output.height != targetH)
output = Resize(cropped, targetW, targetH);
try
{
return output.EncodeToPNG();
}
finally
{
if (output != cropped) Object.Destroy(output);
}
}
finally
{
if (output != cropped) Object.Destroy(output);
Object.Destroy(cropped);
}
}
finally
{
Object.Destroy(cropped);
Object.Destroy(fullScreen);
}
}
finally
{
Object.Destroy(fullScreen);
foreach (var c in disabledCanvases) if (c != null) c.enabled = true;
if (cam != null)
{
cam.clearFlags = prevFlags;
cam.backgroundColor = prevBg;
}
paperCanvas.renderMode = prevMode;
paperCanvas.worldCamera = prevWorldCam;
paperCanvas.planeDistance = prevPlaneDist;
cam.targetTexture = prevTarget;
cam.clearFlags = prevFlags;
cam.backgroundColor = prevBg;
RenderTexture.ReleaseTemporary(rt);
foreach (var g in disabledGraphics)
if (g != null)
g.enabled = true;
foreach (var c in disabledCanvases)
if (c != null)
c.enabled = true;
}
}
@@ -88,6 +130,23 @@ namespace Darkmatter.Services.Capture
c.enabled = false;
disabled.Add(c);
}
return disabled;
}
private static List<UnityEngine.UI.Graphic> HideNonPaperGraphics(Transform paper)
{
var disabled = new List<UnityEngine.UI.Graphic>();
if (paper == null) return disabled;
var all = Object.FindObjectsByType<UnityEngine.UI.Graphic>(FindObjectsSortMode.None);
foreach (var g in all)
{
if (g == null || !g.enabled) continue;
if (g.transform.IsChildOf(paper)) continue;
g.enabled = false;
disabled.Add(g);
}
return disabled;
}
@@ -98,7 +157,6 @@ namespace Darkmatter.Services.Capture
var corners = new Vector3[4];
rt.GetWorldCorners(corners);
// ScreenSpaceOverlay canvas: world corners are already in screen pixels.
float minX = Mathf.Clamp(corners[0].x, 0, screenW);
float minY = Mathf.Clamp(corners[0].y, 0, screenH);
float maxX = Mathf.Clamp(corners[2].x, 0, screenW);
@@ -126,4 +184,4 @@ namespace Darkmatter.Services.Capture
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 27c2e817c276c40b19f6284b7c87860c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e1d52cf6530064afd982535de65293bb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using Darkmatter.Core.Contracts.Services.Music;
using Darkmatter.Libs.Installers;
using Darkmatter.Services.Music.Systems;
using UnityEngine;
using VContainer;
using VContainer.Unity;
namespace Darkmatter.Services.Music.Installers
{
public class MusicServiceModule : MonoBehaviour, IModule
{
[SerializeField] private AudioClip defaultTrack;
[SerializeField, Range(0f, 1f)] private float defaultVolume = 0.7f;
[SerializeField, Min(0f)] private float crossFadeSeconds = 0.4f;
public void Register(IContainerBuilder builder)
{
builder.RegisterInstance(new MusicConfig(defaultTrack, defaultVolume, crossFadeSeconds));
builder.RegisterEntryPoint<MusicService>(Lifetime.Singleton).As<IMusicService>();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 47cce31d8e31341a0ae46684e87cbd95

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bec4745668fea4987809c8370d372048
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using System;
using UnityEngine;
namespace Darkmatter.Services.Music.Systems
{
[Serializable]
public readonly struct MusicConfig
{
public AudioClip DefaultTrack { get; }
public float DefaultVolume { get; }
public float CrossFadeSeconds { get; }
public MusicConfig(AudioClip defaultTrack, float defaultVolume, float crossFadeSeconds)
{
DefaultTrack = defaultTrack;
DefaultVolume = defaultVolume;
CrossFadeSeconds = crossFadeSeconds;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4c15bf1ed26cf4c8f8339b22cb57efc6

View File

@@ -0,0 +1,70 @@
using System;
using Darkmatter.Core.Contracts.Services.Audio;
using Darkmatter.Core.Contracts.Services.Music;
using Darkmatter.Core.Data.Dynamic.Services.Audio;
using Darkmatter.Core.Data.Signals.Features.AppBoot;
using Darkmatter.Core.Enums.Services.Audio;
using Darkmatter.Libs.Observer;
using UnityEngine;
using VContainer.Unity;
namespace Darkmatter.Services.Music.Systems
{
public class MusicService : IMusicService, IStartable, IDisposable
{
private readonly IAudioService _audio;
private readonly IEventBus _bus;
private readonly MusicConfig _config;
private AudioHandle _current;
private IDisposable _introSub;
public MusicService(IAudioService audio, IEventBus bus, MusicConfig config)
{
_audio = audio;
_bus = bus;
_config = config;
}
public void Start()
{
_introSub = _bus.Subscribe<IntroCompletedSignal>(OnIntroCompleted);
}
private void OnIntroCompleted(IntroCompletedSignal _)
{
if (_config.DefaultTrack != null && !_current.IsValid)
Play(_config.DefaultTrack, _config.DefaultVolume, loop: true);
}
public void Play(AudioClip clip, float volume01 = 1f, bool loop = true)
{
if (clip == null) return;
if (_current.IsValid) _audio.Stop(_current, _config.CrossFadeSeconds);
var req = new AudioRequest(
clip: clip,
channel: AudioChannel.Music,
mode: loop ? AudioPlayMode.Loop : AudioPlayMode.OneShot,
stopChannelBeforePlay: true,
volume01: Mathf.Clamp01(volume01));
_current = _audio.Play(req);
}
public void Stop(float fadeOutSeconds = 0f)
{
if (_current.IsValid) _audio.Stop(_current, fadeOutSeconds);
_current = AudioHandle.Invalid;
}
public void SetVolume(float volume01)
{
if (_current.IsValid) _audio.SetVolume(_current, Mathf.Clamp01(volume01));
}
public void Dispose()
{
_introSub?.Dispose();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8b4c07c26f9a44409bd43d2777b9951d

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 854202d005e754405862e01141384a81
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: d2ea12320736942649eb53c30ab7e4bb
AudioImporter:
externalObjects: {}
serializedVersion: 8
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4dd2a1cb2754a410f9f807f563a55e7c
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@@ -0,0 +1,182 @@
fileFormatVersion: 2
guid: 642217a8618e94c7ba1322adee7fbe28
TextureImporter:
internalIDToNameTable:
- first:
213: -7832214784768987486
second: apple_0
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: iOS
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites:
- serializedVersion: 2
name: apple_0
rect:
serializedVersion: 2
x: 301
y: 56
width: 473
height: 497
alignment: 0
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
customData:
outline: []
physicsShape: []
tessellationDetail: -1
bones: []
spriteID: 2ae284d66226e4390800000000000000
internalID: -7832214784768987486
vertices: []
indices:
edges: []
weights: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable:
apple_0: -7832214784768987486
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@@ -948,6 +948,53 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 355949970}
m_CullTransparentMesh: 1
--- !u!1 &361052050
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 361052051}
- component: {fileID: 361052052}
m_Layer: 0
m_Name: MusicServiceModule
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &361052051
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 361052050}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1050564725}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &361052052
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 361052050}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 47cce31d8e31341a0ae46684e87cbd95, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Darkmatter.Services.Music.Installers.MusicServiceModule
defaultTrack: {fileID: 8300000, guid: d2ea12320736942649eb53c30ab7e4bb, type: 3}
defaultVolume: 0.7
crossFadeSeconds: 0.4
--- !u!1 &445008005
GameObject:
m_ObjectHideFlags: 0
@@ -1446,6 +1493,7 @@ Transform:
- {fileID: 1776076871}
- {fileID: 97140292}
- {fileID: 978572232}
- {fileID: 361052051}
m_Father: {fileID: 1798580248}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1239449674
@@ -1930,6 +1978,7 @@ MonoBehaviour:
- {fileID: 97140291}
- {fileID: 789049883}
- {fileID: 978572233}
- {fileID: 361052052}
--- !u!1 &1890425864
GameObject:
m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

View File

@@ -165,6 +165,7 @@ MonoBehaviour:
m_EditorClassIdentifier: Features.Capture::Darkmatter.Features.Capture.CaptureFeatureModule
captureScale: 1
captureButtonView: {fileID: 376589371}
gallerySaveView: {fileID: 0}
--- !u!1 &64614225
GameObject:
m_ObjectHideFlags: 0
@@ -657,6 +658,51 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier: Features.GameplayFlow::Darkmatter.Features.GameplayFlow.UI.NextButtonView
nextButton: {fileID: 259035379}
--- !u!1 &339691221
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 339691222}
- component: {fileID: 339691223}
m_Layer: 0
m_Name: ArtbookFeatureServiceModule
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &339691222
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 339691221}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -40.146973, y: -385.9893, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1965442263}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &339691223
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 339691221}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e42bea53c6fa23c45a7c85e9b025bed7, type: 3}
m_Name:
m_EditorClassIdentifier: Features.Artbook::Darkmatter.Features.Artbook.ArtBookFeatureModule
artbookView: {fileID: 2022514149}
--- !u!1 &357588033
GameObject:
m_ObjectHideFlags: 0
@@ -2045,6 +2091,7 @@ MonoBehaviour:
- {fileID: 1991184380}
- {fileID: 1867428030}
- {fileID: 26318080}
- {fileID: 339691223}
--- !u!1 &1281354567
GameObject:
m_ObjectHideFlags: 0
@@ -2471,6 +2518,7 @@ MonoBehaviour:
m_EditorClassIdentifier: Features.Coloring::Darkmatter.Features.Coloring.UI.ColorPaletteHolderView
spawnRoot: {fileID: 2046672212}
animatedRoot: {fileID: 1518670451}
artbookButton: {fileID: 206970557}
showDuration: 0.35
hideDuration: 0.25
hiddenOffset: {x: 1500, y: 0}
@@ -2610,6 +2658,7 @@ Transform:
- {fileID: 1991184379}
- {fileID: 1867428029}
- {fileID: 26318079}
- {fileID: 339691222}
m_Father: {fileID: 1224714932}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1982732271
@@ -2825,6 +2874,7 @@ MonoBehaviour:
m_EditorClassIdentifier: Features.ShapeBuilder::Darkmatter.Features.ShapeBuilder.UI.ShapeHolderView
spawnRoot: {fileID: 1155451091}
animatedRoot: {fileID: 1989194441}
artbookButton: {fileID: 2065186227}
showDuration: 0.35
hideDuration: 0.25
hiddenOffset: {x: 1500, y: 0}
@@ -3023,6 +3073,123 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2014087207}
m_CullTransparentMesh: 1
--- !u!1001 &2022514147
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 2069155641}
m_Modifications:
- target: {fileID: 3521470624751981147, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_Name
value: ArtBookView
objectReference: {fileID: 0}
- target: {fileID: 3521470624751981147, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
--- !u!224 &2022514148 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 3765577967584406493, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
m_PrefabInstance: {fileID: 2022514147}
m_PrefabAsset: {fileID: 0}
--- !u!114 &2022514149 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 3299125903084573743, guid: 4dd2a1cb2754a410f9f807f563a55e7c, type: 3}
m_PrefabInstance: {fileID: 2022514147}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d635629f252db53479e66347a37c4f0b, type: 3}
m_Name:
m_EditorClassIdentifier: Features.Artbook::Darkmatter.Features.Artbook.ArtbookView
--- !u!1 &2046672211
GameObject:
m_ObjectHideFlags: 0
@@ -3436,6 +3603,7 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 201822947}
- {fileID: 2022514148}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}