SVGDeviceFast.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEngine;
  2. public class SVGDeviceFast : ISVGDevice {
  3. private Texture2D _texture;
  4. private int _width;
  5. private int _height;
  6. public int Width { get { return _width; } }
  7. public int Height { get { return _height; } }
  8. private Color _color = Color.white;
  9. private Color[] pixels;
  10. public void SetDevice(int width, int height) {
  11. _width = width;
  12. _height = height;
  13. if(pixels == null || _width != width || _height != height)
  14. pixels = new Color[_width * _height];
  15. }
  16. public void SetPixel(int x, int y) {
  17. if((x >= 0) && (x < _width) && (y >= 0) && (y < _height))
  18. pixels[y * _height + (_width - x) - 1] = _color;
  19. }
  20. public Color GetPixel(int x, int y) {
  21. return pixels[y * _height + x];
  22. }
  23. public void SetColor(Color color) {
  24. _color = color;
  25. }
  26. public Texture2D Render() {
  27. if(_texture == null) {
  28. _texture = new Texture2D(_width, _height, TextureFormat.RGB24, false);
  29. _texture.hideFlags = HideFlags.HideAndDontSave;
  30. }
  31. _texture.SetPixels(pixels);
  32. _texture.Apply();
  33. return _texture;
  34. }
  35. }