TextureResource.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using UnityEngine;
  3. public class TextureResource
  4. {
  5. public TextureResource(int width, int height, TextureFormat format, Rect[] uvRects, byte[] data)
  6. {
  7. this.width = width;
  8. this.height = height;
  9. this.format = format;
  10. this.uvRects = null;
  11. if (uvRects != null && 0 < uvRects.Length)
  12. {
  13. this.uvRects = new Rect[uvRects.Length];
  14. Array.Copy(uvRects, this.uvRects, uvRects.Length);
  15. }
  16. this.data = data;
  17. }
  18. public Texture2D CreateTexture2D()
  19. {
  20. if (this.format == TextureFormat.DXT1 || this.format == TextureFormat.DXT5)
  21. {
  22. Texture2D texture2D = new Texture2D(this.width, this.height, this.format, false);
  23. texture2D.LoadRawTextureData(this.data);
  24. texture2D.Apply();
  25. return texture2D;
  26. }
  27. if (this.format == TextureFormat.ARGB32 || this.format == TextureFormat.RGB24)
  28. {
  29. Texture2D texture2D2 = new Texture2D(2, 2, this.format, false);
  30. texture2D2.LoadImage(this.data);
  31. return texture2D2;
  32. }
  33. Debug.LogError("format:" + this.format.ToString() + "は対応していません");
  34. return null;
  35. }
  36. public readonly int width;
  37. public readonly int height;
  38. public readonly TextureFormat format;
  39. public readonly Rect[] uvRects;
  40. public readonly byte[] data;
  41. }