VDSampler.js 637 B

123456789101112131415161718
  1. /*
  2. VertexDirt plug-in for Unity
  3. Copyright 2014-2015, Zoltan Farago, All rights reserved.
  4. */
  5. @script ExecuteInEditMode()
  6. function OnPostRender () {
  7. var tex = new Texture2D (VertexDirt.sampleWidth, VertexDirt.sampleHeight, TextureFormat.RGB24, true);
  8. tex.ReadPixels (Rect(0, 0, VertexDirt.sampleWidth, VertexDirt.sampleHeight), 0, 0);
  9. //tex.Apply();
  10. var lum : Color32[] = tex.GetPixels32(tex.mipmapCount-1);
  11. //var bytes = tex.EncodeToPNG();
  12. //System.IO.File.WriteAllBytes(Application.dataPath + "/../SavedScreen"+VertexDirt.vertexSample.index+".png", bytes);
  13. DestroyImmediate (tex);
  14. VertexDirt.SetColorSample(lum[0]);
  15. }