Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by reinher · Feb 12, 2013 at 01:14 AM · fontunity4gui-textbitmap

Edit generated BitmapFont from Unity 4 for use in GUI

So I have created an editable copy of a Font in Unity 4, so that I can use multicolored fonts, textshadows, strokes etc. for GUI Controls.

Problem: The GUI-Text shader (and other Shaders that I found on the Wiki) doesnt seem to render any colorinformation given by the .png with the bitmap font. So if I make a red stroke around the font, the font just gets thicker, but stroke and font have the same color.

I didnt use a dynamic font, I used the GUI-Text shader, and GUI-Texture-Type for the bitmap image of the font. I might be just plain stupid, but I cant find any tutorials or walkthroughs or the like for this kind of stuff... so I would be glad if somone with any experience on this issue could help me please.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Graham-Dunnett · Feb 12, 2013 at 02:21 PM

ASCII and Unicode fonts in Unity render out the glyphs to a texture. This texture is greyscale to save memory space. If you want a coloured glyphs, where, for example, each glyph is a different colour, you might want to use the almost completely undocumented "custom font". In the Project window use Create->Custom Font. The inspector gives you a whole load of options, which basically ask you to say how the glyphs are arranged in your texture. See http://answers.unity3d.com/questions/355953/custom-font-completely-broken-in-unity-4.html for advice on this. It's non-trivial.

To help as much as I can, here is a font texture. It's colored numbers on a grid, with each number 64x64 pixels. Get that into Unity, and then make a material with it. Create a custom font, and then apply the values you see in the inspector screenshot. That should get you the first 4 glyphs rendering correctly. Understanding the UV and Vert data takes a bit getting your read around. It seems to help mentally if you flip the font texture so it's upside down. (Don't do this in Photoshop, just hold the inverted texture in your head.) The UVs are then the coordinates of the corners of each of these 4x4 tiles. Note how the zero glyph in this vertically flipped mental image of the texture starts at V=0.75 and ends 0.25 later at V=1. The U/X coordinate and width works how you expect/want it to. For the pixel rectangle, the height has to be -64, but I can't figure that out just yet. For the next row of glyphs, from 4 to 7, the UV.y will be 0.5.

The other thing that cuaght me out when I had a quick play is the Index in the array of Character Rects is zero based and not the ascii char of the character. So, in my programmer artwork example (ascii chars 48 onwards) I have the Ascii start offset in the font set to 48, and then the indices are zero-based.

Will try and get some proper docs written.

alt textalt text


numbers.png (29.1 kB)
ss.png (80.4 kB)
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Graham-Dunnett ♦♦ · Feb 12, 2013 at 03:06 PM 0
Share

Please accept this answer if it works for you

avatar image reinher · Feb 12, 2013 at 04:57 PM 0
Share

Thanks for the detailed information, really appreciate it. I thought I could get around the custom font stuff, because I find it rather tedious...

And I dont get the point of the "make editable copy" function in Unity 4, when it doesnt really work (only managed to get it to work with GUI-text object and not any GUIControls). So if I want a text-shadow or stroke or whatever on any GUI-Controls I HAVE to make a Custom font? Or does it than still only work with GUI-Text and not with other GUIcontrols? welcome to 2013...

avatar image Graham-Dunnett ♦♦ · Feb 12, 2013 at 10:25 PM 0
Share

When used with a font, "make editable copy" will give you a png, material and the font settings. I guess an editor script can copy the font settings over into a custom font using Font.characterInfo. If you then color the png and make a suitable shader, I think you'd get what you want. Yes, it's not easy. :-(

avatar image fondemzel · Dec 16, 2013 at 11:20 AM 0
Share

Graham Dunnett Thanks a lot! Very helpful information.

avatar image fondemzel · Dec 16, 2013 at 11:20 AM 0
Share

Graham Dunnett Thanks a lot! Very helpful information.

avatar image
1

Answer by Graham-Dunnett · Feb 12, 2013 at 10:28 PM

 #pragma strict

 // copy glyph data from MyFont.ttf into a custom font called f2
 // 
 @MenuItem ("Font/doit")
 static function Doit() {
     var f1 : Font = AssetDatabase.LoadAssetAtPath("Assets/MyFont.ttf", Font);
     Debug.Log(f1.characterInfo.length);
     
     var f2 : Font = AssetDatabase.LoadAssetAtPath("Assets/f2.fontsettings", Font);
     Debug.Log(f2.characterInfo.length);
     
     var myCI : CharacterInfo[] = new CharacterInfo[f1.characterInfo.length];
     for (var i = 0; i < 95; i++){
         myCI[i] = f1.characterInfo[i];
     }
     f2.characterInfo = myCI;
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image reinher · Feb 13, 2013 at 04:59 PM 0
Share

Thanks again! ...why does it have to be that complicated -.-

avatar image Essential · May 22, 2013 at 10:50 PM 0
Share

I'm trying to figure out what this script does. Is it getting the rect data from a font and applying it to one of Unity 4's weird fonts…?

avatar image
0

Answer by FuZZbaLL_b · Mar 23, 2014 at 08:13 AM

In Unity 4.2 i just created an editable copy of the font, changed the PNG to have coloured text and edited the material of this custom font to use the 'Unlit/Transparent' shader. And now i have coloured text.

alt text

alt text


setshader.png (12.6 kB)
result.png (51.5 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Text "Best Fit" is not working for Bitmap fonts? 1 Answer

How to create gradient text 2 Answers

How do you increase GUI-Text font size ??? 1 Answer

Custom Fonts... Missing on friend's computer 1 Answer

Unity custom font shader 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges