Created
June 6, 2021 04:39
-
-
Save wappenull/acfd388185c543bfe8fa98f6ab07f317 to your computer and use it in GitHub Desktop.
Help track unknown Unity scene dirty which bloat the version control.
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 UnityEditor; | |
using UnityEditor.SceneManagement; | |
using UnityEngine; | |
using UnityEngine.SceneManagement; | |
// See https://forum.unity.com/threads/how-to-know-what-makes-scene-dirty.694390 | |
namespace Wappen.Editor | |
{ | |
/// <summary> | |
/// Editor tool to track live scene change. | |
/// </summary> | |
public static class SceneChangeTracker | |
{ | |
public static bool TrackSceneChanges = false; | |
[MenuItem("Tools/Wappen/Toggle SceneChangeTracker")] | |
static void Toggle( ) | |
{ | |
if( TrackSceneChanges ) | |
DisableSceneDirtyChecker( ); | |
else | |
EnableSceneDirtyChecker( ); | |
EditorUtility.DisplayDialog( nameof(SceneChangeTracker), "SceneChangeTracker is now " + (TrackSceneChanges ? "ON" : "OFF"), "YEE" ); | |
} | |
public static void EnableSceneDirtyChecker( ) | |
{ | |
if( !TrackSceneChanges ) | |
{ | |
Undo.postprocessModifications += OnPostProcessModifications; | |
EditorSceneManager.sceneDirtied += SceneDirtied; | |
TrackSceneChanges = true; | |
} | |
} | |
public static void DisableSceneDirtyChecker( ) | |
{ | |
if( TrackSceneChanges ) | |
{ | |
Undo.postprocessModifications -= OnPostProcessModifications; | |
EditorSceneManager.sceneDirtied -= SceneDirtied; | |
TrackSceneChanges = false; | |
} | |
} | |
private static void SceneDirtied( Scene scene ) | |
{ | |
Debug.Log( $"sceneDirtied on {scene.name}. (See full stacktrace)" ); | |
} | |
public static UndoPropertyModification[] OnPostProcessModifications( UndoPropertyModification[] propertyModifications ) | |
{ | |
foreach( UndoPropertyModification mod in propertyModifications ) | |
{ | |
Debug.Log( $"Dirty {mod.currentValue.target.name}: {mod.currentValue.propertyPath} to {mod.currentValue.value} from {mod.previousValue.value}", mod.currentValue.target ); | |
} | |
return propertyModifications; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Godlike!