ASLObjectSendAndSetTexture2D Method |
Namespace: ASL
public void SendAndSetTexture2D( Texture2D _myTexture2D, ASLObjectPostDownloadFunction _myPostDownloadFunction, bool _uploadAsPNG = false )
An example of how to send a Texture2D. Optional parameters include to send it as a PNG (larger file, but allows for transparent pixels, default is JPG), and to synchronize every user's callback function (in this case, "ChangeSpriteTexture"), the default is to not synchronize callback functions, so once a user downloads an image, by default they will execute their given function instead of waiting for every other user to download the image as well. public void SendAndChangeTexture() { _MyASLObject.GetComponent<ASL.ASLObject>().SendAndSetTexture2D(_TextureToSend, ChangeSpriteTexture, false); } The function is called after the Texture2D is sent by all users. Note: All users must have this function defined for them (just like with other callback functions except claim). Just because other users do not have the Texture2D being sent does not mean they do not need this function. This function can be used to do whatever you want to do after the Texture2D has been transferred. In this case, it is simply swapping the Texture2D out on the current sprite, changing the image the sprite displays. This function can be named anything, but must be a static public void function. static public void ChangeSpriteTexture(GameObject _myGameObject, Texture2D _myTexture2D) { Sprite newSprite = Sprite.Create(_myTexture2D, _myGameObject.GetComponent<SpriteRenderer>().sprite.rect, new Vector2(0.5f, 0.5f), _myGameObject.GetComponent<SpriteRenderer>().sprite.pixelsPerUnit); _myGameObject.GetComponent<SpriteRenderer>().sprite = newSprite; }