Skip to content

Instantly share code, notes, and snippets.

@atori708
Created November 19, 2022 06:51
Show Gist options
  • Save atori708/f2c4700a7094d41541d52051d8d62c10 to your computer and use it in GitHub Desktop.
Save atori708/f2c4700a7094d41541d52051d8d62c10 to your computer and use it in GitHub Desktop.
【Unity】シーンの変更を破棄する
using UnityEditor;
using UnityEngine.SceneManagement;
using System.Reflection;
public class DiscardChangeSceneAsset
{
/// <summary>
/// シーンの変更を破棄する
/// </summary>
/// <param name="scene"></param>
public void DiscardChange(Scene scene)
{
// 一応再生中は実行できないようにしておく
if (EditorApplication.isPlaying) {
return;
}
typeof(UnityEditor.SceneManagement.EditorSceneManager).InvokeMember(
"ReloadScene",
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod,
null,
null,
new object[] { scene }
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment