Major Softwares

  INDEX PAGE

  1. 簡介
  2. Java, Android和LibGDX好書推介
  3. Java, Android和LibGDX要學的知識
  4. 用Windows寫Java程式
  5. 用Eclipse寫Java程式
  6. 用Eclipse寫Android程式
  7. 用Eclipse寫LibGDX程式
  8. Standard Java Naming Conventions
  9. System.out.println()的用法和意思
  10. Where is main() method in Android?

LibGDX - Splash & Menu Screen

  1. LibGDX: World, Texture, Background, Camera, Viewport, Screen & OpenGL
  2. LibGDX: Texture, TextureRegion, SpriteBatch & Sprite
  3. UML(Unified Modeling Language): Class Diagram
  4. Type Casting, Upcasting & Downcasting
  5. @Override的用法和意思
  6. LibGDX: Scene2d & Graphical User Interface(GUI)
  7. LibGDX: Splash Screen
  8. LibGDX: Texture Packer
  9. LibGDX: BitmapFonts, JSON & Skin
  10. Android: R.java File
  11. Android: onClick事件的5種實現方式
  12. LibGDX: Game Menu Screen
  13. LibGDX: Advanced Game Menu Screen (using Abstract Screen)
  14. LibGDX: Disposable Interface
  15. Java & LibGDX: super keyword
  16. LibGDX: Advanced Game Menu Screen (using AssetManager)
  17. Java: Array, Arrays, List, ArrayList & LibGDX: Array
  18. LibGDX: File I/O (Preferences)
  19. LibGDX: Game Level Selection Screen
  20. LibGDX: Advanced Game Level Selection Screen (using AssetManager)

LibGDX - Tiled 2D Platform Game

  1. LibGDX: Lifecylce (Render() Method)
  2. LibGDX: Delta Time
  3. LibGDX: Animation & Spritesheet
  4. LibGDX: Keyboard, Mouse & Touch Screen Control
  5. Input Control (Polling VS Event Driven Input)
  6. LibGDX: Tiled (Background and Foreground)
  7. LibGDX: Jumping Action
  8. LibGDX: Tiled (Collision Detection)
  9. LibGDX: Tiled (Bullet Class)
  10. LibGDX: Audio (Sound & Music)
  11. LibGDX: Tiled (Scrollable Background with Camera & HUD)
  12. LibGDX: WorldController & WorldRenderer Class

LibGDX/Java - Card Game No.1 - Blackjack

  1. LibGDX: Install & Setup Android Studio IDE
  2. LibGDX: Use Android Studio to Run Java Hello World
  3. LibGDX: Use Android Studio to Run LibGDX Hello World
  4. Adobe Illustrator: Basic Components Part 1
  5. Adobe Illustrator: Basic Components Part 2
  6. Adobe Illustrator: BlackJack Table & Cards
  7. LibGDX: Blackjack Animation
  8. LibGDX: Interpolation
  9. Java: toString() Method
  10. Java: Blackjack Shuffle Methods
  11. LibGDX: Blackjack Shuffle Method
  12. Java: Blackjack Card Game

LibGDX - Others

  1. Making and Displaying App Icon
  2. LibGDX: Displaying Traditional and Simplified Chinese Characters
  3. LibGDX: Handling Different Screen Resolutions

Unity Game Engine & C#

  1. Visual Studio: C# Hello World
  2. Unity: C# Hello World
  3. Unity: Handling Different Screen Resolutions
  4. Unity: Life Cycle
  5. Unity: StartCoroutine, StopCoroutine, IEnumerator & Yield
  6. Unity: Splash Screen
  7. Unity: Fonts, Traditional and Simplified Chinese Characters
  8. Unity: GameObject, Class Object, new & Instantiate
  9. Unity: Start Screen with Glowing Animated Button
  10. Unity: C# Get & Set Modifier
  11. Unity: Delegates & Events
  12. Unity: File I/O, Read & Write Text File & PlayerPrefs
  13. Unity: Game Level Selection Screen
  14. Unity: Game Menu Screen & ScreenManager
  15. Unity: Encrypt and Decrypt Text File
  16. Unity: Options Menu Screen
  17. Unity: Convert Numbers Image to Custom Font

Unity - Card Game No.1 - Blackjack

  1. Unity: Blackjack Card Game - Part 1 (Full Game)
  2. Unity: Blackjack Card Game - Part 2
  3. Unity: Blackjack Card Game - Part 3
  4. Unity: Blackjack Card Game - Part 4
  5. Unity: Blackjack Card Game - Part 5
  6. Unity: Blackjack Card Game - Part 6
  7. Unity: Blackjack Card Game - Part 7

以下是預告-Coming soon!


Secret Weapon No.1

  1. Unity: Card Game No.2

Advanced Programming

  1. Unity: GPS Programming
  2. Unity: User Login System
  3. Unity: Augmented Reality (AR)

Secret Weapon No.2

  1. Unity: GPS & AR Application

第64節 - Unity: Fonts, Traditional and Simplified Chinese Characters

這一節我會介紹Unity: Fonts, Traditional and Simplified Chinese Characters,則如何在Unity上顯示英文、繁體和簡體中文字。主要介紹以下內容:

1: Display Text Using Default Font (Arial) in Inspector

2: Display Text Using Default Font (Arial) in C# Script

3: Display Text Using Custom Font in Inspector

4: Display Text Using Custom Font in C# Script

1.0 Display Text Using Default Font (Arial) in Inspector

首先,第一個問題是Unity預設字體(Default Font)是Arial,但是我們可以成功顯示所有英文、繁體和簡體中文字,這是不是代表Arial字體支援英文、繁體和簡體中文字?

答案當然不是,Arial字體只支援英文字體和有關符號,當遇到不支援的字體時,電腦(例如: Windows 10)就會自動選擇內置的字體,智能電話一樣,當遇到不支援的字體時,智能電話(例如: 我的智能電話是Samsung Galaxy S6 Edge)就會自動選擇內置的字體。

1: Windows 10預設繁體和簡體中文字體是PMingLiU(新世名體)

2: Samsung Galaxy S6 Edge預設繁體和簡體中文字體是Noto Sans TC和Noto Sans SC

注意: 不同Windows版本和智能電話型號的預設字體會有所不同。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. Windows 10預設英文字體是Segoe UI。

  2. Windows 10預設繁體和簡體字體是PMingLiU(新世名體)。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 在Windows 10左下⻆選擇Run。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 輸入regedit。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 選擇以上檔案。

  2. Windows 10預設繁體和簡體字體是PMingLiU(新世名體)。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. Samsung Galaxy S6 Edge預設英文字體是Noto Sans。

  2. Samsung Galaxy S6 Edge預設繁體和簡體字體是Noto Sans TC和Noto Sans SC。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 大家可在Google Play下載任何File Manager App。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 在system> fonts內就可以找到Noto Sans TC字體。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 在system> fonts內就可以找到Noto Sans SC字體。

1.3 Display Text Using Default Font (Arial) in Inspector

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 建立一個新Project 。

  2. 建立一個新的Canvas Text - Text,再選擇Canvas。

  3. 在Text內輸入Happy New Year (Arial)。

  4. 設定Font = Arial。

  5. 設定Font Size = 100。

  6. 設定Color = Red。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 建立一個新的Canvas Text - Text(1),再選擇Text(1)。

  2. 在Text內輸入新年快樂、新年快乐 (Arial)。

  3. 設定Font = Arial。

  4. 設定Font Size = 100。

  5. 設定Color = Yellow。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 選擇File > Build Settings 。

  2. 選擇Android。

  3. 選擇Build。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 當Build完成後,apk檔案就會建立,檔案大小是大約19M。

    注意: 因為Arial字體都是在Android OS內內置,所以Arial字體是不須包括在apk檔案內。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 當Build完成後,apk檔案就會建立,檔案大小是大約19M。

    注意: 因為Arial字體都是在Android OS內內置,所以Arial字體不須包括在apk檔案內。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 在system> fonts內就可以找到Arial字體。

1.4 Result

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. Unity Console會選舉Windows 10內的Arial字體。

  2. Unity Console會選舉Windows 10預設繁體和簡體字體是PMingLiU(新世名體)。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 如在File > Build Settings選擇Android,Unity Android (例如: Samsung Galaxy S6 Edge)就會自動選擇內置的Arial字體。

  2. Unity Android (例如:Samsung Galaxy S6 Edge)就會自動選擇內置的Noto Sans TC字體和Noto Sans SC字體。

2.0 Display Text Using Default Font (Arial) in C# Script

以下會介紹如何在C# Script內顯示預設的英文、繁體和簡體字體,如下圖:

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 建立一個新Project 。

  2. 建立一個新的Canvas Text - Text,再選擇Canvas。

  3. 設定Render Mode = Screen Space - Camera。

  4. 把Main Camera拖放到Render Camera內。

  5. 設定UI Scale Mode = Scale With Screen Size。

  6. 設定Reference Resolution = 800 x 600和平Screen Match Mode = Expand。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 選擇Text。

  2. 在Text內輸入hkprogram.com。

  3. 設定Font = Arial,Font Size = 50。

  4. 把有關的C# Script拖放到Text內,則Add Component。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 建立一個Text Reference - textRef。

  2. 用gameObject.GetComponent<Text>()方法把Text的Component存入textRef內。

  3. 設定textRef的顏色 。

    注意: 設定顏可以用以上兩種方法。

  4. 設定textRef的內容。

3.2 Result

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. textRef的內容會由hkprogram.com轉為Hello World!。

  2. textRef的顏色會轉為紅色。

3.0 Display Text Using Custom Font in Inspector

以下會介紹如何在Inspector內加入自選的英文、繁體和簡體字體,如下圖:

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 在Windows > Fonts內選擇KAIU字體。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 在Assests區域內加入KAIU字體。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 建立一個新Project 。

  2. 建立一個新的Canvas Text - Text,再選擇Canvas。

  3. 在Text內輸入Happy New Year (Arial)。

  4. 設定Font = Arial。

  5. 設定Font Size = 100。

  6. 設定Color = Red。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 建立一個新的Canvas Text - Text(1),再選擇Text(1)。

  2. 在Text內輸入新年快樂、新年快乐 (KAIU)。

  3. 把KAIU字體拖放到Font內。

  4. 設定Font Size = 100。

  5. 設定Color = Yellow。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 選擇File > Build Settings 。

  2. 選擇Android。

  3. 選擇Build。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 大家可以在Unity >MyDemo64_2 > Assets內找到KAIU.ttf檔案,檔案大小是大約5M。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 當Build完成後,apk檔案就會建立,檔案大小是大約22M。

    注意: 當KAIU字體拖放到Font內,再當Build完成後,KAIU字體就會儲存在apk檔案內,所以大家要留意檔案的大小。

2.2 Result

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. Unity Console會選舉Windows 10內的Arial字體。

  2. Unity Console會選舉Windows 10預設繁體和簡體字體是PMingLiU(新世名體)。

  3. Unity Console會選舉apk檔案內的KAIU字體。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 如在File > Build Settings選擇Android,Unity Android(例如: Samsung Galaxy S6 Edge)就會自動選擇內置的Arial字體。

  2. Unity Android (例如: Samsung Galaxy S6 Edge)就會自動選擇內置的Noto Sans TC字體和Noto Sans SC字體。

  3. Unity Android會選舉apk檔案內的KAIU字體。

4.0 Display Text Using Custom Font in C# Script

以下會介紹如何在C# Script加入自選的英文、繁體和簡體字體,如下圖:

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 建立一個新Project 。

  2. 建立一個新的Canvas Text - Text,再選擇Camera。

  3. 設定Camera Orthographic Size = 600/2 = 300。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 建立一個新的Canvas Text - Text,再選擇Canvas。

  2. 設定Render Mode = Screen Space - Camera。

  3. 把Main Camera拖放到Render Camera內。

  4. 設定UI Scale Mode = Scale With Screen Size。

  5. 設定Reference Resolution = 800 x 600和平Screen Match Mode = Expand。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 選擇Text。

  2. 在Text內輸入hkprogram.com。

  3. 設定Font = Arial,Font Size = 50。

  4. 把有關的C# Script拖放到Text內,則Add Component,再把OLDENGL字體拖放到My New Font內。

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. 建立一個Text Reference - textRef和Font Reference - myNewFont。

  2. 用gameObject.GetComponent<Text>()方法把Text的Component存入textRef內。

  3. 設定textRef的顏色 。

    注意: 設定顏可以用以上兩種方法。

  4. 設定textRef的fontSize = 50。

  5. 設定textRef的font = myNewFont。

  6. 設定textRef的內容。

4.2 Result

Unity: Fonts, Traditional and Simplified Chinese Characters
  1. textRef的Font由Arial轉為OLDENGL。

  2. textRef的Font Size = 50。

  3. textRef的顏色會轉為紅色。

  4. textRef的內容會由hkprogram.com轉為Hello World!。