-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhotoCapture.cs
More file actions
161 lines (121 loc) · 3.92 KB
/
PhotoCapture.cs
File metadata and controls
161 lines (121 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR;
public class PhotoCapture : MonoBehaviour
{
[Header("Photo Taker")]
[SerializeField] private Image photoDisplayArea;
[SerializeField] private GameObject photoFrame;
[SerializeField] private GameObject camerUI;
[SerializeField] private GameObject cameraIndicator;
[SerializeField] private Text photoCounter;
[Header("Flash Effect")]
[SerializeField] private GameObject cameraFlash;
[SerializeField] private float flashTime;
[Header("Photo Fader Effect")]
[SerializeField] private Animator fadingAnimation;
[Header("Camera Audio Effect")]
[SerializeField] private AudioSource cameraAudio;
private Texture2D screenCapture;
private bool viewingPhoto;
private InputDevice rightController;
private bool rightTriggerState;
private bool rightGripState;
private GameObject playerHUD;
private GameObject info;
private int photoNumber = 0;
private void Start()
{
//get player HUD
playerHUD = GameObject.Find("PlayerHUD");
//get devices
List<InputDevice> devices = new List<InputDevice>();
//Get left controller
InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.Right, devices);
if (devices.Count > 0)
{
rightController = devices[0];
devices.Clear();
}
}
private void Update()
{
rightController.TryGetFeatureValue(CommonUsages.triggerButton, out rightTriggerState);
rightController.TryGetFeatureValue(CommonUsages.gripButton, out rightGripState);
SetPhotoCounter();
if (rightGripState)
{
//Activate Camera UI
camerUI.SetActive(true);
if (rightTriggerState)
{
if (!viewingPhoto)
{
StartCoroutine(CapturePhoto());
}
}
}
else
{
camerUI.SetActive(false);
}
}
IEnumerator CapturePhoto()
{
viewingPhoto = true;
cameraIndicator.SetActive(false);
camerUI.SetActive(false);
playerHUD.SetActive(false);
cameraIndicator.SetActive(false);
yield return new WaitForEndOfFrame(); //Take photo after everything has rendered to the screen
screenCapture = ScreenCapture.CaptureScreenshotAsTexture();
ShowPhoto();
if (photoNumber < 4)
{
photoNumber += 1;
}
yield return new WaitForSeconds(2.5f);
RemovePhoto();
}
void ShowPhoto()
{
Sprite photoSprite = Sprite.Create(screenCapture, new Rect(0.0f, 0.0f, screenCapture.width, screenCapture.height), new Vector2(0.5f, 0.5f), 100.0f);
photoDisplayArea.sprite = photoSprite;
playerHUD.SetActive(false);
//Activate flash
StartCoroutine(CameraFlashEffect());
photoFrame.SetActive(true);
fadingAnimation.Play("Photofade");
}
void RemovePhoto()
{
viewingPhoto = false;
photoFrame.SetActive(false);
playerHUD.SetActive(true);
}
void SetPhotoCounter()
{
photoCounter.text = photoNumber + "/4";
}
IEnumerator CameraFlashEffect()
{
cameraAudio.Play();
cameraFlash.SetActive(true);
yield return new WaitForSeconds(flashTime);
cameraFlash.SetActive(false);
}
public IEnumerator ShowCameraIndicator()
{
cameraIndicator.SetActive(true);
yield return new WaitForSeconds(0.5f);
cameraIndicator.SetActive(false);
yield return new WaitForSeconds(0.5f);
cameraIndicator.SetActive(true);
yield return new WaitForSeconds(0.5f);
cameraIndicator.SetActive(false);
yield return new WaitForSeconds(0.5f);
cameraIndicator.SetActive(true);
}
}