Added a Screenshot save, but it's temporarily disabled.
This commit is contained in:
@@ -7,34 +7,57 @@ public class FlashBehaviour : MonoBehaviour
|
||||
public float flashInDuration = 0.05f;
|
||||
public float flashOutDuration = 0.2f;
|
||||
|
||||
//Photo display settings
|
||||
/*public GameObject photoCanvas;
|
||||
private SpriteRenderer photoSpriteRenderer;
|
||||
public Vector3 photoScale = new Vector3(0.2f, 0.2f, 1f);
|
||||
public Vector3 photoPosition = new Vector3(2, 2, 0);*/
|
||||
|
||||
private Color squareColor;
|
||||
private Coroutine flashCoroutine;
|
||||
private SpriteRenderer spriteRenderer;
|
||||
private SpriteRenderer flashSpriteRenderer;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
if (square == null)
|
||||
square = transform.Find("Square")?.gameObject;
|
||||
|
||||
if (square != null)
|
||||
spriteRenderer = square.GetComponent<SpriteRenderer>();
|
||||
flashSpriteRenderer = square.GetComponent<SpriteRenderer>();
|
||||
|
||||
if (spriteRenderer != null)
|
||||
if (flashSpriteRenderer != null)
|
||||
{
|
||||
squareColor = spriteRenderer.color;
|
||||
squareColor = flashSpriteRenderer.color;
|
||||
squareColor.a = 0;
|
||||
}
|
||||
|
||||
|
||||
// Initialize photoSpriteRenderer if photoCanvas is assigned
|
||||
/*if (photoCanvas != null)
|
||||
{
|
||||
photoSpriteRenderer = photoCanvas.GetComponent<SpriteRenderer>();
|
||||
}*/
|
||||
}
|
||||
|
||||
public void TriggerFlash()
|
||||
{
|
||||
// Use coroutine to ensure capture happens after rendering
|
||||
//StartCoroutine(CaptureAndShow());
|
||||
|
||||
// Flash Effect:
|
||||
if (flashCoroutine != null)
|
||||
StopCoroutine(flashCoroutine);
|
||||
flashCoroutine = StartCoroutine(FlashRoutine());
|
||||
}
|
||||
|
||||
// Capture screen and show photo
|
||||
/*private IEnumerator CaptureAndShow()
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
Texture2D screenTexture = ScreenCapture.CaptureScreenshotAsTexture();
|
||||
Debug.Log("Captured Screen Texture: " + screenTexture.width + "x" + screenTexture.height);
|
||||
StartCoroutine(ShowCapturedImage(screenTexture));
|
||||
}*/
|
||||
|
||||
private IEnumerator FlashRoutine()
|
||||
{
|
||||
// Fade in
|
||||
@@ -60,10 +83,35 @@ public class FlashBehaviour : MonoBehaviour
|
||||
|
||||
private void SetAlpha(float alpha)
|
||||
{
|
||||
if (spriteRenderer != null)
|
||||
if (flashSpriteRenderer != null)
|
||||
{
|
||||
squareColor.a = alpha;
|
||||
spriteRenderer.color = squareColor;
|
||||
flashSpriteRenderer.color = squareColor;
|
||||
}
|
||||
}
|
||||
// Show captured image on photo canvas
|
||||
/*private IEnumerator ShowCapturedImage(Texture2D texture)
|
||||
{
|
||||
byte[] pngData = texture.EncodeToPNG();
|
||||
System.IO.File.WriteAllBytes(Application.dataPath + "/../CapturedScreen.png", pngData);
|
||||
Debug.Log("Saved screenshot to: " + Application.dataPath + "/../CapturedScreen.png");
|
||||
|
||||
if (photoSpriteRenderer == null)
|
||||
{
|
||||
Debug.LogWarning("photoSpriteRenderer is not assigned or photoCanvas is missing a SpriteRenderer.");
|
||||
yield break;
|
||||
}
|
||||
|
||||
Sprite capturedSprite = Sprite.Create(
|
||||
texture,
|
||||
new Rect(0, 0, texture.width, texture.height),
|
||||
new Vector2(0.5f, 0.5f),
|
||||
100f
|
||||
);
|
||||
|
||||
photoSpriteRenderer.sprite = capturedSprite;
|
||||
photoCanvas.transform.position = photoPosition;
|
||||
photoCanvas.transform.localScale = photoScale;
|
||||
yield return null;
|
||||
}*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user