Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TextコンポーネントのFontを一括で置き換えるEditor拡張
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