feat: webcam crop
This commit is contained in:
parent
f6b5408275
commit
95665b2aab
@ -625,10 +625,10 @@ RectTransform:
|
|||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 1908036955}
|
m_Father: {fileID: 1908036955}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||||
m_AnchorMax: {x: 1, y: 1}
|
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 0, y: 0}
|
m_SizeDelta: {x: 512, y: 512}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!114 &1128585036
|
--- !u!114 &1128585036
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@ -643,6 +643,8 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
webCamTexture: {fileID: 0}
|
webCamTexture: {fileID: 0}
|
||||||
|
freezeButton: {fileID: 1776746473}
|
||||||
|
resumeButton: {fileID: 1872873213}
|
||||||
--- !u!114 &1128585037
|
--- !u!114 &1128585037
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -11,14 +11,34 @@ public class CameraManager : MonoBehaviour
|
|||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
webCamTexture = new WebCamTexture();
|
webCamTexture = new WebCamTexture();
|
||||||
|
//gameObject.transform.rotation = transform.rotation * Quaternion.AngleAxis(webCamTexture.videoRotationAngle, Vector3.up);
|
||||||
WebcamResume();
|
WebcamResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
gameObject.GetComponent<RawImage>().texture = webCamTexture;
|
var x = 0;
|
||||||
gameObject.GetComponent<RawImage>().material.mainTexture = webCamTexture;
|
var y = 0;
|
||||||
|
var size = webCamTexture.height;
|
||||||
|
|
||||||
|
if (webCamTexture.height > webCamTexture.width)
|
||||||
|
{
|
||||||
|
size = webCamTexture.width;
|
||||||
|
y = (webCamTexture.height - webCamTexture.width) / 2;
|
||||||
|
}
|
||||||
|
else if (webCamTexture.height < webCamTexture.width)
|
||||||
|
{
|
||||||
|
size = webCamTexture.height;
|
||||||
|
x = (webCamTexture.width - webCamTexture.height) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2D cropped = new(size, size);
|
||||||
|
cropped.SetPixels(webCamTexture.GetPixels(x, y, size, size));
|
||||||
|
cropped.Apply();
|
||||||
|
|
||||||
|
gameObject.GetComponent<RawImage>().texture = cropped;
|
||||||
|
gameObject.GetComponent<RawImage>().material.mainTexture = cropped;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WebcamResume()
|
public void WebcamResume()
|
||||||
|
@ -8,7 +8,7 @@ PlayerSettings:
|
|||||||
AndroidProfiler: 0
|
AndroidProfiler: 0
|
||||||
AndroidFilterTouchesWhenObscured: 0
|
AndroidFilterTouchesWhenObscured: 0
|
||||||
AndroidEnableSustainedPerformanceMode: 0
|
AndroidEnableSustainedPerformanceMode: 0
|
||||||
defaultScreenOrientation: 4
|
defaultScreenOrientation: 0
|
||||||
targetDevice: 2
|
targetDevice: 2
|
||||||
useOnDemandResources: 0
|
useOnDemandResources: 0
|
||||||
accelerometerFrequency: 60
|
accelerometerFrequency: 60
|
||||||
|
Loading…
Reference in New Issue
Block a user