using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Threading.Tasks; using Amazon; using Amazon.S3; using Amazon.S3.Transfer; using Amazon.S3.Model; using UltraCombos.Upload; [System.Serializable] public class S3Tag { public string key; public string value; public static implicit operator Tag(S3Tag t) => new Tag { Key = t.key, Value = t.value }; } public class SaveImage : MonoBehaviour { public Uploader uploader; public RenderTexture renderTexture; public string OutputFolder = "output"; // Start is called before the first frame update void Start() { uploader = GetComponent(); } // Update is called once per frame void Update() { } public void save(string filename) { if(string.IsNullOrEmpty(filename)) { Debug.LogError("Filename cannot be null or empty."); return; } Debug.Log("Saving image to: " + filename); string timestamp = System.DateTime.Now.ToString("yyyyMMdd"); if (!System.IO.Directory.Exists(OutputFolder + "/" + timestamp)) { System.IO.Directory.CreateDirectory(OutputFolder + "/" + timestamp); } SaveRenderTextureToPNG(renderTexture, System.IO.Path.Combine(OutputFolder + "/" + timestamp, filename)); Debug.Log("Image saved to " + filename); // Optionally, you can also log the full path string fullPath = System.IO.Path.Combine(OutputFolder + "/" + timestamp + "/", filename); Debug.Log("path: " + fullPath); upload(fullPath); } void SaveRenderTextureToPNG(RenderTexture rt, string filePath) { RenderTexture currentRT = RenderTexture.active; RenderTexture.active = rt; Texture2D tex = new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, false); tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); tex.Apply(); byte[] bytes = tex.EncodeToPNG(); System.IO.File.WriteAllBytes(filePath, bytes); Debug.Log("Saved RenderTexture to PNG at " + filePath+ " with size: " + bytes.Length + " bytes"); RenderTexture.active = currentRT; Destroy(tex); } void upload(string filename){ if (uploader != null) { uploader.Upload(filename, (response) => { if (response.success) { Debug.Log("Upload successful: " + response); } else { Debug.LogError("Upload failed: " + response); } }); } else { Debug.LogError("Uploader is not assigned."); } } }