I have a project in witch I use mirror (unet 2.0 :P) to make a simple low poly WebGL game in unity. the game works great. Now I want to send a webcamstream over the network. I want to do this for every player.
I managed to get the cam working locally. Now I want to get it to run via the network. I made a Colors32[] array witch holds the image, it also works locally. Only If I try to send it over the network using a [Command] function I get the message that my packet is to large. I heard that splitting a package gives a lot of latency so I tried this solution sendTextures but it doesn't play nice with mirror. I only get one frame (if I'm lucky) if I turn my networkmanager on.
Do you guys have any pointers for me to get it working?
This is the code I have so far:
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;
*/
}
}