Created
November 19, 2022 06:06
-
-
Save atori708/c06c63e43f0cda693e42c271a0a54e1a to your computer and use it in GitHub Desktop.
【Unity】特定のシーンアセットを保存させない実装
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.IO; | |
using UnityEditor; | |
public class SaveSceneAssetBlocker : AssetModificationProcessor | |
{ | |
/// <summary> | |
/// 保存したくないシーン名 | |
/// </summary> | |
static string _dontSaveSceneName; | |
/// <summary> | |
/// 保存したくないシーン名を設定 | |
/// </summary> | |
/// <param name="sceneName">シーン名</param> | |
public static void SetDontSaveScene(string sceneName) | |
{ | |
_dontSaveSceneName = sceneName; | |
} | |
/// <summary> | |
/// 保存したくないシーン設定をリセット | |
/// </summary> | |
public static void ResetDontSaveScene() | |
{ | |
_dontSaveSceneName = string.Empty; | |
} | |
/// <summary> | |
/// アセット保存時に呼ばれる | |
/// </summary> | |
/// <param name="paths"></param> | |
/// <returns></returns> | |
static string[] OnWillSaveAssets(string[] paths) | |
{ | |
if (string.IsNullOrEmpty(_dontSaveSceneName)) { | |
return paths; | |
} | |
var newPaths = new List<string>(paths.Length); | |
// 保存したくないアセット以外のパスを返す | |
foreach (string path in paths) { | |
var fileName = Path.GetFileName(path); | |
if (fileName != _dontSaveSceneName) { | |
newPaths.Add(path); | |
} | |
} | |
return newPaths.ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment