问题描述
我在女巫中有一个项目,我使用 mirror (unet 2.0 :P) 统一制作一个简单的低多边形 WebGL 游戏。游戏效果很好。现在我想通过网络发送网络摄像头流。我想为每个玩家都这样做。
我设法让摄像头在本地工作。现在我想让它通过网络运行。我制作了一个 Colors32[] 数组,用于保存图像,它也可以在本地使用。只有当我尝试使用 [Command] 函数通过网络发送它时,我才会收到我的数据包太大的消息。我听说拆分一个包会产生很多延迟,所以我尝试了这个解决方案 sendTextures,但它在镜像中效果不佳。如果我打开网络管理器,我只会得到一帧(如果我幸运的话)。
你们有什么建议让我让它工作吗?
这是我目前的代码:
public class WebCamScript : NetworkBehavIoUr
{
static WebCamTexture camTexture;
Color32[] data;
private int width = 640,height = 480;
public GameObject screen;
void Start()
{
screen = GameObject.Find("screen");
if (camTexture == null)
camTexture = new WebCamTexture(width,height);
data = new Color32[width * height];
if (!camTexture.isPlaying)
camTexture.Play();
}
// Update is called once per frame
void Update()
{
CmdsendCam(data.Length,camTexture.GetPixels32(data));
}
[Command]
void CmdsendCam(int length,Color32[] receivedImage)
{
/*
Texture2D t = new Texture2D(width,height);
t.SetPixels32(receivedImage);
t.Apply();
screen.GetComponent<Renderer>().material.mainTexture = t;
*/
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)