Created
September 5, 2016 01:42
-
-
Save lycoris102/9439fd0ad54fe9b96ff419d4b566b8f8 to your computer and use it in GitHub Desktop.
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.SceneManagement; | |
using UnityEngine.UI; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class FontReplacer : EditorWindow | |
{ | |
private Font font; | |
[MenuItem("Custom/FontReplacer")] | |
public static void OpenWindow() | |
{ | |
EditorWindow.GetWindow(typeof(FontReplacer)).Show(); | |
} | |
void OnGUI() | |
{ | |
font = EditorGUILayout.ObjectField("Font", font, typeof(Font), true) as Font; | |
if (font != null) | |
{ | |
if (GUILayout.Button("Replace font in all scenes")) | |
{ | |
ReplaceFont(font); | |
Debug.Log("Replaced font in all scenes."); | |
} | |
} | |
} | |
static void ReplaceFont(Font font) | |
{ | |
// 現在開いているシーン群 | |
var sceneCount = UnityEngine.SceneManagement.SceneManager.sceneCount; | |
var scenePath2ActiveMap = new Dictionary<string, bool>(); | |
for (int i = 0; i < sceneCount; i++) | |
{ | |
var scene = UnityEngine.SceneManagement.SceneManager.GetSceneAt(i); | |
scenePath2ActiveMap[scene.path] = true; | |
} | |
// 全てのシーンを取得し開く | |
var allScenePaths = AssetDatabase.FindAssets("t:Scene").Select(guid => AssetDatabase.GUIDToAssetPath(guid)).ToList(); | |
foreach (var path in allScenePaths) | |
{ | |
UnityEditor.SceneManagement.EditorSceneManager.OpenScene(path, OpenSceneMode.Additive); | |
} | |
// Scene上に存在するTextComponentのフォントを置換する | |
var textComponents = Resources.FindObjectsOfTypeAll(typeof(Text)) as Text[]; | |
foreach (var textComponent in textComponents) | |
{ | |
textComponent.font = font; | |
} | |
foreach (var path in allScenePaths) | |
{ | |
// シーンを保存 | |
var scene = UnityEngine.SceneManagement.SceneManager.GetSceneByPath(path); | |
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(scene); | |
// 予め開いていたシーン群以外を閉じる | |
if (!scenePath2ActiveMap.ContainsKey(path)) | |
{ | |
UnityEditor.SceneManagement.EditorSceneManager.CloseScene(scene, true); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment