Skip to content

Instantly share code, notes, and snippets.

@yuri-hattori
Created January 6, 2020 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuri-hattori/13f47cda436836f0f09ff8364972db3d to your computer and use it in GitHub Desktop.
Save yuri-hattori/13f47cda436836f0f09ff8364972db3d to your computer and use it in GitHub Desktop.
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