Click or drag to resize

ASLObjectSendAndSetTexture2D Method

Sends a Texture2D to other users and then calls the sent function once it is successfully recreated

Namespace:  ASL
Assembly:  Assembly-CSharp (in Assembly-CSharp.dll) Version: 0.0.0.0
Syntax
public void SendAndSetTexture2D(
	Texture2D _myTexture2D,
	ASLObjectPostDownloadFunction _myPostDownloadFunction,
	bool _uploadAsPNG = false
)

Parameters

_myTexture2D
Type: Texture2D
The Texture2D to be uploaded and sent to others
_myPostDownloadFunction
Type: ASLASLObjectPostDownloadFunction
The function to be called after the Texture2D is downloaded
_uploadAsPNG (Optional)
Type: SystemBoolean
Optional parameter allowing the user to upload the image as a PNG. The default is JPG.
Examples
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;
}
See Also