I'm creating a Visual Novel in Unity and i'd like to give the player the option to import his own fonts into the game, my initial idea was to explain to the player that he needs to put the font file in a specific folder and i would scan the fonts in that folder using System.IO.DirectoryInfo.GetFiles();, though i do manage to access those files, i still haven't figured out how to deserialize those font files(.ttf) into Unity's Font type. The binary formatter throws a exception when trying to serialize/deserialize Unity's Font Type and as far as i searched Unity does not have a native API to do that, Unity imports fonts using the class TrueTypeFontImporter that's only implemented in the Editor, so i cannot access that class at runtime.
Anybody got any ideas on how to solve this?
The answer may be too late, but for late-comers.
You can load dynamic .ttf file by
Font font = new Font ("path_to_ttf_file");
As for static .ttf file, I dont know.
Related
I would like to import a file ".step" to use it with unity 2018.3.1f1 but I don't know how to do it
I didn't found any topic.
Any one could help me please ?
.step is a cad file, right? This isn't supported by unity out of the box. You may need to buy an asset store plugin to open cad files, or roll your own importer. You would need to read up on the file format and build a new mesh based on interpretation of the file format.
Documentation on building a mesh from scratch: https://docs.unity3d.com/Manual/GeneratingMeshGeometryProcedurally.html
In Windows, using C#, one can check if a specific font style is available, but this does not tell if it is generated by windows from a Regular style (e.g. bold or italic can be generated like that), or there is a separate font file. Like for arial font, we have separate files: arial.ttf, arialbd.ttf, ariali.ttf, ...
My problem is, that we use a 3-rd party pdf export library, which seems to work ok with styles only, when there are such additional files for these styles. If they are not available, there is only Regular style from this one file present. To fix this, I need/would prefer to know, if a style has a separate file or not.
Windows has two classes: FontFamily, in System.Drawing and System.Windows.Media, but neither of them seem to answer this question, only if style is available. Or am I missing this functionality? Is there a way to determine such file?
I was thinking to just search C:\Windows\fonts, but is this always the only location of system fonts in recent windows versions?
Thank you!
I need a c# script for unity that can read the EXIF lat/long data from a photo. i would like to place a posTransform at that location. not sure if this is possible within Unity. i would like to load my images into unity and have a script read the EXIF: 1-GPS lat/long, 2-rotation, 3-timestamp from photographs. i haven't found any info that says this can be done within unity, however, i've read about exiflib github project and other ways outside of unity.
THANKS in advance for help
I maintain a project for extracting metadata from images that will give you what you need.
https://github.com/drewnoakes/metadata-extractor-dotnet
The library supports .NET 3.5 so should work under Unity, though I haven't tested it before.
With it, you would write:
var directories = ImageMetadataReader.ReadMetadata(filePath);
var gpsDirectory = directories.OfType<GpsDirectory>().FirstOrDefault();
if (gpsDirectory != null)
{
var location = gpsDirectory.GetGeoLocation();
Console.WriteLine($"Photo was taken at {location.Latitude},{location.Longitude}");
}
The answer from Drew Noakes doesn't work because it has dependencies on .NET that Unity doesn't support.
In my opinion, the best option right now, after a few days of research, is this project:
https://www.codeproject.com/Articles/5251929/CompactExifLib-Access-to-EXIF-Tags-in-JPEG-TIFF-an
This is a simple one-file project that you can drag in your unity project and that has no external dependencies. And it can read and update EXIF tags for JPG, PNG and TIFF files.
I'm working on an application that uses the XNA framework to do it's 3D rendering. I now want to load a texture from file. I've found two methods so far:
Texture2D.FromStream(GraphicsDevice, Stream) The problem with this approach is that it only loads gif, png and jpg and I also need support for tga images.
Create a ContentManager object. The problem with this approach is that it seems like all the textures need to be statically added to the project, from the documentation: "Before a ContentManager can load an asset, you need to add the asset to your game project". The program in question is a level editor and which textures are needed isn't known in advance.
Is there any other easy way to load the texture, I'm thinking about using some other class to load the image (although I don't know which, I'm not very familiar with C#) and then perhaps use the Texture2D.SetData method?
Is there any other easy way to achieve what I'm trying to achieve?
There are a few ways to achieve what you want:
You could invoke the content pipeline from within your editor, dynamically creating your content project. How to do this is described in the WinForms Series 2 Sample. This is probably the "best" way, because it allows you to keep using the content pipeline.
You could, as you say, decode the TGA file yourself and use SetData. There are lots of results for C# TGA readers on Google. This is the first one.
I've used Texture2D.FromFile(device, path) before, and it works well. However occasionally I'll encounter problems and will also have to specify TextureCreationParameters and pass them in. Keep in mind that you'll need to dispose the loaded Texture2D manually.
I am planning on building a 2D game library for XNA, and one of the components I want to include is a simple text drawer for debug purposes. Now, to draw text with SpriteBatch you need a .spritefont file, which is an xml format file, and these seem to need to compile into a separate folder. I would prefer not to have to copy that around with the dll, so here is my question:
can i build some sort of text renderer for XNA that
A: does not require me to carry around external files with the dll (if you can embed the sprite font into a dll then that works) and
B: does not force me to rewrite a fair amount of underlying (is it managed directx? a different part of xna?) code that makes the SpriteBatch.DrawString code work.
Could you not just require that a SpriteFont be passed into your library, so that whoever is using the library has to supply that component? That would seem to be the best solution, since then they could use whatever font they wanted. Or you could write in a component that generates the spritefont xml file based on a given font name, because it's not all that complicated of a file. Disregard. I forgot that XNA compiles its resources.
You can precompile the project and then grab the xnb file for the spritefont. Then add the file to the project Content folder as a content file. It should then be deployed together with the library. However u will need to build a separate xnb file for each platform you wish to support (xbox360, windows, zune) and deploy the correct file.
Or why don't u just create a XNA Content Library project?