#pragma strict
var webcamTexture : WebCamTexture = WebCamTexture();
var receivedTexture:Texture2D;
var devices : WebCamDevice[];
var TimeBack:float;
function Start(){
devices = WebCamTexture.devices;
for( var i = 0 ; i < devices.length ; i++ )
Debug.Log(devices[i].name);
}
function Update () {
if(Network.isServer){
webcamTexture.Play();
if(webcamTexture) {
renderer.material.mainTexture = webcamTexture;
var destTexture = new Texture2D(webcamTexture.width, webcamTexture.height, TextureFormat.ARGB32, false);
var textureData = webcamTexture.GetPixels();
destTexture.SetPixels(textureData);
destTexture.Apply();
var pngData = destTexture.EncodeToPNG();
receivedTexture= destTexture as Texture2D;
if(Time.time>(TimeBack+0.5f)){
networkView.RPC("Send",RPCMode.Others,pngData);
TimeBack=Time.time;
}
}
}
}
@RPC
private function Send(receivedByte:byte[]){
receivedTexture = null;
receivedTexture = new Texture2D(1, 1);
receivedTexture.LoadImage(receivedByte);
renderer.material.mainTexture = receivedTexture;
}
this is my code for send my webcam to others!but how Can i use a delay code for improve Send Byte Speed.how delete my last bytes.Other Clients Receive MyWebCam nice,but after a moment They receive webcam of many times ago!
↧