Пример #1
0
        internal static Texture2D BuildPreviewTexture(UnityEngine.Object obj, int width, int height)
        {
            Texture2D previewTex = null;

            var sprite = SVGImporter.GetImportedSprite(obj);

            if (sprite != null)
            {
                var mat = SVGImporter.CreateSVGSpriteMaterial(sprite);
                previewTex = VectorUtils.RenderSpriteToTexture2D(sprite, width, height, mat, 4);
                Material.DestroyImmediate(mat);
            }
#if UNITY_2019_3_OR_NEWER
            else
            {
                Vector2[] vertices = null;
                UInt16[]  indices  = null;
                Vector2[] uvs      = null;
                Color[]   colors   = null;
                Vector2[] settings = null;
                Texture2D atlas    = null;
                Vector2   size     = Vector2.zero;
                if (InternalBridge.GetDataFromVectorImage(obj, ref vertices, ref indices, ref uvs, ref colors, ref settings, ref atlas, ref size))
                {
                    var mat = SVGImporter.CreateSVGSpriteMaterial(atlas != null);
                    previewTex = InternalBridge.RenderVectorImageToTexture2D(obj, width, height, mat, 4);
                    Material.DestroyImmediate(mat);
                }
            }
#endif
            return(previewTex);
        }
Пример #2
0
 public Texture2D GetReadableTexture2D()
 {
     if (m_ReadableTexture == null)
     {
         if (GetImporter().SvgType == SVGType.VectorSprite)
         {
             var sprite = GetSprite();
             var size   = ((Vector2)sprite.bounds.size) * sprite.pixelsPerUnit;
             m_ReadableTexture = VectorUtils.RenderSpriteToTexture2D(sprite, (int)size.x, (int)size.y, SVGImporter.CreateSVGSpriteMaterial(sprite), 4);
         }
         else
         {
             return(GetTexture2D());
         }
     }
     return(m_ReadableTexture);
 }