Implement.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. using UnityEngine.Profiling;
  3. public class Implement {
  4. private TextAsset _SVGFile;
  5. private Texture2D _texture;
  6. private readonly SVGGraphics _graphics;
  7. private SVGDocument _svgDocument;
  8. public Implement(TextAsset svgFile, ISVGDevice device) {
  9. _SVGFile = svgFile;
  10. _graphics = new SVGGraphics(device);
  11. }
  12. private void CreateEmptySVGDocument() {
  13. _svgDocument = new SVGDocument(_SVGFile.text, _graphics);
  14. }
  15. public void StartProcess() {
  16. Profiler.BeginSample("SVG.Implement.StartProcess[CreateEmptySVGDocument]");
  17. CreateEmptySVGDocument();
  18. Profiler.EndSample();
  19. Profiler.BeginSample("SVG.Implement.StartProcess[GetRootElement]");
  20. SVGSVGElement _rootSVGElement = _svgDocument.RootElement;
  21. Profiler.EndSample();
  22. Profiler.BeginSample("SVG.Implement.StartProcess[ClearCanvas]");
  23. _graphics.SetColor(Color.white);
  24. Profiler.EndSample();
  25. Profiler.BeginSample("SVG.Implement.StartProcess[RenderSVGElement]");
  26. _rootSVGElement.Render();
  27. Profiler.EndSample();
  28. Profiler.BeginSample("SVG.Implement.StartProcess[RenderGraphics]");
  29. _texture = _graphics.Render();
  30. Profiler.EndSample();
  31. }
  32. public void NewSVGFile(TextAsset svgFile) {
  33. _SVGFile = svgFile;
  34. }
  35. public Texture2D GetTexture() {
  36. if(_texture == null)
  37. return new Texture2D(0, 0, TextureFormat.ARGB32, false);
  38. return _texture;
  39. }
  40. }