Invoke.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections;
  2. using System.Diagnostics;
  3. using UnityEngine;
  4. [RequireComponent(typeof(Renderer))]
  5. [DisallowMultipleComponent()]
  6. public class Invoke : MonoBehaviour {
  7. public TextAsset SVGFile = null;
  8. [Tooltip("Use a faster rendering approach that takes notably more memory.")]
  9. public bool fastRenderer = false;
  10. [Space(15)]
  11. public TextureWrapMode wrapMode = TextureWrapMode.Clamp;
  12. public FilterMode filterMode = FilterMode.Trilinear;
  13. [Range(0, 9)]
  14. public int anisoLevel = 9;
  15. private void Start() {
  16. //yield return new WaitForSeconds(0.1f);
  17. if(SVGFile != null) {
  18. Stopwatch w = new Stopwatch();
  19. w.Reset();
  20. w.Start();
  21. ISVGDevice device;
  22. if(fastRenderer)
  23. device = new SVGDeviceFast();
  24. else
  25. device = new SVGDeviceSmall();
  26. var implement = new Implement(SVGFile, device);
  27. w.Stop();
  28. long c = w.ElapsedMilliseconds;
  29. w.Reset();
  30. w.Start();
  31. implement.StartProcess();
  32. w.Stop();
  33. long p = w.ElapsedMilliseconds;
  34. w.Reset();
  35. w.Start();
  36. var myRenderer = GetComponent<Renderer>();
  37. var result = implement.GetTexture();
  38. result.wrapMode = wrapMode;
  39. result.filterMode = filterMode;
  40. result.anisoLevel = anisoLevel;
  41. myRenderer.material.mainTexture = result;
  42. w.Stop();
  43. long r = w.ElapsedMilliseconds;
  44. UnityEngine.Debug.LogFormat("Construction: {0} ms, Processing: {1} ms, Rendering: {2} ms", c, p, r);
  45. }
  46. }
  47. }