Guest User

Untitled

a guest
Mar 28th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. public class MeshPaintableSource : MonoBehaviour, IClientComponent
  2. {
  3.     //
  4.     // Fields
  5.     //
  6.     public int texWidth = 256;
  7.  
  8.     public Vector3 localRotation;
  9.  
  10.     public Vector3 localPosition;
  11.  
  12.     public Mesh collisionMesh;
  13.  
  14.     public GameObject sourceObject;
  15.  
  16.     [NonSerialized]
  17.     public Texture2D texture;
  18.  
  19.     public int texHeight = 128;
  20.  
  21.     public string replacementTextureName = "_DecalTexture";
  22.  
  23.     public float cameraFOV = 60;
  24.  
  25.     public float cameraDistance = 2;
  26.  
  27.     //
  28.     // Methods
  29.     //
  30.     public void Free ()
  31.     {
  32.         if (this.texture) {
  33.             Object.Destroy (this.texture);
  34.             this.texture = null;
  35.         }
  36.     }
  37.  
  38.     public void Init ()
  39.     {
  40.         if (this.texture) {
  41.             return;
  42.         }
  43.         this.texture = new Texture2D (this.texWidth, this.texHeight, TextureFormat.ARGB32, false);
  44.         this.texture.name = "MeshPaintableSource_" + base.gameObject.name;
  45.         this.texture.Clear (Color.clear);
  46.         MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock ();
  47.         materialPropertyBlock.SetTexture (this.replacementTextureName, this.texture);
  48.         Renderer[] componentsInChildren = base.transform.root.GetComponentsInChildren<Renderer> (true);
  49.         for (int i = 0; i < componentsInChildren.Length; i++) {
  50.             Renderer renderer = componentsInChildren [i];
  51.             renderer.SetPropertyBlock (materialPropertyBlock);
  52.         }
  53.     }
  54.  
  55.     public void Load (byte[] data)
  56.     {
  57.         this.Init ();
  58.         if (data != null) {
  59.             this.texture.LoadImage (data);
  60.             this.texture.Apply (true, false);
  61.         }
  62.     }
  63.  
  64.     public void UpdateFrom (Texture2D input)
  65.     {
  66.         this.Init ();
  67.         this.texture.SetPixels32 (input.GetPixels32 ());
  68.         this.texture.Apply (true, false);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment