- Validator: Added asset validators with material texture and shader validation
- Validator: Added option to enable/disable certain validators - Project Settings: Fixed issue, where changes weren't always saved - Unity: Removed deprecated warnings in Unity 6.4
This commit is contained in:
parent
01ac17a078
commit
dd55a87740
30 changed files with 716 additions and 38 deletions
|
|
@ -10,18 +10,31 @@ namespace Module.ProjectValidator.Editor
|
|||
{
|
||||
static EditorProjectValidatorHierarchy()
|
||||
{
|
||||
#if UNITY_6000_4_OR_NEWER
|
||||
EditorApplication.hierarchyWindowItemByEntityIdOnGUI -= OnHierarchyWindowItemByEntityIdOnGUI;
|
||||
EditorApplication.hierarchyWindowItemByEntityIdOnGUI += OnHierarchyWindowItemByEntityIdOnGUI;
|
||||
#else
|
||||
EditorApplication.hierarchyWindowItemOnGUI -= OnHierarchyWindowItemOnGUI;
|
||||
EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyWindowItemOnGUI;
|
||||
#endif
|
||||
|
||||
EditorSceneManager.sceneOpened -= OnSceneOpened;
|
||||
EditorSceneManager.sceneOpened += OnSceneOpened;
|
||||
}
|
||||
|
||||
#if UNITY_6000_4_OR_NEWER
|
||||
private static void OnHierarchyWindowItemByEntityIdOnGUI(EntityId entityId, Rect selectionRect)
|
||||
{
|
||||
if (Report.HasActive && Report.Active.TryGetSeverityFor(entityId, out var instance) && instance.Severity != EValidatorSeverity.Valid)
|
||||
EditorIconUtility.Draw(new Rect(selectionRect.x, selectionRect.y, selectionRect.height, selectionRect.height), instance.Severity, instance.IsRedirect);
|
||||
}
|
||||
#else
|
||||
private static void OnHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
|
||||
{
|
||||
if (Report.HasActive && Report.Active.TryGetSeverityFor(instanceID, out var instance) && instance.Severity != EValidatorSeverity.Valid)
|
||||
EditorIconUtility.Draw(new Rect(selectionRect.x, selectionRect.y, selectionRect.height, selectionRect.height), instance.Severity, instance.IsRedirect);
|
||||
}
|
||||
#endif
|
||||
|
||||
private static void OnSceneOpened(Scene scene, OpenSceneMode mode)
|
||||
{
|
||||
|
|
|
|||
BIN
Editor/Icons/editor_project_validator_settings.png
Normal file
BIN
Editor/Icons/editor_project_validator_settings.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 595 B |
117
Editor/Icons/editor_project_validator_settings.png.meta
Normal file
117
Editor/Icons/editor_project_validator_settings.png.meta
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a6c61d5fbd310894d8159ba6af32d7e3
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 13
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
flipGreenChannel: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMipmapLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
wrapV: 0
|
||||
wrapW: 0
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
swizzle: 50462976
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 4
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
customData:
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
|
|
@ -11,7 +12,12 @@ namespace Module.ProjectValidator.Editor
|
|||
|
||||
public readonly List<Entry> Entries = new();
|
||||
private readonly Dictionary<GUID, MappingEntry> _assetToSeverityMapping = new();
|
||||
|
||||
#if UNITY_6000_4_OR_NEWER
|
||||
private readonly Dictionary<EntityId, MappingEntry> _instanceToSeverityMapping = new();
|
||||
#else
|
||||
private readonly Dictionary<int, MappingEntry> _instanceToSeverityMapping = new();
|
||||
#endif
|
||||
|
||||
public void Add(GUID assetGuid, string relativePath, string fieldPath, Attribute attribute, EValidatorSeverity severity, string message)
|
||||
{
|
||||
|
|
@ -58,13 +64,23 @@ namespace Module.ProjectValidator.Editor
|
|||
|
||||
public bool TryGetSeverityFor(string guid, out MappingEntry mapping)
|
||||
{
|
||||
if (GUID.TryParse(guid, out var assetGuid) && _assetToSeverityMapping.TryGetValue(assetGuid, out mapping))
|
||||
if (UnityEngine.GUID.TryParse(guid, out var assetGuid) && _assetToSeverityMapping.TryGetValue(assetGuid, out mapping))
|
||||
return true;
|
||||
|
||||
mapping = new MappingEntry();
|
||||
return false;
|
||||
}
|
||||
|
||||
#if UNITY_6000_4_OR_NEWER
|
||||
public bool TryGetSeverityFor(EntityId entityId, out MappingEntry mapping)
|
||||
{
|
||||
if (_instanceToSeverityMapping.TryGetValue(entityId, out mapping))
|
||||
return true;
|
||||
|
||||
mapping = new MappingEntry();
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
public bool TryGetSeverityFor(int instanceId, out MappingEntry mapping)
|
||||
{
|
||||
if (_instanceToSeverityMapping.TryGetValue(instanceId, out mapping))
|
||||
|
|
@ -73,6 +89,7 @@ namespace Module.ProjectValidator.Editor
|
|||
mapping = new MappingEntry();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
public bool TryGetSeverityFor(GUID assetGuid, string relativePath, out MappingEntry mapping)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,9 +31,16 @@ namespace Module.ProjectValidator.Editor
|
|||
if (!IsFieldSerializable(fi))
|
||||
continue;
|
||||
|
||||
var attributes = fi.GetCustomAttributes();
|
||||
var fieldAttributes = fi.GetCustomAttributes();
|
||||
var fieldTypeAttributes = fi.FieldType.GetCustomAttributes();
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
foreach (var attribute in fieldAttributes)
|
||||
{
|
||||
if (validatorList.TryGetAttributeValidator(attribute.GetType(), out var validator))
|
||||
entry.AddField(fi, attribute, validator);
|
||||
}
|
||||
|
||||
foreach (var attribute in fieldTypeAttributes)
|
||||
{
|
||||
if (validatorList.TryGetAttributeValidator(attribute.GetType(), out var validator))
|
||||
entry.AddField(fi, attribute, validator);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -11,6 +12,7 @@ namespace Module.ProjectValidator.Editor
|
|||
private readonly Dictionary<Type, object> _attributeValidators = new();
|
||||
private readonly Dictionary<Type, List<object>> _componentValidators = new();
|
||||
public readonly List<IGameObjectValidator> GameObjectValidators = new();
|
||||
public readonly Dictionary<Type, List<AssetValidator>> AssetValidators = new();
|
||||
|
||||
public void AddAttribute(Type type)
|
||||
{
|
||||
|
|
@ -76,6 +78,33 @@ namespace Module.ProjectValidator.Editor
|
|||
}
|
||||
}
|
||||
|
||||
public void AddAsset(Type type)
|
||||
{
|
||||
if (type.IsInterface || type.IsAbstract)
|
||||
return;
|
||||
|
||||
var typeValidator = type.GetInterfaces().FirstOrDefault(typeInterface => typeInterface.IsGenericType && typeInterface.GetGenericTypeDefinition() == typeof(IAssetValidator<>));
|
||||
var componentType = typeValidator?.GetGenericArguments()[0];
|
||||
|
||||
if (componentType == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var instance = FormatterServices.GetUninitializedObject(type);
|
||||
var validator = new AssetValidator(instance);
|
||||
|
||||
if (AssetValidators.TryGetValue(componentType, out var list))
|
||||
list.Add(validator);
|
||||
else
|
||||
AssetValidators.Add(componentType, new List<AssetValidator> { validator });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetAttributeValidator(Type type, out object validatorInstance)
|
||||
{
|
||||
return _attributeValidators.TryGetValue(type, out validatorInstance);
|
||||
|
|
@ -85,5 +114,17 @@ namespace Module.ProjectValidator.Editor
|
|||
{
|
||||
return _componentValidators.TryGetValue(type, out validatorInstances);
|
||||
}
|
||||
|
||||
public sealed class AssetValidator
|
||||
{
|
||||
public readonly object Validator;
|
||||
public readonly MethodInfo ValidatorMethod;
|
||||
|
||||
public AssetValidator(object validator)
|
||||
{
|
||||
Validator = validator;
|
||||
ValidatorMethod = validator.GetType().GetMethod("Validate");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +1,35 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine.Pool;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
internal sealed class ProjectValidatorSettings : ScriptableObject
|
||||
{
|
||||
public List<string> assemblies = new();
|
||||
public List<ValidatorEnabled> validators = new();
|
||||
|
||||
public const string MenuPath = "Project/Project Validator";
|
||||
private const string AssetPath = "ProjectSettings/ProjectValidatorSettings.asset";
|
||||
private const string StyleSheetName = "StyleSheetProjectValidatorSettings";
|
||||
|
||||
internal static ProjectValidatorSettings GetOrCreate()
|
||||
{
|
||||
var objects = InternalEditorUtility.LoadSerializedFileAndForget(AssetPath);
|
||||
ProjectValidatorSettings settings;
|
||||
|
||||
if (objects.Length != 0)
|
||||
return (ProjectValidatorSettings)objects[0];
|
||||
settings = (ProjectValidatorSettings)objects[0];
|
||||
else
|
||||
settings = CreateInstance<ProjectValidatorSettings>();
|
||||
|
||||
var settings = CreateInstance<ProjectValidatorSettings>();
|
||||
PopulateValidatorList(settings);
|
||||
InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] { settings }, AssetPath, true);
|
||||
return settings;
|
||||
}
|
||||
|
|
@ -29,7 +37,7 @@ namespace Module.ProjectValidator.Editor
|
|||
[SettingsProvider]
|
||||
public static SettingsProvider CreateProvider()
|
||||
{
|
||||
return new SettingsProvider("Project/Project Validator", SettingsScope.Project)
|
||||
return new SettingsProvider(MenuPath, SettingsScope.Project)
|
||||
{
|
||||
label = "Project Validator",
|
||||
activateHandler = (_, root) =>
|
||||
|
|
@ -37,16 +45,73 @@ namespace Module.ProjectValidator.Editor
|
|||
var settings = GetOrCreate();
|
||||
var serializedObject = new SerializedObject(settings);
|
||||
var container = new VisualElement { style = { flexDirection = FlexDirection.Column } };
|
||||
var propertyField = new PropertyField(serializedObject.FindProperty("assemblies"), "Assemblies");
|
||||
propertyField.RegisterCallback<ChangeEvent<string>>(_ => InternalEditorUtility.SaveToSerializedFileAndForget(new[] { serializedObject.targetObject }, AssetPath, true));
|
||||
propertyField.RegisterValueChangeCallback(_ => InternalEditorUtility.SaveToSerializedFileAndForget(new[] { serializedObject.targetObject }, AssetPath, true));
|
||||
container.Add(propertyField);
|
||||
|
||||
var assemblyField = new PropertyField(serializedObject.FindProperty(nameof(assemblies)), "Assemblies");
|
||||
container.Add(assemblyField);
|
||||
|
||||
var enabledField = new PropertyField(serializedObject.FindProperty(nameof(validators)), "Validators");
|
||||
container.Add(enabledField);
|
||||
|
||||
root.Add(container);
|
||||
root.Bind(serializedObject);
|
||||
root.RegisterCallback<SerializedObjectChangeEvent>(_ => InternalEditorUtility.SaveToSerializedFileAndForget(new[] { serializedObject.targetObject }, AssetPath, true));
|
||||
root.RegisterCallback<SerializedPropertyChangeEvent>(_ => InternalEditorUtility.SaveToSerializedFileAndForget(new[] { serializedObject.targetObject }, AssetPath, true));
|
||||
root.styleSheets.Add(EditorAssetUtility.LoadFirstAsset<StyleSheet>(StyleSheetName));
|
||||
},
|
||||
keywords = new HashSet<string>(new[] { "Project", "Validator", "Assemblies" })
|
||||
};
|
||||
}
|
||||
|
||||
private static void PopulateValidatorList(ProjectValidatorSettings settings)
|
||||
{
|
||||
using var pool0 = ListPool<string>.Get(out var list);
|
||||
using var pool1 = ListPool<string>.Get(out var temp);
|
||||
|
||||
FetchValidatorsOfType(typeof(IAssetValidator<>), list);
|
||||
FetchValidatorsOfType(typeof(IAttributeValidator<>), list);
|
||||
FetchValidatorsOfType(typeof(IComponentValidator<>), list);
|
||||
FetchValidatorsOfType(typeof(IGameObjectValidator), list);
|
||||
|
||||
for (var i = 0; i < settings.validators.Count; i++)
|
||||
{
|
||||
temp.Add(settings.validators[i].type);
|
||||
}
|
||||
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (!temp.Contains(list[i]))
|
||||
settings.validators.Add(new ValidatorEnabled(list[i], true));
|
||||
}
|
||||
|
||||
for (var i = temp.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (!list.Contains(temp[i]))
|
||||
settings.validators.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchValidatorsOfType(Type type, List<string> typeNames)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(type);
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
if (!types[i].IsInterface && !types[i].IsAbstract)
|
||||
typeNames.Add(types[i].FullName);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class ValidatorEnabled
|
||||
{
|
||||
public string type;
|
||||
public bool enabled;
|
||||
|
||||
public ValidatorEnabled(string type, bool enabled)
|
||||
{
|
||||
this.type = type;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
|
|
@ -29,6 +31,22 @@ namespace Module.ProjectValidator.Editor
|
|||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static Object[] LoadAllAssets(Type type)
|
||||
{
|
||||
var guids = AssetDatabase.FindAssetGUIDs($"a:assets t:{type.Name}");
|
||||
var list = new List<Object>(guids.Length);
|
||||
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var asset = AssetDatabase.LoadAssetByGUID(guid, type);
|
||||
|
||||
if (asset != null)
|
||||
list.Add(asset);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
internal static GUID GetAssetGuid(Object obj)
|
||||
{
|
||||
var assetPath = string.Empty;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,14 @@ namespace Module.ProjectValidator.Editor
|
|||
return window;
|
||||
}
|
||||
|
||||
public static string GetAssetValidatorName(object validator)
|
||||
{
|
||||
var str = validator.GetType().Name;
|
||||
str = str.Replace("AssetValidator", string.Empty);
|
||||
str = ObjectNames.NicifyVariableName(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
internal static string GetGameObjectValidatorName(IGameObjectValidator validator)
|
||||
{
|
||||
var str = validator.GetType().Name;
|
||||
|
|
@ -196,6 +204,93 @@ namespace Module.ProjectValidator.Editor
|
|||
}
|
||||
}
|
||||
|
||||
#if UNITY_6000_4_OR_NEWER
|
||||
internal static void RebuildSceneInstanceMapping(Report report, Dictionary<EntityId, Report.MappingEntry> dictMapping)
|
||||
{
|
||||
dictMapping.Clear();
|
||||
using var _ = ListPool<GameObject>.Get(out var rootObjects);
|
||||
|
||||
for (var i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
var scene = SceneManager.GetSceneAt(i);
|
||||
|
||||
if (!scene.isLoaded)
|
||||
continue;
|
||||
|
||||
var strAssetGuid = AssetDatabase.AssetPathToGUID(scene.path);
|
||||
GUID.TryParse(strAssetGuid, out var assetGuid);
|
||||
scene.GetRootGameObjects(rootObjects);
|
||||
|
||||
for (var j = 0; j < rootObjects.Count; j++)
|
||||
{
|
||||
var rootObject = rootObjects[j];
|
||||
var relativePath = string.Empty;
|
||||
RebuildSceneInstanceMapping(report, dictMapping, rootObject, assetGuid, relativePath, true);
|
||||
}
|
||||
}
|
||||
|
||||
RebuildForAllParents(dictMapping);
|
||||
}
|
||||
|
||||
|
||||
private static void RebuildSceneInstanceMapping(Report report, Dictionary<EntityId, Report.MappingEntry> dictMapping, GameObject gameObject, GUID assetGuid, string relativePath, bool initial)
|
||||
{
|
||||
var transform = gameObject.transform;
|
||||
AppendToRelativePath(gameObject, ref relativePath, initial);
|
||||
|
||||
if (report.TryGetSeverityFor(assetGuid, relativePath, out var mapping))
|
||||
dictMapping.Add(gameObject.GetEntityId(), new Report.MappingEntry(mapping.Severity, false));
|
||||
|
||||
for (var i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
RebuildSceneInstanceMapping(report, dictMapping, transform.GetChild(i).gameObject, assetGuid, relativePath, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RebuildForAllParents(Dictionary<EntityId, Report.MappingEntry> dictMapping)
|
||||
{
|
||||
using var _ = DictionaryPool<EntityId, Report.MappingEntry>.Get(out var newMappings);
|
||||
|
||||
foreach (var pair in dictMapping)
|
||||
{
|
||||
var obj = EditorUtility.EntityIdToObject(pair.Key);
|
||||
|
||||
if (obj is not GameObject gameObject)
|
||||
continue;
|
||||
|
||||
var severity = pair.Value.Severity;
|
||||
var transform = gameObject.transform.parent;
|
||||
|
||||
while (transform != null)
|
||||
{
|
||||
gameObject = transform.gameObject;
|
||||
var entityId = gameObject.GetEntityId();
|
||||
|
||||
if (dictMapping.TryGetValue(entityId, out var parentMapping))
|
||||
{
|
||||
if (severity < parentMapping.Severity)
|
||||
severity = parentMapping.Severity;
|
||||
}
|
||||
else if (newMappings.TryGetValue(entityId, out var currentMapping))
|
||||
{
|
||||
if (currentMapping.Severity < severity)
|
||||
newMappings[entityId] = new Report.MappingEntry(severity, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
newMappings.Add(entityId, new Report.MappingEntry(severity, true));
|
||||
}
|
||||
|
||||
transform = transform.parent;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var pair in newMappings)
|
||||
{
|
||||
dictMapping.Add(pair.Key, pair.Value);
|
||||
}
|
||||
}
|
||||
#else
|
||||
internal static void RebuildSceneInstanceMapping(Report report, Dictionary<int, Report.MappingEntry> dictMapping)
|
||||
{
|
||||
dictMapping.Clear();
|
||||
|
|
@ -223,6 +318,7 @@ namespace Module.ProjectValidator.Editor
|
|||
RebuildForAllParents(dictMapping);
|
||||
}
|
||||
|
||||
|
||||
private static void RebuildSceneInstanceMapping(Report report, Dictionary<int, Report.MappingEntry> dictMapping, GameObject gameObject, GUID assetGuid, string relativePath, bool initial)
|
||||
{
|
||||
var transform = gameObject.transform;
|
||||
|
|
@ -280,6 +376,7 @@ namespace Module.ProjectValidator.Editor
|
|||
dictMapping.Add(pair.Key, pair.Value);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
internal static void RefreshUnityWindows()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ namespace Module.ProjectValidator.Editor
|
|||
{
|
||||
internal static class ValidatorRunner
|
||||
{
|
||||
private static bool _initialized;
|
||||
private static ValidatorList _validatorList;
|
||||
private static TypeTree _typeTree;
|
||||
|
||||
|
|
@ -56,21 +55,19 @@ namespace Module.ProjectValidator.Editor
|
|||
|
||||
private static void Initialize()
|
||||
{
|
||||
if (_initialized)
|
||||
return;
|
||||
|
||||
var settings = ProjectValidatorSettings.GetOrCreate();
|
||||
var assemblies = GetAssembliesFrom(settings);
|
||||
var enabled = GetEnabledValidators(settings);
|
||||
|
||||
_validatorList = new ValidatorList();
|
||||
_typeTree = new TypeTree();
|
||||
|
||||
FetchAllGameObjectValidators();
|
||||
FetchAllComponentValidators();
|
||||
FetchAllAttributeValidators();
|
||||
FetchAllGameObjectValidators(enabled);
|
||||
FetchAllComponentValidators(enabled);
|
||||
FetchAllAttributeValidators(enabled);
|
||||
FetchAllAssetValidators(enabled);
|
||||
FetchAllTypesWithValidators<Component>(assemblies);
|
||||
FetchAllTypesWithValidators<ScriptableObject>(assemblies);
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
private static Assembly[] GetAssembliesFrom(ProjectValidatorSettings settings)
|
||||
|
|
@ -93,36 +90,75 @@ namespace Module.ProjectValidator.Editor
|
|||
return assemblies.ToArray();
|
||||
}
|
||||
|
||||
private static void FetchAllAttributeValidators()
|
||||
private static HashSet<Type> GetEnabledValidators(ProjectValidatorSettings settings)
|
||||
{
|
||||
var enabled = new HashSet<Type>(settings.validators.Count);
|
||||
|
||||
for (var i = 0; i < settings.validators.Count; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!settings.validators[i].enabled)
|
||||
continue;
|
||||
|
||||
var type = Type.GetType(settings.validators[i].type);
|
||||
|
||||
if (type != null)
|
||||
enabled.Add(type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private static void FetchAllAttributeValidators(HashSet<Type> enabled)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IAttributeValidator<>));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
if (enabled.Contains(types[i]))
|
||||
_validatorList.AddAttribute(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchAllGameObjectValidators()
|
||||
private static void FetchAllGameObjectValidators(HashSet<Type> enabled)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IGameObjectValidator));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
if (enabled.Contains(types[i]))
|
||||
_validatorList.AddGameObject(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchAllComponentValidators()
|
||||
private static void FetchAllComponentValidators(HashSet<Type> enabled)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IComponentValidator<>));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
if (enabled.Contains(types[i]))
|
||||
_validatorList.AddComponent(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchAllAssetValidators(HashSet<Type> enabled)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IAssetValidator<>));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
if (enabled.Contains(types[i]))
|
||||
_validatorList.AddAsset(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchAllTypesWithValidators<T>(Assembly[] assemblies)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom<T>();
|
||||
|
|
@ -172,6 +208,25 @@ namespace Module.ProjectValidator.Editor
|
|||
private static void ValidateAllAssets(Report report)
|
||||
{
|
||||
ValidateAssetsBytype<ScriptableObject>(report);
|
||||
|
||||
foreach (var pair in _validatorList.AssetValidators)
|
||||
{
|
||||
var assets = EditorAssetUtility.LoadAllAssets(pair.Key);
|
||||
|
||||
for (var i = 0; i < assets.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var assetPath = AssetDatabase.GetAssetPath(assets[i]);
|
||||
var assetGuid = AssetDatabase.GUIDFromAssetPath(assetPath);
|
||||
ValidateAsset(assets[i], assetGuid, assetPath, pair.Value, report);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateAllPrefabs(Report report)
|
||||
|
|
@ -254,6 +309,29 @@ namespace Module.ProjectValidator.Editor
|
|||
}
|
||||
}
|
||||
|
||||
private static void ValidateAsset(UnityEngine.Object obj, GUID assetGuid, string relativePath, List<ValidatorList.AssetValidator> validators, Report report)
|
||||
{
|
||||
using var _ = ListPool<ValidatorResult>.Get(out var results);
|
||||
|
||||
for (var i = 0; i < validators.Count; i++)
|
||||
{
|
||||
results.Clear();
|
||||
var validator = validators[i];
|
||||
validator.ValidatorMethod.Invoke(validator.Validator, new object[] { obj, results });
|
||||
|
||||
for (var j = 0; j < results.Count; j++)
|
||||
{
|
||||
var result = results[j];
|
||||
|
||||
if (result.Severity == EValidatorSeverity.Valid)
|
||||
continue;
|
||||
|
||||
var validatorName = ProjectValidatorUtility.GetAssetValidatorName(validator.Validator);
|
||||
report.Add(assetGuid, relativePath, string.Empty, validatorName, result.Severity, result.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateChildren(GameObject gameObject, string relativePath, Report report)
|
||||
{
|
||||
var transform = gameObject.transform;
|
||||
|
|
|
|||
3
Editor/Validators/Assets.meta
Normal file
3
Editor/Validators/Assets.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ddbf30cd5a674751be0c125c1f4e917b
|
||||
timeCreated: 1779623970
|
||||
43
Editor/Validators/Assets/AssetValidatorMaterialShader.cs
Normal file
43
Editor/Validators/Assets/AssetValidatorMaterialShader.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
internal sealed class AssetValidatorMaterialShader : IAssetValidator<Material>
|
||||
{
|
||||
public void Validate(Material obj, List<ValidatorResult> results)
|
||||
{
|
||||
if (obj.shader == null)
|
||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, "Shader is Null"));
|
||||
else if (!IsCompatible(obj.shader))
|
||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"Shader '{obj.shader.name}' is not compatible with render pipeline"));
|
||||
else if (!obj.shader.isSupported)
|
||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"Shader '{obj.shader.name}' is not supported"));
|
||||
else if (ShaderUtil.ShaderHasError(obj.shader))
|
||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, $"Shader '{obj.shader.name}' has compile errors"));
|
||||
}
|
||||
|
||||
private static bool IsCompatible(Shader shader)
|
||||
{
|
||||
var pipeline = GraphicsSettings.currentRenderPipeline;
|
||||
|
||||
if (pipeline == null)
|
||||
return true;
|
||||
|
||||
var tagSearch = new ShaderTagId("RenderPipeline");
|
||||
var tagPipeline = new ShaderTagId(pipeline.renderPipelineShaderTag);
|
||||
|
||||
for (var i = 0; i < shader.passCount; i++)
|
||||
{
|
||||
var tagPass = shader.FindPassTagValue(i, tagSearch);
|
||||
|
||||
if (tagPass == tagPipeline)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2218d247daff44bf84629756b63ea650
|
||||
timeCreated: 1779623986
|
||||
31
Editor/Validators/Assets/AssetValidatorMaterialTexture.cs
Normal file
31
Editor/Validators/Assets/AssetValidatorMaterialTexture.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
internal sealed class AssetValidatorMaterialTexture : IAssetValidator<Material>
|
||||
{
|
||||
public void Validate(Material obj, List<ValidatorResult> results)
|
||||
{
|
||||
if (obj.shader == null)
|
||||
return;
|
||||
|
||||
var count = obj.shader.GetPropertyCount();
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var propertyType = obj.shader.GetPropertyType(i);
|
||||
|
||||
if (propertyType != ShaderPropertyType.Texture)
|
||||
continue;
|
||||
|
||||
var propertyName = obj.shader.GetPropertyName(i);
|
||||
var propertyValue = obj.GetTexture(propertyName);
|
||||
|
||||
if (propertyValue == null)
|
||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"Texture property '{propertyName}' is Null"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cfeb4b29a9cd4ea79c1e9325b8122e17
|
||||
timeCreated: 1779627240
|
||||
12
Editor/Validators/Attributes/AttributeValidatorObsolete.cs
Normal file
12
Editor/Validators/Attributes/AttributeValidatorObsolete.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
internal sealed class AttributeValidatorObsolete : IAttributeValidator<ObsoleteAttribute>
|
||||
{
|
||||
public ValidatorResult Validate(ObsoleteAttribute attribute, object value)
|
||||
{
|
||||
return ValidatorResult.Create(EValidatorSeverity.Error, "Obsolete");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 982ac4e898cc2ca438e98a2f0034a8d3
|
||||
28
Editor/Validators/GameObject/GameObjectValidatorTransform.cs
Normal file
28
Editor/Validators/GameObject/GameObjectValidatorTransform.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
internal sealed class GameObjectValidatorTransform : IGameObjectValidator
|
||||
{
|
||||
public void Validate(GameObject gameObject, List<ValidatorResult> results)
|
||||
{
|
||||
var transform = gameObject.transform;
|
||||
var lp = transform.localPosition;
|
||||
var lr = transform.localRotation;
|
||||
var ls = transform.localScale;
|
||||
|
||||
if (IsInvalid(lp.x) || IsInvalid(lp.y) || IsInvalid(lp.z))
|
||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, $"Local position '{lp}' is invalid"));
|
||||
if (IsInvalid(lr.x) || IsInvalid(lr.y) || IsInvalid(lr.z) || IsInvalid(lr.w))
|
||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, $"Local rotation '{lr}' is invalid"));
|
||||
if (IsInvalid(ls.x) || IsInvalid(ls.y) || IsInvalid(ls.z))
|
||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, $"Local scale '{ls}' is invalid"));
|
||||
}
|
||||
|
||||
private static bool IsInvalid(float value)
|
||||
{
|
||||
return float.IsNaN(value) || float.IsInfinity(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 727d5de59b004deb8c192337bcee132e
|
||||
timeCreated: 1779628852
|
||||
|
|
@ -24,6 +24,7 @@ namespace Module.ProjectValidator.Editor
|
|||
root.Q<ToolbarButton>("button-run").clicked += OnToolbarButtonRunClicked;
|
||||
root.Q<ToolbarButton>("button-clear").clicked += OnToolbarButtonClearClicked;
|
||||
root.Q<ToolbarSearchField>().RegisterValueChangedCallback(OnToolbarSearchFieldChanged);
|
||||
root.Q<ToolbarButton>("button-settings").clicked += OnToolbarButtonSettingsClicked;
|
||||
|
||||
_treeView = root.Q<MultiColumnTreeView>();
|
||||
_treeView.columns["asset"].makeCell = CreateObjectField;
|
||||
|
|
@ -126,6 +127,11 @@ namespace Module.ProjectValidator.Editor
|
|||
ValidatorRunner.Clear();
|
||||
}
|
||||
|
||||
private void OnToolbarButtonSettingsClicked()
|
||||
{
|
||||
SettingsService.OpenProjectSettings(ProjectValidatorSettings.MenuPath);
|
||||
}
|
||||
|
||||
private void OnToolbarSearchFieldChanged(ChangeEvent<string> evt)
|
||||
{
|
||||
_searchFilter = evt.newValue;
|
||||
|
|
|
|||
3
Editor/Window/Objects.meta
Normal file
3
Editor/Window/Objects.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a22633e08b3d4c0fbbea654a8a8cd287
|
||||
timeCreated: 1779637991
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(ProjectValidatorSettings.ValidatorEnabled))]
|
||||
internal sealed class EditorProjectValidatorEnabledPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override VisualElement CreatePropertyGUI(SerializedProperty property)
|
||||
{
|
||||
var spType = property.FindPropertyRelative(nameof(ProjectValidatorSettings.ValidatorEnabled.type));
|
||||
var spEnabled = property.FindPropertyRelative(nameof(ProjectValidatorSettings.ValidatorEnabled.enabled));
|
||||
|
||||
var root = new VisualElement { style = { flexDirection = FlexDirection.Row } };
|
||||
var veType = new PropertyField(spType, string.Empty) { style = { flexGrow = 1f } };
|
||||
var veEnabled = new PropertyField(spEnabled, string.Empty);
|
||||
root.Add(veEnabled);
|
||||
root.Add(veType);
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e6c8cb829f514028b705bf121373c67c
|
||||
timeCreated: 1779638011
|
||||
|
|
@ -17,3 +17,16 @@
|
|||
}
|
||||
|
||||
|
||||
|
||||
.toolbar-button-settings {
|
||||
width: 24px;
|
||||
min-width: 24px;
|
||||
max-width: 24px;
|
||||
padding-top: 0;
|
||||
padding-right: 0;
|
||||
padding-bottom: 0;
|
||||
padding-left: 0;
|
||||
background-image: url("project://database/Packages/com.module.project-validator/Editor/Icons/editor_project_validator_settings.png?fileID=2800000&guid=a6c61d5fbd310894d8159ba6af32d7e3&type=3#editor_project_validator_settings");
|
||||
-unity-background-scale-mode: scale-to-fit;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<uie:ToolbarButton text="Clear" name="button-clear"/>
|
||||
<uie:ToolbarSpacer style="flex-grow: 1;"/>
|
||||
<uie:ToolbarSearchField name="search-field"/>
|
||||
<uie:ToolbarButton text="" name="button-settings" class="toolbar-button-settings"/>
|
||||
</uie:Toolbar>
|
||||
<ui:MultiColumnTreeView columns="" sort-column-descriptions="" name="tree-view" show-alternating-row-backgrounds="All" data-source-type="Module.ProjectValidator.Editor.Report+Entry, Module.ProjectValidator.Editor" sorting-mode="Default" class="tree-view">
|
||||
<ui:Columns reorderable="false" primary-column-name="severity">
|
||||
|
|
|
|||
45
README.md
45
README.md
|
|
@ -1,15 +1,50 @@
|
|||
# Description
|
||||
|
||||
A tool to help validate data across scenes, prefabs and scriptable objects.
|
||||
A tool to help validate data across scenes, prefabs, scriptable objects and assets.
|
||||
|
||||

|
||||
|
||||
### Unity Windows
|
||||
## Unity Windows
|
||||
|
||||

|
||||

|
||||
|
||||
## Game Object Validators
|
||||
## Settings
|
||||

|
||||
|
||||
|
||||
## Validators
|
||||
|
||||
### Asset Validators
|
||||
|
||||
```csharp
|
||||
public sealed class AssetValidatorMaterialTexture : IAssetValidator<Material>
|
||||
{
|
||||
public void Validate(Material obj, List<ValidatorResult> results)
|
||||
{
|
||||
if (obj.shader == null)
|
||||
return;
|
||||
|
||||
var count = obj.shader.GetPropertyCount();
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var propertyType = obj.shader.GetPropertyType(i);
|
||||
|
||||
if (propertyType != ShaderPropertyType.Texture)
|
||||
continue;
|
||||
|
||||
var propertyName = obj.shader.GetPropertyName(i);
|
||||
var propertyValue = obj.GetTexture(propertyName);
|
||||
|
||||
if (propertyValue == null)
|
||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"Texture property '{propertyName}' is Null"));
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Game Object Validators
|
||||
|
||||
```csharp
|
||||
public sealed class GameObjectValidatorBrokenPrefab : IGameObjectValidator
|
||||
|
|
@ -22,7 +57,7 @@ public sealed class GameObjectValidatorBrokenPrefab : IGameObjectValidator
|
|||
}
|
||||
```
|
||||
|
||||
## Component Validators
|
||||
### Component Validators
|
||||
|
||||
```csharp
|
||||
public sealed class ComponentValidatorMeshCollider : IComponentValidator<MeshCollider>
|
||||
|
|
@ -35,7 +70,7 @@ public sealed class ComponentValidatorMeshCollider : IComponentValidator<MeshCol
|
|||
}
|
||||
```
|
||||
|
||||
## Attribute Validators
|
||||
### Attribute Validators
|
||||
|
||||
The field attribute:
|
||||
```csharp
|
||||
|
|
|
|||
10
Runtime/Interfaces/IAssetValidator.cs
Normal file
10
Runtime/Interfaces/IAssetValidator.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.ProjectValidator
|
||||
{
|
||||
public interface IAssetValidator<in T> where T : Object
|
||||
{
|
||||
void Validate(T obj, List<ValidatorResult> results);
|
||||
}
|
||||
}
|
||||
3
Runtime/Interfaces/IAssetValidator.cs.meta
Normal file
3
Runtime/Interfaces/IAssetValidator.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 24ee414b7fa14a368a48cab1b608ee3b
|
||||
timeCreated: 1779624012
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "com.module.project-validator",
|
||||
"version": "0.6.0",
|
||||
"version": "1.0.0",
|
||||
"displayName": "Module.ProjectValidator",
|
||||
"description": "",
|
||||
"unity": "6000.3",
|
||||
|
|
|
|||
BIN
~Images/editor-project-settings.png
Normal file
BIN
~Images/editor-project-settings.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
Loading…
Add table
Add a link
Reference in a new issue