Compare commits
2 Commits
ec7f2b3eb7
...
aac0dc1513
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aac0dc1513 | ||
|
|
848b176953 |
@@ -1,3 +1,4 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -5,6 +6,7 @@ namespace Darkmatter.Core.Contracts.Services.Gallery
|
||||
{
|
||||
public interface IGalleryService
|
||||
{
|
||||
void SaveImageAsync(Texture2D sprite, string fileName);
|
||||
UniTask SaveImageAsync(Texture2D sprite, string fileName,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@
|
||||
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
|
||||
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
|
||||
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
||||
"GUID:6e5063adab271564ba0098a06a8cebda"
|
||||
"GUID:6e5063adab271564ba0098a06a8cebda",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
BIN
Readme.docx
Normal file
BIN
Readme.docx
Normal file
Binary file not shown.
Reference in New Issue
Block a user