Skip to content

Commit

Permalink
[KK/KKS/EC] Add ScreenshotManager.Capture API to match AI/HS2; discou…
Browse files Browse the repository at this point in the history
…rage using AlphaShot2 directly
  • Loading branch information
ManlyMarco committed Mar 12, 2022
1 parent d899fb4 commit 09839ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Core_Screencap/Core.ScreenshotManager.cs
Expand Up @@ -269,6 +269,31 @@ protected void Update()
else if (KeyCapture360in3D.Value.IsDown()) StartCoroutine(Take360Screenshot(true));
}

/// <summary>
/// Capture the screen into a texture based on supplied arguments. Remember to destroy the texture when done with it.
/// Can return null if there no 3D camera was found to take the picture with.
/// </summary>
/// <param name="width">Width of the resulting capture, after downscaling</param>
/// <param name="height">Height of the resulting capture, after downscaling</param>
/// <param name="downscaling">How much to oversize and then downscale. 1 for none.</param>
/// <param name="transparent">Should the capture be transparent</param>
public Texture2D Capture(int width, int height, int downscaling, bool transparent)
{
if (currentAlphaShot == null)
{
Logger.LogDebug("Capture - No camera found");
return null;
}

try { OnPreCapture?.Invoke(); }
catch (Exception ex) { Logger.LogError(ex); }
var capture = currentAlphaShot.CaptureTex(width, height, downscaling, transparent ? AlphaShot2.AlphaMode.rgAlpha : AlphaShot2.AlphaMode.None);
try { OnPostCapture?.Invoke(); }
catch (Exception ex) { Logger.LogError(ex); }

return capture;
}

private void TakeScreenshot()
{
var filename = GetUniqueFilename("UI");
Expand Down
2 changes: 2 additions & 0 deletions src/Core_Screencap/Renderers/AlphaShot2.cs
Expand Up @@ -4,10 +4,12 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityStandardAssets.ImageEffects;
#pragma warning disable 1591

//code by essu
namespace alphaShot
{
[Obsolete("Avoid using AlphaShot2 directly since it might get changed in the future. Use ScreenshotManager.Capture instead", false)]
public class AlphaShot2 : MonoBehaviour
{
private Material matScale;
Expand Down

0 comments on commit 09839ec

Please sign in to comment.