Merge remote-tracking branch 'origin/main' into work_branch
# Conflicts: # Packages/manifest.json
This commit is contained in:
@@ -5,7 +5,7 @@ using VContainer.Unity;
|
||||
|
||||
namespace Darkmatter.Services.Analytics
|
||||
{
|
||||
public class AnalyticsServiceModule : MonoBehaviour, IServiceModule
|
||||
public class AnalyticsModule : MonoBehaviour, IModule
|
||||
{
|
||||
public void Register(IContainerBuilder builder)
|
||||
{
|
||||
@@ -7,17 +7,19 @@ using CameraType = Darkmatter.Core.Enums.Services.Camera.CameraType;
|
||||
|
||||
namespace Darkmatter.Services.Camera.Installers
|
||||
{
|
||||
public class CameraServiceModule : MonoBehaviour, IServiceModule
|
||||
public class CameraModule : MonoBehaviour, IModule
|
||||
{
|
||||
[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);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e8e28c4942b5410d962cbff40ac302f
|
||||
guid: cfe101c06a10441b082df8d013705b5a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 588d1c926497b491c96d2f405876b176
|
||||
guid: 726f6016537e648efbf32dbf5f1aa3f7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -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 CaptureModule : MonoBehaviour, IModule
|
||||
{
|
||||
public void Register(IContainerBuilder builder)
|
||||
{
|
||||
builder.Register<ICaptureService, CaptureService>(Lifetime.Singleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e14e6746c7bb4b57808b4d3020dc7bbb
|
||||
timeCreated: 1779876898
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84edfab748bc54037bf370551f172e4f
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Darkmatter/Code/Services/Capture/Systems.meta
Normal file
8
Assets/Darkmatter/Code/Services/Capture/Systems.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16df33345840c4107a9b86892641ed13
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f5c8d288050e471d9d3d0ffc5e14799
|
||||
@@ -1,3 +1,6 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Darkmatter.Core.Contracts.Services.Gallery;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -5,9 +8,36 @@ namespace Darkmatter.Services.Gallery
|
||||
{
|
||||
public class GalleryService : IGalleryService
|
||||
{
|
||||
public void SaveImageAsync(Texture2D image, string fileName)
|
||||
public async UniTask SaveImageAsync(Texture2D image, string fileName, CancellationToken cancellationToken)
|
||||
{
|
||||
NativeGallery.SaveImageToGallery(image, "ColorBook", fileName);
|
||||
var permission = await NativeGallery.RequestPermissionAsync(NativeGallery.PermissionType.Write,
|
||||
NativeGallery.MediaType.Image);
|
||||
|
||||
if (permission != NativeGallery.Permission.Granted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var tcs = new UniTaskCompletionSource();
|
||||
var registration = cancellationToken.Register(() => tcs.TrySetCanceled(cancellationToken));
|
||||
|
||||
NativeGallery.SaveImageToGallery(image, "Colorbook",
|
||||
filename: $"colorbook_{DateTime.UtcNow:yyyyMMdd_HHmmss}.png", callback: (success, path) =>
|
||||
{
|
||||
registration.Dispose();
|
||||
if (!success)
|
||||
{
|
||||
Debug.LogError("Failed to save image to gallery.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Image saved to gallery at: {path}");
|
||||
}
|
||||
|
||||
tcs.TrySetResult();
|
||||
});
|
||||
|
||||
await tcs.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Darkmatter.Core.Contracts.Services.Gallery;
|
||||
using Darkmatter.Libs.Installers;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Services.Gallery
|
||||
{
|
||||
public class GalleryModule : MonoBehaviour,IModule
|
||||
{
|
||||
public void Register(IContainerBuilder builder)
|
||||
{
|
||||
builder.Register<IGalleryService,GalleryService>(Lifetime.Singleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Services.Gallery
|
||||
{
|
||||
public class GalleryServiceModule : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@
|
||||
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
|
||||
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
|
||||
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
||||
"GUID:6e5063adab271564ba0098a06a8cebda"
|
||||
"GUID:6e5063adab271564ba0098a06a8cebda",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
using Darkmatter.Core.Contracts.Services.Inputs;
|
||||
using Darkmatter.Libs.Installers;
|
||||
using Darkmatter.Services.Inputs.Readers;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
using VContainer.Unity;
|
||||
|
||||
namespace Darkmatter.Services.Inputs
|
||||
{
|
||||
public class InputServiceModule : MonoBehaviour, IServiceModule
|
||||
{
|
||||
[SerializeField] private InputReaderSO inputReaderSO;
|
||||
|
||||
public void Register(IContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterComponent<IInputReader>(inputReaderSO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b23ca8ea5ee647ddba0712811953811
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using Darkmatter.Core.Contracts.Services.Inputs;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Darkmatter.Services.Inputs.Readers
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Darkmatter/Inputs/New Input Reader")]
|
||||
public class InputReaderSO : ScriptableObject, IInputReader, GameInputs.IPlayerActions
|
||||
{
|
||||
public Vector2 TouchPosition { get; private set; }
|
||||
public event Action OnTouchStart;
|
||||
public event Action OnTouchEnd;
|
||||
|
||||
private GameInputs _gameInputActions;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_gameInputActions = new GameInputs();
|
||||
_gameInputActions.Player.SetCallbacks(this);
|
||||
_gameInputActions.Enable();
|
||||
}
|
||||
|
||||
public void OnTouchPosition(InputAction.CallbackContext context)
|
||||
{
|
||||
TouchPosition = context.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
public void OnTouched(InputAction.CallbackContext context)
|
||||
{
|
||||
if(context.started)
|
||||
OnTouchStart?.Invoke();
|
||||
else if(context.canceled)
|
||||
OnTouchEnd?.Invoke();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_gameInputActions != null)
|
||||
{
|
||||
_gameInputActions.Disable();
|
||||
_gameInputActions.Dispose();
|
||||
_gameInputActions = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7a7f36a3426c43b7a1ceeaa853bdc3e
|
||||
Reference in New Issue
Block a user