Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created July 22, 2017 20:59
Show Gist options
  • Save unity3dcollege/b3afb67d2bb4090dc39deefacffc51be to your computer and use it in GitHub Desktop.
Save unity3dcollege/b3afb67d2bb4090dc39deefacffc51be to your computer and use it in GitHub Desktop.
using UnityEngine;
public class PaintCanvas : MonoBehaviour
{
public static Texture2D Texture { get; private set; }
public static byte[] GetAllTextureData()
{
return Texture.GetRawTextureData();
}
private void Start()
{
PrepareTemporaryTexture();
}
private void PrepareTemporaryTexture()
{
Texture = (Texture2D)GameObject.Instantiate(GetComponent<Renderer>().material.mainTexture);
GetComponent<Renderer>().material.mainTexture = Texture;
}
internal static void SetAllTextureData(byte[] textureData)
{
Texture.LoadRawTextureData(textureData);
Texture.Apply();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment