using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.IO; using UnityEngine.Networking; public class ScreenShot : MonoBehaviour { string folderPath = "Assets/Resources/Screenshots/"; // the path of your project folder // Update is called once per frame public void Capture() { StartCoroutine(Capturing()); } IEnumerator Capturing() { WaitForSeconds _w = new WaitForSeconds(0.10f); /*if (!System.IO.Directory.Exists(folderPath)) // if this path does not exist yet System.IO.Directory.CreateDirectory(folderPath); // it will get created*/ //var screenshotName = //"Screenshot_1" + //System.DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss") + // puts the current time right into the screenshot name //".png"; // put youre favorite data format here //ScreenCapture.CaptureScreenshot(System.IO.Path.Combine(folderPath, screenshotName), 2); yield return new WaitForEndOfFrame(); //Texture2D texture2D01 = ScreenCapture.CaptureScreenshotAsTexture(); // takes the sceenshot, the "2" is for the scaled resolution, you can put this to 600 but it will take really long to scale the image up //Debug.Log(folderPath + screenshotName); // You get instant feedback in the console var uploadURL = "https://gateeleven.net/wp-content/uploads/ALI/unityUpload.php"; // Create a texture the size of the screen, RGB24 format Texture2D savedTexture = ScreenCapture.CaptureScreenshotAsTexture(); if (savedTexture == null) { Debug.Log("Empty"); } Texture2D newTexture = new Texture2D(savedTexture.width, savedTexture.height, TextureFormat.ARGB32, false); newTexture.SetPixels(0, 0, savedTexture.width, savedTexture.height, savedTexture.GetPixels()); //newTexture = FillInClear(newTexture); newTexture.Apply(); var bytes = newTexture.EncodeToPNG(); // Encode texture into PNG //var bytes = tex.EncodeToPNG(); Destroy(newTexture); // Create a Web Form var form = new WWWForm(); form.AddField("frameCount", Time.frameCount.ToString()); form.AddBinaryData("file", bytes, "texture.png", "image/png"); //File.WriteAllBytes("abc.png",bytes); // Upload to a cgi script WWW w = new WWW(uploadURL, form); //yield return w; if (w.error != null) { Debug.Log(w.error); } else { Debug.Log("Finished Uploading Texture"); } yield return _w; GameObject.Find("Separator1").GetComponent().enabled = false; GameObject.Find("Separator2").GetComponent().enabled = false; GameObject.Find("Text FV").GetComponent().enabled = false; GameObject.Find("Text BV").GetComponent().enabled = false; GameObject.Find("Text RV").GetComponent().enabled = false; GameObject.Find("Text LV").GetComponent().enabled = false; StartCoroutine(GetTexture()); } IEnumerator GetTexture() { UnityWebRequest www = UnityWebRequestTexture.GetTexture("https://gateeleven.net/wp-content/uploads/ALI/Textures/FourViews.png"); yield return www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { print(www.error); } else { for (int i = 0; i < 4; i++) { GameObject.Find("FourViewsImg").GetComponent().texture = ((DownloadHandlerTexture)www.downloadHandler).texture; GameObject.Find("FourViewsImg").GetComponent().enabled = true; GameObject.Find("FourViews").transform.GetChild(i).GetComponent().enabled = false; GameObject.Find("CanvasPlan").transform.GetChild(0).gameObject.SetActive(true); } } } }