-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(assets): Auto reverting on save
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
Packages/com.nekometer.esnya.inari-udon/Assets/AutoRevert.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using UnityEngine; | ||
#if UNITY_EDITOR | ||
using System.Linq; | ||
using UnityEngine.SceneManagement; | ||
using UnityEditor; | ||
using UnityEditor.SceneManagement; | ||
using VRC.Udon; | ||
using UdonSharp; | ||
#endif | ||
|
||
namespace InariUdon | ||
{ | ||
|
||
public class AutoRevert : MonoBehaviour | ||
{ | ||
private void Reset() | ||
{ | ||
hideFlags = HideFlags.DontSaveInBuild; | ||
} | ||
|
||
#if UNITY_EDITOR | ||
public void Revert() | ||
{ | ||
foreach (var gameObject in GetComponentsInChildren<Transform>(true) | ||
.Where(PrefabUtility.IsPartOfAnyPrefab) | ||
.Select(t => PrefabUtility.GetOutermostPrefabInstanceRoot(t)) | ||
.Distinct() | ||
.Where(r => PrefabUtility.HasPrefabInstanceAnyOverrides(r, false)) | ||
) | ||
{ | ||
Debug.Log($"[AutoRevert] Reverting {gameObject}", gameObject); | ||
PrefabUtility.RevertPrefabInstance(gameObject, InteractionMode.AutomatedAction); | ||
} | ||
|
||
} | ||
|
||
public static void RevertAll(Scene scene) | ||
{ | ||
foreach (var autoRevert in scene.GetRootGameObjects().SelectMany(o => o.GetComponentsInChildren<AutoRevert>(true))) | ||
{ | ||
autoRevert.Revert(); | ||
} | ||
} | ||
|
||
[InitializeOnLoadMethod] | ||
private static void Initialize() | ||
{ | ||
EditorSceneManager.sceneSaving += (scene, _) => RevertAll(scene); | ||
} | ||
#endif | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/com.nekometer.esnya.inari-udon/Assets/AutoRevert.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.