Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
0
Question by AAcat · Aug 04, 2019 at 01:26 AM · textinterfaceretro

Custom text UI

I have this custom ASCII table that I want to use in a dialogue UI, for when characters are talking to each other. It's a .png image and each letter takes up 8x8 pixel spaces, so just set it as sprite (2D and UI) and put the sprite mode to multiple and split them all and set the Pixels Per Unit to 8. (its suppose to look like a retro UI for gameboy)

Now, is there any way I can set it all up so that each sprite is designated a letter so that I can put text in without having to create a tilemap of each dialogue that shows up? or will i have to painstakingly just make a tilemap of each dialogue. here is what im using: alt text

ascii.png (28.8 kB)
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

1 Reply

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

Answer by DCordoba · Aug 04, 2019 at 03:28 PM

you can easy search a font that match with console type but, to make it complex, I took the challenge to automate the creation of each letter on the UI

to set up this you need to:

  • create a prefab with a raw Image component

  • create a object in the canvas with the following script and a GridLayoutGroup component attached

  • fill the field CustomTexture with the sprite texture that you show there

  • fill the field LetterPrefab with the prefab that you created

the script component, required GridLayoutGroup on the same object:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 [RequireComponent(GridLayoutGroup)]
 public class CustomText : MonoBehaviour {
 
     public string text;
     public Texture CustomImage;
     public RawImage LetterPrefab;
     // Use this for initialization
     void Start () {
         foreach (char letter in text) {
             CreateLetter (letter);
         }
     }
 
     RawImage letterInstance;
     void CreateLetter(char ch){
         letterInstance = Instantiate (LetterPrefab, transform);
         letterInstance.texture = CustomImage;
         SetLetter(letterInstance, ch);
         letterInstance.uvRect = _uvRect;
     }
 
     GameObject Letter;
     Rect _uvRect = new Rect(0f,0f,.06f,.07f);
     void SetLetter(RawImage Img , char a){
         switch (a) {
         case ' ':
             _uvRect = SetRect (_uvRect,0);
             break;
         case '!':
             _uvRect = SetRect (_uvRect,1);
             break;
         case '"':
             _uvRect = SetRect (_uvRect,2);
             break;
         case '#':
             _uvRect = SetRect (_uvRect,3);
             break;
         case '$':
             _uvRect = SetRect (_uvRect,4);
             break;
         case '%':
             _uvRect = SetRect (_uvRect,5);
             break;
         case '&':
             _uvRect = SetRect (_uvRect,6);
             break;
         case '\'':
             _uvRect = SetRect (_uvRect,7);
             break;
         case '(':
             _uvRect = SetRect (_uvRect,8);
             break;
         case ')':
             _uvRect = SetRect (_uvRect,9);
             break;
         case '*':
             _uvRect = SetRect (_uvRect,10);
             break;
         case '+':
             _uvRect = SetRect (_uvRect,11);
             break;
         case ',':
             _uvRect = SetRect (_uvRect,12);
             break;
         case '-':
             _uvRect = SetRect (_uvRect,13);
             break;
         case '.':
             _uvRect = SetRect (_uvRect,14);
             break;
         case '/':
             _uvRect = SetRect (_uvRect,15);
             break;
         case '0':
             _uvRect = SetRect (_uvRect,16);
             break;
         case '1':
             _uvRect = SetRect (_uvRect,17);
             break;
         case '2':
             _uvRect = SetRect (_uvRect,18);
             break;
         case '3':
             _uvRect = SetRect (_uvRect,19);
             break;
         case '4':
             _uvRect = SetRect (_uvRect,20);
             break;
         case '5':
             _uvRect = SetRect (_uvRect,21);
             break;
         case '6':
             _uvRect = SetRect (_uvRect,22);
             break;
         case '7':
             _uvRect = SetRect (_uvRect,23);
             break;
         case '8':
             _uvRect = SetRect (_uvRect,24);
             break;
         case '9':
             _uvRect = SetRect (_uvRect,25);
             break;
         case ':':
             _uvRect = SetRect (_uvRect,26);
             break;
         case ';':
             _uvRect = SetRect (_uvRect,27);
             break;
         case '<':
             _uvRect = SetRect (_uvRect,28);
             break;
         case '=':
             _uvRect = SetRect (_uvRect,29);
             break;
         case '>':
             _uvRect = SetRect (_uvRect,30);
             break;
         case '?':
             _uvRect = SetRect (_uvRect,31);
             break;
         case '@':
             _uvRect = SetRect (_uvRect,32);
             break;
         case 'A':
             _uvRect = SetRect (_uvRect,33);
             break;
         case 'B':
             _uvRect = SetRect (_uvRect,34);
             break;
         case 'C':
             _uvRect = SetRect (_uvRect,35);
             break;
         case 'D':
             _uvRect = SetRect (_uvRect,36);
             break;
         case 'E':
             _uvRect = SetRect (_uvRect,37);
             break;
         case 'F':
             _uvRect = SetRect (_uvRect,38);
             break;
         case 'G':
             _uvRect = SetRect (_uvRect,39);
             break;
         case 'H':
             _uvRect = SetRect (_uvRect,40);
             break;
         case 'I':
             _uvRect = SetRect (_uvRect,41);
             break;
         case 'J':
             _uvRect = SetRect (_uvRect,42);
             break;
         case 'K':
             _uvRect = SetRect (_uvRect,43);
             break;
         case 'L':
             _uvRect = SetRect (_uvRect,44);
             break;
         case 'M':
             _uvRect = SetRect (_uvRect,45);
             break;
         case 'N':
             _uvRect = SetRect (_uvRect,46);
             break;
         case 'O':
             _uvRect = SetRect (_uvRect,47);
             break;
         case 'P':
             _uvRect = SetRect (_uvRect,48);
             break;
         case 'Q':
             _uvRect = SetRect (_uvRect,49);
             break;
         case 'R':
             _uvRect = SetRect (_uvRect,50);
             break;
         case 'S':
             _uvRect = SetRect (_uvRect,51);
             break;
         case 'T':
             _uvRect = SetRect (_uvRect,52);
             break;
         case 'U':
             _uvRect = SetRect (_uvRect,53);
             break;
         case 'V':
             _uvRect = SetRect (_uvRect,54);
             break;
         case 'W':
             _uvRect = SetRect (_uvRect,55);
             break;
         case 'X':
             _uvRect = SetRect (_uvRect,56);
             break;
         case 'Y':
             _uvRect = SetRect (_uvRect,57);
             break;
         case 'Z':
             _uvRect = SetRect (_uvRect,58);
             break;
         case '[':
             _uvRect = SetRect (_uvRect,59);
             break;
         case '\\':
             _uvRect = SetRect (_uvRect,60);
             break;
         case ']':
             _uvRect = SetRect (_uvRect,61);
             break;
         case '^':
             _uvRect = SetRect (_uvRect,62);
             break;
         case '_':
             _uvRect = SetRect (_uvRect,63);
             break;
         case '`':
             _uvRect = SetRect (_uvRect,64);
             break;
         case 'a':
             _uvRect = SetRect (_uvRect,65);
             break;
         case 'b':
             _uvRect = SetRect (_uvRect,66);
             break;
         case 'c':
             _uvRect = SetRect (_uvRect,67);
             break;
         case 'd':
             _uvRect = SetRect (_uvRect,68);
             break;
         case 'e':
             _uvRect = SetRect (_uvRect,69);
             break;
         case 'f':
             _uvRect = SetRect (_uvRect,70);
             break;
         case 'g':
             _uvRect = SetRect (_uvRect,71);
             break;
         case 'h':
             _uvRect = SetRect (_uvRect,72);
             break;
         case 'i':
             _uvRect = SetRect (_uvRect,73);
             break;
         case 'j':
             _uvRect = SetRect (_uvRect,74);
             break;
         case 'k':
             _uvRect = SetRect (_uvRect,75);
             break;
         case 'l':
             _uvRect = SetRect (_uvRect,76);
             break;
         case 'm':
             _uvRect = SetRect (_uvRect,77);
             break;
         case 'n':
             _uvRect = SetRect (_uvRect,78);
             break;
         case 'o':
             _uvRect = SetRect (_uvRect,79);
             break;
         case 'p':
             _uvRect = SetRect (_uvRect,80);
             break;
         case 'q':
             _uvRect = SetRect (_uvRect,81);
             break;
         case 'r':
             _uvRect = SetRect (_uvRect,82);
             break;
         case 's':
             _uvRect = SetRect (_uvRect,83);
             break;
         case 't':
             _uvRect = SetRect (_uvRect,84);
             break;
         case 'u':
             _uvRect = SetRect (_uvRect,85);
             break;
         case 'v':
             _uvRect = SetRect (_uvRect,86);
             break;
         case 'w':
             _uvRect = SetRect (_uvRect,87);
             break;
         case 'x':
             _uvRect = SetRect (_uvRect,88);
             break;
         case 'y':
             _uvRect = SetRect (_uvRect,89);
             break;
         case 'z':
             _uvRect = SetRect (_uvRect,90);
             break;
         case '{':
             _uvRect = SetRect (_uvRect,91);
             break;
         case '|':
             _uvRect = SetRect (_uvRect,92);
             break;
         case '}':
             _uvRect = SetRect (_uvRect,93);
             break;
         case '~':
             _uvRect = SetRect (_uvRect,94);
             break;
             //continue adding characters if you want, I stopped on 6 row, 13 column
         default:
             _uvRect = SetRect (_uvRect, 0);
             break;
         }
     }
 
     Rect SetRect(Rect rect, int charNum){
         int x = charNum % 16;
         int y = charNum / 16;
         rect.x =  (x)/16f;
         rect.y =  (13 - y)/14f ;
         return rect;
     }
 }

if you have any questions just ask.

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 AAcat · Aug 04, 2019 at 04:32 PM 0
Share

Aw this is dope, I'll check it out as soon as I can. Thanks

avatar image AAcat · Aug 04, 2019 at 09:17 PM 0
Share

I think i kinda understand this, but i dont know what you mean with the prefab stuff

avatar image AAcat · Aug 04, 2019 at 09:32 PM 0
Share

I kinda got it to work, but nothing shows up in the scene or game window. The game objects are being created, (for the word "Hello World!" 12 objects are created) and those letters are being assigned properly, by looking at each gameobjects raw image in the bottom window of the inspector. So I don't know why it's not showing.

avatar image AAcat · Aug 04, 2019 at 10:16 PM 0
Share

ok never $$anonymous$$d got it working, completely forgot to add the canvas component to the game object :v

avatar image DCordoba AAcat · Aug 05, 2019 at 06:44 AM 0
Share

sorry to come so late, you manage to resolve it alone

note for me next time, include a example scene

you can read how to use Camera.main.WorldToScreenPoint (3d_world_desired_comment position) to put the dialogues up each character.

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

115 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Pop up text from Floating text positioner interface c# 0 Answers

UI behavior on resolution change 1 Answer

TextMeshPro smallcaps option is converting "i" to "İ" not "I", why ? 1 Answer

TextMeshPro smallcaps option is converting "i" to "İ" not "I" 0 Answers

How do I make text selectable to highlight? 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