我最近在使用 WebCamTexture API in Unity ,但遇到了几个问题。
我最大的问题是方向。当我在手机上运行该应用程序时,它无法在纵向模式下正常工作:图像的方向是横向的,而手机是纵向的。旋转手机没有帮助。
然后我将应用程序的默认方向更改为横向并且它起作用了,但图像被反射:字母等在图像中会向后。将图像沿 y 轴旋转 180 度没有帮助,因为它是单面图像。
这是单独的相机代码:
cam = new WebCamTexture();
camImage.texture = cam;
camImage.material.mainTexture = cam;
cam.Play ();
camImage.transform.localScale = new Vector3(-1,-1,1);
其中 camImage 是 RawImage。
我如何旋转图像才能正确地以纵向显示并正确地反射(reflect)图像?我是否错误地使用了 API?
请您参考如下方法:
重要-
多年来,在 Unity3D 中,无论是 ios 还是 droid,在相机工作中使用“NatCam”确实是唯一实用的 - 每个使用相机的应用程序都在使用它。
没有其他现实的解决方案,直到 Unity 真正完成工作并包括(工作:))相机软件。
解决方案基本上是这样的......
你必须在每一帧都这样做,你不能在“相机启动时”这样做。
Unity f'd 起来,实际值仅在一秒左右后到达。这是一个众所周知的问题
private void _orient()
{
float physical = (float)wct.width/(float)wct.height;
rawImageARF.aspectRatio = physical;
float scaleY = wct.videoVerticallyMirrored ? -1f : 1f;
rawImageRT.localScale = new Vector3(1f, scaleY, 1f);
int orient = -wct.videoRotationAngle;
rawImageRT.localEulerAngles = new Vector3(0f,0f,orient);
showOrient.text = orient.ToString();
}
