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

@@ -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);
}
}
}