unity Editor扫描路径下场景或者组件,并进行批量修改

最近比较忙,不过还是想记录一点东西,最近需要扫描项目并添加脚本,就查了一下,由此记录一下

unity Editor下扫描文件夹下对应类型文件 例如Prefab

//便利预制件Prefab,从文件夹Assets/TestScene
string[] allPath = AssetDatabase.FindAssets("t:Prefab", new string[] {
    
     "Assets/TestScene" });
for (int i = 0; i < allPath.Length; i++)
{
    
    
    string path = AssetDatabase.GUIDToAssetPath(allPath[i]);
    GameObject obj = AssetDatabase.LoadAssetAtPath<GameObject>(path);
    if (obj != null)
    {
    
    
        Light[] lights = obj.GetComponentsInChildren<Light>();
        foreach (Light light in lights)
	    {
    
    
	    	Debug.Log(".......");
		}
    }
}
//保存更改
 AssetDatabase.SaveAssets();

扫描文件夹下的所有场景scene,并获得场景中XX类型的组件

 //便利场景--获取场景中Light类型组件
string[] scenePaths = AssetDatabase.FindAssets("t:Scene", new string[] {
    
     "Assets/TestScene" });
for (int i = 0; i < scenePaths.Length; i++)
{
    
    
    string assetPath = AssetDatabase.GUIDToAssetPath(scenePaths[i]);
    Scene newScene = EditorSceneManager.OpenScene(assetPath);
    //获取Light类型组件
    Light[] lights = Resources.FindObjectsOfTypeAll<Light>();
    foreach (Light light in lights)
    {
    
    
    	Debug.Log(".......");
	}
    EditorSceneManager.SaveScene(newScene);
}

或者你会需要显示查找并且修改进度:

进度条弹窗

//参数:1:弹窗标题,2:弹窗描述:可以用来写对应进度,3:进度0-1之间float值
EditorUtility.DisplayProgressBar("title", "des", slider);

就酱
-------------------------------------------------------------END--------------------------------------------------------------

猜你喜欢

转载自blog.csdn.net/QO_GQ/article/details/129369901