Implemented Drawing and coloring DTOs and capture system

This commit is contained in:
Savya Bikram Shah
2026-05-27 16:01:45 +05:45
parent aac0dc1513
commit df861765c2
33 changed files with 518 additions and 67 deletions

View File

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

View File

@@ -0,0 +1,11 @@
using System.Collections.Generic;
using UnityEngine;
namespace Darkmatter.Core.Contracts.Features.Coloring
{
public interface IColorPalette
{
string Id { get; }
IReadOnlyList<Color> Colors { get; }
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9727b71700be94dd5996eae7a4643d45

View File

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

View File

@@ -0,0 +1,16 @@
using System.Collections.Generic;
using Darkmatter.Core.Data.Dynamic.Features.Coloring;
using UnityEngine;
namespace Darkmatter.Core.Contracts.Features.Drawing
{
public interface IDrawingTemplate
{
string Id { get; }
string DisplayName { get; }
Sprite DefaultThumbnail { get; }
Sprite PaperBackground { get; }
IReadOnlyList<ShapeSO> Pieces { get; }
IReadOnlyList<ColorRegionDTO> Regions { get; }
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 34c3363cf5c2645bf89a6716881d637d

View File

@@ -0,0 +1,16 @@
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace Darkmatter.Core.Contracts.Features.Drawing
{
public interface IDrawingTemplateCatalog
{
UniTask InitializeAsync();
IReadOnlyList<string> AllTemplateIds { get; }
UniTask<Sprite> GetThumbnailAsync(string id);
UniTask<IDrawingTemplate> LoadAsync(string id);
void Release(string id);
string NextUnseen(string currentId);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7932dbf9ea8724ec0962fb38ce70c69a

View File

@@ -1,12 +1,12 @@
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace Darkmatter.Core.Contracts.Services.Capture
{
public interface ICaptureService
{
UniTask<byte[]> CapturePngAsync(CancellationToken cancellationToken = default);
UniTask<byte[]> CaptureThumbnailPngAsync(int size, CancellationToken cancellationToken = default);
UniTask<Sprite> CapturePngAsync(GameObject captureObject, float captureSize,
CancellationToken cancellationToken = default);
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,20 @@
using UnityEngine;
namespace Darkmatter.Core.Data.Dynamic.Features.Coloring
{
public readonly struct ColorRegionDTO
{
public string RegionId { get; }
public Sprite Sprite { get; }
public Vector2 AnchoredPosition { get; }
public Color InitialColor { get; }
public ColorRegionDTO(string regionId, Sprite sprite, Vector2 anchoredPosition, Color initialColor)
{
RegionId = regionId;
Sprite = sprite;
AnchoredPosition = anchoredPosition;
InitialColor = initialColor;
}
}
}

View File

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

View File

@@ -0,0 +1,18 @@
using UnityEngine;
namespace Darkmatter.Core.Data.Dynamic.Features.Coloring
{
public readonly struct PaintCommandDTO
{
public string RegionId { get; }
public Color FromColor { get; }
public Color ToColor { get; }
public PaintCommandDTO(string regionId, Color fromColor, Color toColor)
{
RegionId = regionId;
FromColor = fromColor;
ToColor = toColor;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1705bbb970da44af7b0cdf6c2fe90cfb

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace Darkmatter.Core
{
[CreateAssetMenu(fileName = "ShapeSO", menuName = "Darkmatter/Drawing/New Shape")]
public class ShapeSO : ScriptableObject
{
[field: SerializeField] public string Id { get; private set; }
[field: SerializeField] public Sprite Sprite { get; private set; }
}
}

View File

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

View File

@@ -3,6 +3,7 @@ namespace Darkmatter.Core.Enums.Services.Camera
public enum CameraType
{
MainCamera,
UICamera
UICamera,
CaptureCamera
}
}

View File

@@ -11,13 +11,15 @@ namespace Darkmatter.Services.Camera.Installers
{
[SerializeField] private UnityEngine.Camera mainCamera;
[SerializeField] private UnityEngine.Camera uiCamera;
[SerializeField] private UnityEngine.Camera captureCamera;
public void Register(IContainerBuilder builder)
{
var cameras = new Dictionary<CameraType, UnityEngine.Camera>
{
{ CameraType.MainCamera, mainCamera },
{ CameraType.UICamera, uiCamera }
{ CameraType.UICamera, uiCamera },
{ CameraType.CaptureCamera, captureCamera }
};
builder.Register<ICameraService, CameraService>(Lifetime.Singleton).WithParameter(cameras);
}

View File

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

View File

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

View File

@@ -0,0 +1,15 @@
using Darkmatter.Core.Contracts.Services.Capture;
using Darkmatter.Libs.Installers;
using UnityEngine;
using VContainer;
namespace Darkmatter.Services.Capture.Installers
{
public class CaptureServiceModule : MonoBehaviour, IServiceModule
{
public void Register(IContainerBuilder builder)
{
builder.Register<ICaptureService, CaptureService>(Lifetime.Singleton);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e14e6746c7bb4b57808b4d3020dc7bbb
timeCreated: 1779876898

View File

@@ -0,0 +1,19 @@
{
"name": "Services.Capture",
"rootNamespace": "Darkmatter.Services.Capture",
"references": [
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 84edfab748bc54037bf370551f172e4f
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@@ -0,0 +1,53 @@
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<Sprite> CapturePngAsync(GameObject captureObject, float captureSize,
CancellationToken cancellationToken = default)
{
var captureCamera = _cameraService.GetCamera(CameraType.CaptureCamera);
await UniTask.Yield(PlayerLoopTiming.Update, cancellationToken);
int size = Mathf.RoundToInt(captureSize);
var renderTexture = RenderTexture.GetTemporary(size, size, 24);
var previousTarget = captureCamera.targetTexture;
var previousActive = RenderTexture.active;
try
{
captureCamera.targetTexture = renderTexture;
captureCamera.Render();
RenderTexture.active = renderTexture;
var texture = new Texture2D(size, size, TextureFormat.RGBA32, false);
texture.ReadPixels(new Rect(0, 0, size, size), 0, 0);
texture.Apply();
return Sprite.Create(texture, new Rect(0, 0, size, size), new Vector2(0.5f, 0.5f));
}
finally
{
captureCamera.targetTexture = previousTarget;
RenderTexture.active = previousActive;
RenderTexture.ReleaseTemporary(renderTexture);
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6f5c8d288050e471d9d3d0ffc5e14799

View File

@@ -1,19 +1,15 @@
using Darkmatter.Core.Contracts.Services.Gallery;
using Darkmatter.Libs.Installers;
using UnityEngine;
using VContainer;
namespace Darkmatter.Services.Gallery
{
public class GalleryServiceModule : MonoBehaviour
public class GalleryServiceModule : MonoBehaviour,IServiceModule
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
public void Register(IContainerBuilder builder)
{
}
// Update is called once per frame
void Update()
{
builder.Register<IGalleryService,GalleryService>(Lifetime.Singleton);
}
}
}