-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImagePicker.cs
83 lines (69 loc) · 1.63 KB
/
ImagePicker.cs
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
using UnityEngine;
public class ImagePicker : MonoBehaviour
{
[SerializeField]
private Material picture;
[SerializeField]
private Vector3 imageScale;
[SerializeField]
private Texture defaultTexture;
[SerializeField]
private Transform picturePlane;
[SerializeField]
private GameObject takePicButton;
WebCamTexture camText;
bool camAvailable;
bool isDeafault = true;
private void Start()
{
picture.mainTexture = defaultTexture;
WebCamDevice[] devices = WebCamTexture.devices;
if(devices.Length == 0)
{
camAvailable = false;
return;
}
for(int i = 0; i < devices.Length; i++)
{
if (!devices[i].isFrontFacing)
{
camText = new WebCamTexture();
}
}
if (camText == null)
return;
camText.Play();
camAvailable = true;
camText.wrapMode = TextureWrapMode.Repeat;
}
private void Update()
{
if (!camAvailable)
return;
int orient = -camText.videoRotationAngle;
if(!isDeafault)
picturePlane.localEulerAngles = new Vector3(0f, 0f, orient);
}
/*
public void SetImage()
{
NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
{
if (path != null)
{
Texture texture = NativeGallery.LoadImageAtPath(path);
text = texture;
}
});
}
*/
public void TakeImage()
{
Texture2D snap = new Texture2D(camText.width, camText.height);
snap.SetPixels(camText.GetPixels());
snap.Apply();
isDeafault = false;
picture.mainTexture = snap;
picturePlane.transform.localScale = imageScale;
}
}