-
Notifications
You must be signed in to change notification settings - Fork 50
/
SceneRefValidatorOnSave.cs
51 lines (41 loc) · 1.36 KB
/
SceneRefValidatorOnSave.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace KBCore.Refs
{
[InitializeOnLoad]
public static class SceneRefValidatorOnSave
{
private const string PrefsKey = "KBCore/ValidateRefsOnSave";
private const string MenuItemText = "Tools/KBCore/Validate Refs on Save";
public static bool ValidateRefsOnSave
{
get => EditorPrefs.GetBool(PrefsKey, false);
private set => EditorPrefs.SetBool(PrefsKey, value);
}
static SceneRefValidatorOnSave()
{
EditorSceneManager.sceneSaving += OnSceneSaving;
}
[MenuItem(MenuItemText, false, 1000)]
public static void ToggleValidateRefsOnSave()
{
ValidateRefsOnSave = !ValidateRefsOnSave;
Menu.SetChecked(MenuItemText, ValidateRefsOnSave);
}
[MenuItem(MenuItemText, true)]
public static bool ToggleValidateRefsOnSaveValidate()
{
Menu.SetChecked(MenuItemText, ValidateRefsOnSave);
return true;
}
private static void OnSceneSaving(Scene scene, string path)
{
if (!ValidateRefsOnSave) return;
SceneRefAttributeValidator.ValidateAllRefs();
}
}
}
#endif