Requested Code!Send Texture Over Network

hi.many members asked this question.and i followed all answers!but nobody couldnt send texture!
i tried all ways!but not works!
please help me!Some body write a script for send texture please!many people need it!i need too!

(i ready to pay your work cost)

Create an enum ( : byte) which correlates to the textures, then send the byte (good for bandwidth) and load the texture locally. That is one way to do it :wink:

1 Like

i dont know how can i do it?(please send for me a script!and i can compensate your help!)
this is my last code:

    public Texture2D MyTexture;
    public byte[] N;
    public Texture2D texi;
    void Start () {
         texi = new Texture2D(MyTexture.width,MyTexture.height);
    }
    void Update () {
        if(Network.isServer){
        if(Input.GetKeyDown(KeyCode.X)){
            StartCoroutine(GetRenderTexturePixel(MyTexture));
            networkView.RPC("Send", RPCMode.Other,N);
        }
        }
        if(Network.isClient){
        if(Input.GetKeyDown(KeyCode.X)){
            texi.LoadImage(N);
            renderer.material.mainTexture = texi;
        }
        }
    }
    IEnumerator GetRenderTexturePixel(Texture2D tex)
    {
        Texture2D tempTex = new Texture2D(tex.width, tex.height);
        yield return new WaitForEndOfFrame();
        tempTex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
        tempTex.Apply();
        N= tempTex.EncodeToPNG();
    }
    [RPC]
    public  void Send(byte[] receivedByte){
        N=receivedByte;
    }

this code works for rendertexture.i tested it!(with Some Edit in scripts)!but it didnt send mytexture !

    public Texture2D textureToSend;

    private Texture2D receivedTexture;

    void Update () {
        if(Network.isServer){
            if(Input.GetKeyDown(KeyCode.X)){
                networkView.RPC("Send", RPCMode.Others, textureToSend.EncodeToPNG());
            }
        }
    }

    [RPC]
    private void Send(byte[] receivedByte){
        receivedTexture = new Texture2D(1, 1);
        receivedTexture.LoadImage(receivedByte);
    }

This will take “textureToSend” and send it to all clients when you press x. The clients will store the received texture in “receivedTexture”.

2 Likes

wow.that was so easy,but i didnt know.i tested it with a simple texture.but my game have many big texture.i will test this code and come back!thankyou Cha0os

that works nicely.

now i want know sending texture with networkview is rational for mmo games or www load from urls?

i have a host!my textures uploaded!now do i download textures with www foreach client or do i download textures by server and server sends textures to other clients with networkview?