Last active
October 24, 2018 14:47
-
-
Save deathponta/3afc4fac1428682fc7e430f014e78993 to your computer and use it in GitHub Desktop.
端末言語によって日本語・英語を切り替える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
端末言語によって日本語・英語を切り替える | |
■ 使い方 | |
Image または Text コンポーネントが割あたっているゲームオブジェクトにD&Dして、 | |
日本語&英語 テキスト・画像 を割り当てればOKです。 | |
動的に変更されているテキストに関しては、別途処理が必要ですが、基本的にこのクラス内と同じ処理を行えばOKです。 | |
*/ | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class mbLocalize : MonoBehaviour { | |
void Start () { | |
SetLanguageUI(); | |
} | |
[SerializeField,Header("■ 日本語&英語用のSpriteを入れてください。")] | |
Sprite m_image_jp; | |
[SerializeField] | |
Sprite m_image_en; | |
[SerializeField, Header( "■ 日本語&英語用のテキストを入れてください。" )] | |
string m_text_jp; | |
[SerializeField] | |
string m_text_en; | |
void SetLanguageUI() { | |
Image img = GetComponent<Image>(); | |
Text txt = GetComponent<Text>(); | |
SystemLanguage sl = Application.systemLanguage; | |
switch (sl) { | |
case SystemLanguage.Japanese: | |
if (img) img.sprite = m_image_jp; | |
if (txt) txt.text = m_text_jp; | |
break; | |
case SystemLanguage.English: | |
if (img) img.sprite = m_image_en; | |
if (txt) txt.text = m_text_en; | |
break; | |
default:// デフォルトでは英語に | |
if (img) img.sprite = m_image_en; | |
if (txt) txt.text = m_text_en; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment