public IEnumerator TakeScreenshot() { string imageName = Application.dataPath + screenshotCount + ".png"; //Hide canvas ui.Hide(hideGameObject); //Wait until rendering is done yield return(new WaitForEndOfFrame()); // Take the screenshot screenshotTexture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); screenshotTexture.ReadPixels(new UnityEngine.Rect(0, 0, Screen.width, Screen.height), 0, 0, false); screenshotTexture.Apply(); //Show canvas ui.Show(hideGameObject); // Create a sprite Sprite screenshotSprite = Sprite.Create(screenshotTexture, new UnityEngine.Rect(0, 0, Screen.width, Screen.height), new Vector2(0.5f, 0.5f)); // Set the sprite to the screenshotPreview screenshotPreview.GetComponent <Image>().sprite = screenshotSprite; //Show the image ui.Show(screenshotPreview); }
public IEnumerator ReadQRCode() { while (true) { if (cameraInitialized) { image = CameraDevice.Instance.GetCameraImage(mPixelFormat); if (image == null) { Debug.Log("No camera image found"); } else { result = barCodeReader.Decode(image.Pixels, image.BufferWidth, image.BufferHeight, RGBLuminanceSource.BitmapFormat.RGB24); image = null; if (result != null) { // QRCode detected. QRVisible = true; Debug.Log(i + " QR code: " + result.Text); //Do something with the QR code. GameObject instantiatedSucces = Instantiate(succes, GameObject.Find("Canvas Start").transform); Manager.Instance.controllerUrl = result.Text; Debug.Log("Manager's controllerUrl set: " + Manager.Instance.controllerUrl); int firstIndex = 0; int secondIndex = result.Text.IndexOf("can"); int thirdIndex = result.Text.IndexOf("=") + 1; string canvasUrl = result.Text.Substring(firstIndex, secondIndex) + result.Text.Substring(thirdIndex); Manager.Instance.canvasUrl = canvasUrl + "?raw"; Debug.Log("Manager's variable set: " + Manager.Instance.canvasUrl); result = null; // clear data yield return(new WaitForSeconds(1)); Destroy(instantiatedSucces); uiMethods.Show(GameObject.Find("Canvas full")); uiMethods.Hide(GameObject.Find("Canvas Start")); yield break; } } } yield return(new WaitForSeconds(0.5f)); } }
void Start() { Debug.Log("Start bliver kaldt igen"); barCodeReader = new BarcodeReader(); uiMethods = FindObjectOfType <UIMethods>(); uiMethods.Hide(GameObject.Find("Canvas full")); uiMethods.Show(GameObject.Find("Canvas Start")); StartCoroutine(InitializeCamera()); }
public void OnButtonBackPressed() { uiMethods.Hide(GameObject.Find("Canvas full")); uiMethods.Show(GameObject.Find("Canvas Start")); StartCoroutine(FindObjectOfType <QRScannerVuforia>().ReadQRCode()); }