1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity シーンの変更を保存

Posted at
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
using UnityEditor.SceneManagement;

public class Sample
{
    [MenuItem("MyTools/Sample")]
    public static void Main()
    {
        // 変更処理
        var root = new GameObject("Root");

        var gameObjects = (GameObject[])Object.FindObjectsOfType(typeof(GameObject));

        foreach(var obj in gameObjects)
        {
            obj.transform.SetParent(root.transform);
        }
        // 終了

        // シーンの取得
        var currentScene = SceneManager.GetActiveScene();
        // 変更したことを知らせる。
        EditorSceneManager.MarkSceneDirty(currentScene);
        // 変更を保存する。
        EditorSceneManager.SaveScene(currentScene);
    }
}

SaveCurrentScene.gif

Dirtyの簡単な説明

Unityではデータが変更されているが、ディスクには保存されておらず保存する必要がある場合にダーティフラグを使用します。
参考
https://docs.unity3d.com/jp/460/ScriptReference/EditorUtility.SetDirty.html

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?