きゅぶろぐ

きゅぶんずの ぶろぐができて べんりだな

プロジェクト内の全てのPrefabに対してなんかする

ああ〜〜プロジェクト内の全てのPrefabのTextComponentの色変えて〜

using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

namespace Sandbox
{
    public static class ReimportPrefab
    {
        [MenuItem("Sandbox/ReimportPrefab")]
        public static void Run()
        {
            var directory = new System.IO.DirectoryInfo(Application.dataPath);
            var files = directory.GetFiles("*.prefab", System.IO.SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var path = Path.Combine("Assets", file.ToString().Replace(Application.dataPath, ""));

                var go = PrefabUtility.LoadPrefabContents(path);
                foreach (var text in go.GetComponentsInChildren<Text>(true))
                {
                    text.color = Color.blue;
                }
                PrefabUtility.SaveAsPrefabAsset(go, path);
                PrefabUtility.UnloadPrefabContents(go);
            }
        }
    }
}