3 using UnityEditor.Presets;
6 namespace Essentials.Presets
11 public static class PresetsTools
17 [MenuItem(
"CONTEXT/Preset/Validate all Game Objects in scene")]
18 public static void ValidateAllGameObjectsInScene(MenuCommand command)
21 Preset referencePreset = command.context as Preset;
23 if (referencePreset ==
null)
26 bool foundAnyMissmatch =
false;
28 GameObject[] allObjects =
UnityEngine.Object.FindObjectsOfType<GameObject>() ;
29 foreach (GameObject go
in allObjects)
34 foreach (Component component
in go.GetComponents(typeof(Component)))
36 if (!referencePreset.CanBeAppliedTo(component))
39 if (!referencePreset.DataEquals(component))
41 Debug.LogWarning($
"The '{referencePreset.GetTargetTypeName()}' in the Game Object '{go}' does not match the selected preset.", component);
42 foundAnyMissmatch =
true;
49 if (!foundAnyMissmatch)
50 Debug.Log(
"All GameObjects' components in the scene are configured according to the selected preset.");
57 [MenuItem(
"GameObject/Presets/Search mismatches between scene GameObjects and default Presets",
false, -20)]
58 public static bool AreAllGameObjectsInSceneMatchingWithDefaultPresets()
60 bool foundAnyMissmatch =
false;
62 GameObject[] allObjects =
UnityEngine.Object.FindObjectsOfType<GameObject>() ;
64 foreach (GameObject go
in allObjects)
66 foreach (Component component
in go.GetComponents(typeof(Component)))
68 Preset[] defaults = Preset.GetDefaultPresetsForObject(component);
70 foreach (Preset defaultPreset
in defaults)
73 if (!defaultPreset.CanBeAppliedTo(component))
79 if (!defaultPreset.DataEquals(component))
81 Debug.LogWarning($
"The '{defaultPreset.GetTargetTypeName()}' in the Game Object '{go}' does not match the default preset ({defaultPreset.name}).", component);
82 foundAnyMissmatch =
true;
90 if (foundAnyMissmatch)
93 Debug.Log(
"All GameObjects' components in the scene are configured according to the selected preset.");