artbook added to drawing

This commit is contained in:
Savya Bikram Shah
2026-05-29 18:28:06 +05:45
parent 676b389244
commit 47fb204446
10 changed files with 141 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ namespace Darkmatter.Services.Capture
{
var paperCanvas = GetRootCanvas(captureObject);
var disabledCanvases = DisableOtherRootCanvases(paperCanvas);
var disabledGraphics = HideNonPaperGraphics(captureObject != null ? captureObject.transform : null);
var cam = Camera.main;
CameraClearFlags prevFlags = default;
Color prevBg = default;
@@ -26,7 +27,21 @@ namespace Darkmatter.Services.Capture
await UniTask.WaitForEndOfFrame(cancellationToken);
var fullScreen = ScreenCapture.CaptureScreenshotAsTexture();
int sw = Screen.width;
int sh = Screen.height;
var captureRT = RenderTexture.GetTemporary(sw, sh, 0, RenderTextureFormat.ARGB32);
ScreenCapture.CaptureScreenshotIntoRenderTexture(captureRT);
var prevActive = RenderTexture.active;
RenderTexture.active = captureRT;
var fullScreen = new Texture2D(sw, sh, TextureFormat.RGBA32, mipChain: false);
fullScreen.ReadPixels(new Rect(0, 0, sw, sh), 0, 0);
fullScreen.Apply();
RenderTexture.active = prevActive;
RenderTexture.ReleaseTemporary(captureRT);
FlipVertical(fullScreen);
try
{
Rect crop = ComputeCropRect(captureObject, fullScreen.width, fullScreen.height);
@@ -62,6 +77,7 @@ namespace Darkmatter.Services.Capture
finally
{
Object.Destroy(fullScreen);
foreach (var g in disabledGraphics) if (g != null) g.enabled = true;
foreach (var c in disabledCanvases) if (c != null) c.enabled = true;
if (cam != null)
{
@@ -91,6 +107,21 @@ namespace Darkmatter.Services.Capture
return disabled;
}
private static List<UnityEngine.UI.Graphic> HideNonPaperGraphics(Transform paper)
{
var disabled = new List<UnityEngine.UI.Graphic>();
if (paper == null) return disabled;
var all = Object.FindObjectsByType<UnityEngine.UI.Graphic>(FindObjectsSortMode.None);
foreach (var g in all)
{
if (g == null || !g.enabled) continue;
if (g.transform.IsChildOf(paper)) continue;
g.enabled = false;
disabled.Add(g);
}
return disabled;
}
private static Rect ComputeCropRect(GameObject target, int screenW, int screenH)
{
if (target == null || target.transform is not RectTransform rt)
@@ -106,6 +137,18 @@ namespace Darkmatter.Services.Capture
return Rect.MinMaxRect(minX, minY, maxX, maxY);
}
private static void FlipVertical(Texture2D tex)
{
int w = tex.width, h = tex.height;
var pixels = tex.GetPixels();
var flipped = new Color[pixels.Length];
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
flipped[(h - 1 - y) * w + x] = pixels[y * w + x];
tex.SetPixels(flipped);
tex.Apply();
}
private static Texture2D Resize(Texture2D src, int width, int height)
{
var rt = RenderTexture.GetTemporary(width, height);

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,20 @@
using System;
using UnityEngine;
namespace Darkmatter.Services.Music.Systems
{
[Serializable]
public readonly struct MusicConfig
{
public AudioClip DefaultTrack { get; }
public float DefaultVolume { get; }
public float CrossFadeSeconds { get; }
public MusicConfig(AudioClip defaultTrack, float defaultVolume, float crossFadeSeconds)
{
DefaultTrack = defaultTrack;
DefaultVolume = defaultVolume;
CrossFadeSeconds = crossFadeSeconds;
}
}
}