Created
January 6, 2020 08:38
-
-
Save yuri-hattori/13f47cda436836f0f09ff8364972db3d to your computer and use it in GitHub Desktop.
TextコンポーネントのFontを一括で置き換えるEditor拡張
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
using UnityEngine; | |
using UnityEditor; | |
using UnityEngine.UI; | |
using UnityEditor.SceneManagement; | |
public class FontReplacer | |
{ | |
[MenuItem("Tools/FontReplace")] | |
public static void Replace () | |
{ | |
// 置き換えたいフォントの指定 | |
var replaceFont = (Font)AssetDatabase.LoadAssetAtPath ("Assets/Font/mplus-1p-regular.otf", typeof(Font)); | |
var textComponents = Resources.FindObjectsOfTypeAll(typeof(Text)) as Text[]; | |
foreach (var component in textComponents) | |
{ | |
// 置き換え | |
component.font = replaceFont; | |
} | |
// 非保存のマーキング(Sceneの米印がついた状態) | |
EditorSceneManager.MarkAllScenesDirty(); | |
// Sceneの保存 | |
EditorSceneManager.SaveOpenScenes(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment