The example explained in this chapter is implemented in the plane scene. The example shows a simple plane object with an attached texture, generated from an SVG file. The example has been realized following these steps:
Create a new Unity project, AmanithSVG can be used for 2D and 3D projects; in this case we select the 2D setup.
Select the Game view, and make sure that “Scale” slider is completely on the left (i.e.
scale = 1x); switch back to the Scene view.
|Set a unitary scene scale|
Because the project is a new one, it is required to copy AmanithSVG binding for Unity (
Scripts folders) inside the new project’s
Assets/SVGAssets folder; so that resources (e.g. config file, fonts, SVG files), native AmanithSVG plugins and its C# interface will be available for the project.
|The minimal project layout after copying all needed files|
Set a full white
Ambient Color light (menu:
Environment Lighting), in order to display SVG files with their original colors (in older Unity version the option was accessible through the
Lighting Settings menu).
|Ensure a pure white ambient light|
Create a plane object (menu:
3D Object →
Plane) and make sure that the main camera is pointing it. To do so, place the plane object at
(0, 0, 0) and the camera object at
(0, 10, 0) with a rotation of
(90, 0, -180).
|The plane gameobject|
Select the plane object and attach the “SVG Texture Behaviour” script (menu
Scripts subsection). This script is really simple, it shows a possible usage of AmanithSVG library. In the detail the script:
Creates a drawing surface with the same dimensions
Creates and load the SVG document
Renders the SVG document to the drawing surface
Creates the texture with the specified dimensions
Copies the drawing surface pixels to the texture
Destroys SVG document and drawing surface
Returns the created texture
girl.svg file (located in
Assets/SVGAssets/SVGFiles) and drag&drop it from the Project window to the
SVG File property field of the script. Let other properties unchanged to their default values (
512 x 512 pixels texture dimensions, white background clear color).
Click play and see the result.
|This is the result after pressing Play|
AmanithSVG binding for Unity also includes another script called
SVGTextureAtlasBehaviour; in order to test it, stop the current execution and perform the following steps:
Select the plane and remove the attached
SVGTextureAtlasBehaviour script component: this script allows you to specify four different SVG files to be rendered on a single texture
Drag&drop four SVG files from the Project window to
1,2,3,4 property fields of the script.
As before, click play and see the result in the Game window.
|Four SVG files rendered on a single texture|
Thanks to “Ror362” for its great girl svg. Original source: https://www.deviantart.com/ror362/art/Yayoi-iM-S-397886689