Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MeshPaintableSource : MonoBehaviour, IClientComponent
- {
- //
- // Fields
- //
- public int texWidth = 256;
- public Vector3 localRotation;
- public Vector3 localPosition;
- public Mesh collisionMesh;
- public GameObject sourceObject;
- [NonSerialized]
- public Texture2D texture;
- public int texHeight = 128;
- public string replacementTextureName = "_DecalTexture";
- public float cameraFOV = 60;
- public float cameraDistance = 2;
- //
- // Methods
- //
- public void Free ()
- {
- if (this.texture) {
- Object.Destroy (this.texture);
- this.texture = null;
- }
- }
- public void Init ()
- {
- if (this.texture) {
- return;
- }
- this.texture = new Texture2D (this.texWidth, this.texHeight, TextureFormat.ARGB32, false);
- this.texture.name = "MeshPaintableSource_" + base.gameObject.name;
- this.texture.Clear (Color.clear);
- MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock ();
- materialPropertyBlock.SetTexture (this.replacementTextureName, this.texture);
- Renderer[] componentsInChildren = base.transform.root.GetComponentsInChildren<Renderer> (true);
- for (int i = 0; i < componentsInChildren.Length; i++) {
- Renderer renderer = componentsInChildren [i];
- renderer.SetPropertyBlock (materialPropertyBlock);
- }
- }
- public void Load (byte[] data)
- {
- this.Init ();
- if (data != null) {
- this.texture.LoadImage (data);
- this.texture.Apply (true, false);
- }
- }
- public void UpdateFrom (Texture2D input)
- {
- this.Init ();
- this.texture.SetPixels32 (input.GetPixels32 ());
- this.texture.Apply (true, false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment