void takePhoto() { if (!gameObject.activeSelf || m_photoCount >= m_maxPhotoCount) { return; } m_source.Play(); m_flashSurface.SetActive(true); DOVirtual.DelayedCall(m_flashDuration, () => m_flashSurface.SetActive(false)); const int width = 640; const int height = 360; RenderTexture rt = new RenderTexture(width, height, 24); m_camera.targetTexture = rt; Texture2D pic = new Texture2D(width, height, TextureFormat.RGB24, false); m_camera.Render(); RenderTexture.active = rt; pic.ReadPixels(new Rect(0, 0, width, height), 0, 0); pic.Apply(); m_camera.targetTexture = null; RenderTexture.active = null; Destroy(rt); PhotoInfos infos = new PhotoInfos(); infos.photo = pic; infos.pos = getPhotoLocation(); photos.Add(infos); m_photoCount++; Event <PhotoTakenEvent> .Broadcast(new PhotoTakenEvent(pic, m_photoCount, m_maxPhotoCount)); }
List <PhotoInfos> getScorablePhotos() { List <PhotoInfos> m_scores = new List <PhotoInfos>(); foreach (var p in CameraLogic.photos) { int bestX = 0; int bestY = 0; float bestDistance = float.MaxValue; string bestName = ""; foreach (var i in LevelMap.instance.importantPoints) { var d = new Vector2(p.pos.x - i.x, p.pos.y - i.y).magnitude; if (d < bestDistance) { bestX = i.x; bestY = i.y; bestName = i.name; bestDistance = d; } } if (bestDistance < m_maxPhotoDistance) { var s = new PhotoInfos(); s.x = bestX; s.y = bestY; s.name = bestName; s.distance = bestDistance; s.pic = p.photo; m_scores.Add(s); } } for (int i = m_scores.Count - 1; i >= 0; i--) { bool isBest = true; for (int j = 0; j < m_scores.Count; j++) { if (i == j) { continue; } var a = m_scores[i]; var b = m_scores[j]; if (a.x == b.x && a.y == b.y && a.distance > b.distance) { isBest = false; break; } } if (!isBest) { m_scores.RemoveAt(i); } } foreach (var s in m_scores) { s.score = (m_maxScorePhoto - m_minScorePhoto) * (1 - s.distance / m_maxPhotoDistance) + m_minScorePhoto; } return(m_scores); }