Skip to content

Commit

Permalink
Added feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Wildeaso1 committed Apr 25, 2024
1 parent f8af2fb commit 74c66f4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
6 changes: 6 additions & 0 deletions Assets/Scripts/UI/Canvas/PhotoTaking/CameraPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public sealed class CameraPanel : CameraPermission
[SerializeField] private RawImage background;
[SerializeField] private TMP_Text pointOfInterestName;
[SerializeField] private Texture2D pointOfInterestRender;
[SerializeField] private RenderTexture renderTexture;

/// <summary>
/// Fills the camera panel with data from the given scriptable object
Expand All @@ -24,5 +25,10 @@ public void SetPanelData(PhotoData targetPhotoData)
// to do: set render from scriptable object
taker.StartCamera(background);
}
private void Update()
{
if(taker.WebcamTexture && taker.WebcamTexture.isPlaying)
Graphics.Blit(taker.WebcamTexture, renderTexture);
}
}
}
27 changes: 10 additions & 17 deletions Assets/Scripts/UI/Canvas/PhotoTaking/PhotoTaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public sealed class PhotoTaker : CameraPermission
[SerializeField] private RawImage liveCamera;
[SerializeField] private RawImage lastPhoto;
[SerializeField] private Texture2D defaultTex;
[SerializeField] private RenderTexture renderTexture;

private WebCamTexture _webcamTexture;

public WebCamTexture WebcamTexture { get; private set; }
private Texture2D _currentPhoto;
private PhotoInteractable _currentInteractable;

Expand All @@ -35,17 +34,11 @@ public sealed class PhotoTaker : CameraPermission

private void Awake() => FindCamera();

private void Update()
{
if(_webcamTexture && _webcamTexture.isPlaying)
Graphics.Blit(_webcamTexture, renderTexture);
}

private void OnDisable()
{
if (_webcamTexture != null
&& _webcamTexture.isPlaying)
_webcamTexture.Stop();
if (WebcamTexture != null
&& WebcamTexture.isPlaying)
WebcamTexture.Stop();
}

/// <summary>
Expand All @@ -61,8 +54,8 @@ private void OnDisable()

private void ApplyCamera(RawImage targetImage)
{
_webcamTexture.Play();
targetImage.texture = _webcamTexture;
WebcamTexture.Play();
targetImage.texture = WebcamTexture;
onOpenCamera?.Invoke();
}

Expand All @@ -71,13 +64,13 @@ private void ApplyCamera(RawImage targetImage)
/// </summary>
public void TakePhoto()
{
if (!_webcamTexture.isPlaying)
if (!WebcamTexture.isPlaying)
throw new Exception(CAMERA_NOT_ACTIVE_ERROR);

if (_currentInteractable == null)
throw new Exception(NO_PHOTO_INTERACTABLE_ERROR);

_currentPhoto = CaptureFrame(_webcamTexture);
_currentPhoto = CaptureFrame(WebcamTexture);

if (!_currentInteractable.SaveTexture(_currentPhoto))
throw new Exception(UNABLE_TO_SAVE_PHOTO_ERROR + _currentInteractable.name);
Expand All @@ -102,7 +95,7 @@ private void FindCamera()
if (devices.Length <= 0)
throw new Exception(NO_CAMERA_ERROR);

_webcamTexture = new WebCamTexture(devices[0].name);
WebcamTexture = new WebCamTexture(devices[0].name);
}

private Texture2D CaptureFrame(WebCamTexture liveTexture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RenderTexture:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Webcam
m_Name: RT_Webcam
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
Expand Down
File renamed without changes.

0 comments on commit 74c66f4

Please sign in to comment.