Updates
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Threading;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -5,6 +6,7 @@ namespace Darkmatter.Core.Contracts.Services.Gallery
|
|||||||
{
|
{
|
||||||
public interface IGalleryService
|
public interface IGalleryService
|
||||||
{
|
{
|
||||||
UniTask SaveImageAsync(Texture2D sprite, string fileName, string albumName = "Colorbook");
|
UniTask SaveImageAsync(Texture2D sprite, string fileName,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
using Darkmatter.Core.Contracts.Services.Gallery;
|
using Darkmatter.Core.Contracts.Services.Gallery;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -7,7 +8,7 @@ namespace Darkmatter.Services.Gallery
|
|||||||
{
|
{
|
||||||
public class GalleryService : IGalleryService
|
public class GalleryService : IGalleryService
|
||||||
{
|
{
|
||||||
public async UniTask SaveImageAsync(Texture2D image, string fileName, string albumName = "Colorbook")
|
public async UniTask SaveImageAsync(Texture2D image, string fileName, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var permission = await NativeGallery.RequestPermissionAsync(NativeGallery.PermissionType.Write,
|
var permission = await NativeGallery.RequestPermissionAsync(NativeGallery.PermissionType.Write,
|
||||||
NativeGallery.MediaType.Image);
|
NativeGallery.MediaType.Image);
|
||||||
@@ -18,10 +19,12 @@ namespace Darkmatter.Services.Gallery
|
|||||||
}
|
}
|
||||||
|
|
||||||
var tcs = new UniTaskCompletionSource();
|
var tcs = new UniTaskCompletionSource();
|
||||||
|
var registration = cancellationToken.Register(() => tcs.TrySetCanceled(cancellationToken));
|
||||||
|
|
||||||
NativeGallery.SaveImageToGallery(image, albumName,
|
NativeGallery.SaveImageToGallery(image, "Colorbook",
|
||||||
filename: $"colorbook_{DateTime.UtcNow:yyyyMMdd_HHmmss}.png", callback: (success, path) =>
|
filename: $"colorbook_{DateTime.UtcNow:yyyyMMdd_HHmmss}.png", callback: (success, path) =>
|
||||||
{
|
{
|
||||||
|
registration.Dispose();
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
Debug.LogError("Failed to save image to gallery.");
|
Debug.LogError("Failed to save image to gallery.");
|
||||||
@@ -30,6 +33,7 @@ namespace Darkmatter.Services.Gallery
|
|||||||
{
|
{
|
||||||
Debug.Log($"Image saved to gallery at: {path}");
|
Debug.Log($"Image saved to gallery at: {path}");
|
||||||
}
|
}
|
||||||
|
|
||||||
tcs.TrySetResult();
|
tcs.TrySetResult();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
|
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
|
||||||
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
|
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
|
||||||
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
||||||
"GUID:6e5063adab271564ba0098a06a8cebda"
|
"GUID:6e5063adab271564ba0098a06a8cebda",
|
||||||
|
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|||||||
Reference in New Issue
Block a user