Created
March 14, 2015 05:14
-
-
Save westhillapps/03665e001be9b7344c80 to your computer and use it in GitHub Desktop.
uGUIでビットマップフォントを適用したText生成用Editor拡張。BitmapFontScalerと併せて使う。
This file contains hidden or 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
using UnityEngine; | |
using UnityEngine.UI; | |
using UnityEditor; | |
public class BitmapFontTextCreator | |
{ | |
// デフォルトカスタムフォントパス | |
const string DEFAULT_FONT_PATH = "Assets/CustomFont/customfont.fontsettings"; | |
// デフォルトフォントカラー | |
static readonly Color32 DEFAULT_COLOR = new Color32(50, 50, 50, 255); | |
[MenuItem("GameObject/UI/Bitmap Font Text", false, 2003)] | |
static void CreateBitmapFontText () | |
{ | |
if (Selection.activeGameObject == null) { | |
Debug.LogWarning("Please select the GameObject on hierarchy."); | |
return; | |
} | |
if (Selection.activeGameObject.GetComponentInParent<Canvas>() == null) { | |
Debug.LogWarning("Please select the GameObject under the ui canvas."); | |
return; | |
} | |
Transform parent = Selection.activeGameObject.transform; | |
// Text生成 | |
var go = new GameObject("BitmapFontText"); | |
go.transform.SetParent(parent, false); | |
var uiText = go.AddComponent<Text>(); | |
uiText.fontSize = 0; | |
uiText.color = DEFAULT_COLOR; | |
uiText.text = "New Bitmap Font Text"; | |
// BitmapFontScaler追加 | |
go.AddComponent<BitmapFontScaler>(); | |
// デフォルトのカスタムフォントを設定 | |
var font = Resources.LoadAssetAtPath<Font>(DEFAULT_FONT_PATH); | |
if (font != null) { | |
uiText.font = font; | |
Resources.UnloadAsset(font); | |
} | |
} | |
[MenuItem("GameObject/UI/Bitmap Font Text", true)] | |
static bool CreateBitmapFontTextEnable () | |
{ | |
if (Selection.activeGameObject == null || Selection.activeGameObject.GetComponentInParent<Canvas>() == null) { | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment