public void CheckCorrect(Texture2D sourceTexture) { if (Application.isEditor) { byte[] bytes = sourceTexture.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/Rendering/textures/test.png", bytes); } Image <Bgr, byte> sourceImage = ImageHelper.ToImage(sourceTexture); Image <Gray, float> result = new Image <Gray, float> (257 - templateImage.Width, 257 - templateImage.Height); Emgu.CV.CvInvoke.MatchTemplate(sourceImage, templateImage, result, TemplateMatchingType.CcorrNormed, mask); double[] minValues, maxValues; Point[] minLocations, maxLocations; result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations); print(maxValues [0] + " " + maxLocations [0]); if (maxValues [0] > accuracy) { solved = true; gameObject.transform.Find("whole").gameObject.SetActive(true); string levelName = "Level" + (SceneManager.GetActiveScene().buildIndex - 1); float currentTime = Time.time - startTime; if (!PlayerPrefs.HasKey(levelName)) { PlayerPrefs.SetFloat(levelName, currentTime); } else if (PlayerPrefs.GetFloat(levelName) > currentTime) { PlayerPrefs.SetFloat(levelName, currentTime); OverlayEffects.ShowTime("New best time! " + formatTime(currentTime)); } else { OverlayEffects.ShowTime(formatTime(currentTime) + "\nBest time: " + formatTime(PlayerPrefs.GetFloat(levelName))); } PlayerPrefs.Save(); //sender.SendTime (levelName, currentTime); if (Application.isEditor) { RotRememberer.WriteString(gameObject); } StartCoroutine("NextLevel"); } }
// Update is called once per frame void Update() { if (!solved) { if (!levelBeacon.GetActive()) { return; } bool focus = Input.GetKey(KeyCode.F); if (focus && !wasFocus) //do once after f is pressed { levelBeacon.SetCameraActive(true); StartCoroutine(levelBeacon.TakePicture(this)); } else if (!focus && wasFocus) //do once after release { levelBeacon.SetCameraActive(false); FPCamera.enabled = true; } wasFocus = focus; OverlayEffects.ShowTime(formatTime(Time.time - startTime)); } }