LoginSignup
4
3

More than 5 years have passed since last update.

【Unity】Project内の全シーンに処理を実行する

Posted at

すべてのSceneに対して操作を行う

Editorから何らかの処理を実行します。
Componentを置換したりRenameしたり...etc.

磯野ー!何かしようぜー!

using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using System;
using System.IO;
using System.Linq;

/// <summary>
/// シーン操作クラス
/// </summary>
public class SceneOperation
{
    /// <summary>
    /// Project内の全てのシーンに対して処理を実行します
    /// </summary>
    public static void OperationAllScene(Action<Scene> action)
    {
        var cnt = 0;
        var scenePathList = AssetDatabase.GetAllAssetPaths().Where(_ => Path.GetExtension(_) == ".unity").ToList();
        foreach (var path in scenePathList)
        {
            var scene = EditorSceneManager.OpenScene(path);
            EditorUtility.DisplayProgressBar("全Scene操作", scene.name + "シーンの操作をしています", (float) cnt / scenePathList.Count);
            // TODO ここに処理を追加.
            if (action != null) action(scene);
            EditorSceneManager.SaveScene(scene);
            EditorSceneManager.CloseScene(scene, true);
            cnt++;
        }
        EditorUtility.ClearProgressBar();
    }
}

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3