Created
July 22, 2017 20:59
-
-
Save unity3dcollege/b3afb67d2bb4090dc39deefacffc51be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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