Compare commits
11 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb46c22ffc | |||
| 9dd45f536e | |||
| 3802ca557c | |||
| ed3c02a0aa | |||
| 2ec61871c2 | |||
| 58acb2979d | |||
| ddb4fc25ea | |||
| dd55a87740 | |||
| 01ac17a078 | |||
| 47c9c53819 | |||
| 591693da1d |
41 changed files with 1155 additions and 111 deletions
|
|
@ -10,19 +10,32 @@ namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
static EditorProjectValidatorHierarchy()
|
static EditorProjectValidatorHierarchy()
|
||||||
{
|
{
|
||||||
|
#if UNITY_6000_4_OR_NEWER
|
||||||
|
EditorApplication.hierarchyWindowItemByEntityIdOnGUI -= OnHierarchyWindowItemByEntityIdOnGUI;
|
||||||
|
EditorApplication.hierarchyWindowItemByEntityIdOnGUI += OnHierarchyWindowItemByEntityIdOnGUI;
|
||||||
|
#else
|
||||||
EditorApplication.hierarchyWindowItemOnGUI -= OnHierarchyWindowItemOnGUI;
|
EditorApplication.hierarchyWindowItemOnGUI -= OnHierarchyWindowItemOnGUI;
|
||||||
EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyWindowItemOnGUI;
|
EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyWindowItemOnGUI;
|
||||||
|
#endif
|
||||||
|
|
||||||
EditorSceneManager.sceneOpened -= OnSceneOpened;
|
EditorSceneManager.sceneOpened -= OnSceneOpened;
|
||||||
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)
|
private static void OnHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
|
||||||
{
|
{
|
||||||
if (Report.HasActive && Report.Active.TryGetSeverityFor(instanceID, out var instance) && instance.Severity != EValidatorSeverity.Valid)
|
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);
|
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)
|
private static void OnSceneOpened(Scene scene, OpenSceneMode mode)
|
||||||
{
|
{
|
||||||
if (Report.HasActive && ProjectValidatorUtility.IsValidForRun())
|
if (Report.HasActive && ProjectValidatorUtility.IsValidForRun())
|
||||||
|
|
|
||||||
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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Module.ProjectValidator.Editor
|
namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
|
|
@ -11,23 +12,28 @@ namespace Module.ProjectValidator.Editor
|
||||||
|
|
||||||
public readonly List<Entry> Entries = new();
|
public readonly List<Entry> Entries = new();
|
||||||
private readonly Dictionary<GUID, MappingEntry> _assetToSeverityMapping = 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();
|
private readonly Dictionary<int, MappingEntry> _instanceToSeverityMapping = new();
|
||||||
|
#endif
|
||||||
|
|
||||||
public void Add(GUID assetGuid, string scenePath, string fieldPath, Attribute attribute, EValidatorSeverity severity, string message)
|
public void Add(GUID assetGuid, string relativePath, string fieldPath, Attribute attribute, EValidatorSeverity severity, string message)
|
||||||
{
|
{
|
||||||
var type = ProjectValidatorUtility.GetAttributeShortName(attribute);
|
var type = ProjectValidatorUtility.GetAttributeShortName(attribute);
|
||||||
Add(assetGuid, scenePath, fieldPath, type, severity, message);
|
Add(assetGuid, relativePath, fieldPath, type, severity, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(GUID assetGuid, string scenePath, string fieldPath, string type, EValidatorSeverity severity, string message)
|
public void Add(GUID assetGuid, string relativePath, string fieldPath, string type, EValidatorSeverity severity, string message)
|
||||||
{
|
{
|
||||||
Entries.Add(new Entry
|
Entries.Add(new Entry
|
||||||
{
|
{
|
||||||
AssetGuid = assetGuid,
|
AssetGuid = assetGuid,
|
||||||
AssetName = EditorAssetUtility.GetAssetName(assetGuid),
|
AssetName = EditorAssetUtility.GetAssetName(assetGuid),
|
||||||
ScenePath = scenePath,
|
RelativePath = relativePath,
|
||||||
FieldPath = fieldPath,
|
FieldPath = fieldPath,
|
||||||
ScenePathRichText = ProjectValidatorUtility.ApplyRichTextToScenePath(scenePath),
|
RelativePathRichText = ProjectValidatorUtility.ApplyRichTextToRelativePath(relativePath),
|
||||||
FieldPathRichText = ProjectValidatorUtility.ApplyRichTextToFieldPath(fieldPath),
|
FieldPathRichText = ProjectValidatorUtility.ApplyRichTextToFieldPath(fieldPath),
|
||||||
Type = type,
|
Type = type,
|
||||||
Severity = severity,
|
Severity = severity,
|
||||||
|
|
@ -64,7 +70,17 @@ namespace Module.ProjectValidator.Editor
|
||||||
mapping = new MappingEntry();
|
mapping = new MappingEntry();
|
||||||
return false;
|
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)
|
public bool TryGetSeverityFor(int instanceId, out MappingEntry mapping)
|
||||||
{
|
{
|
||||||
if (_instanceToSeverityMapping.TryGetValue(instanceId, out mapping))
|
if (_instanceToSeverityMapping.TryGetValue(instanceId, out mapping))
|
||||||
|
|
@ -73,8 +89,9 @@ namespace Module.ProjectValidator.Editor
|
||||||
mapping = new MappingEntry();
|
mapping = new MappingEntry();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public bool TryGetSeverityFor(GUID assetGuid, string scenePath, out MappingEntry mapping)
|
public bool TryGetSeverityFor(GUID assetGuid, string relativePath, out MappingEntry mapping)
|
||||||
{
|
{
|
||||||
if (!_assetToSeverityMapping.TryGetValue(assetGuid, out mapping))
|
if (!_assetToSeverityMapping.TryGetValue(assetGuid, out mapping))
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -83,7 +100,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
|
|
||||||
for (var i = 0; i < Entries.Count; i++)
|
for (var i = 0; i < Entries.Count; i++)
|
||||||
{
|
{
|
||||||
if (Entries[i].AssetGuid != assetGuid || Entries[i].ScenePath != scenePath || Entries[i].Severity <= mapping.Severity)
|
if (Entries[i].AssetGuid != assetGuid || Entries[i].RelativePath != relativePath || Entries[i].Severity <= mapping.Severity)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mapping = new MappingEntry(Entries[i].Severity, false);
|
mapping = new MappingEntry(Entries[i].Severity, false);
|
||||||
|
|
@ -110,10 +127,10 @@ namespace Module.ProjectValidator.Editor
|
||||||
public GUID AssetGuid;
|
public GUID AssetGuid;
|
||||||
public string AssetName;
|
public string AssetName;
|
||||||
|
|
||||||
public string ScenePath;
|
public string RelativePath;
|
||||||
public string FieldPath;
|
public string FieldPath;
|
||||||
|
|
||||||
public string ScenePathRichText;
|
public string RelativePathRichText;
|
||||||
public string FieldPathRichText;
|
public string FieldPathRichText;
|
||||||
|
|
||||||
public string Type;
|
public string Type;
|
||||||
|
|
@ -124,7 +141,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
public bool Filter(string filter)
|
public bool Filter(string filter)
|
||||||
{
|
{
|
||||||
return AssetName.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
return AssetName.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
ScenePath.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
RelativePath.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
FieldPath.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
FieldPath.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
Type.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
Type.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
SeverityResult.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
SeverityResult.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,16 @@ namespace Module.ProjectValidator.Editor
|
||||||
if (!IsFieldSerializable(fi))
|
if (!IsFieldSerializable(fi))
|
||||||
continue;
|
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))
|
if (validatorList.TryGetAttributeValidator(attribute.GetType(), out var validator))
|
||||||
entry.AddField(fi, attribute, validator);
|
entry.AddField(fi, attribute, validator);
|
||||||
|
|
@ -164,7 +171,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
return Components == null && Fields == null && Entries == null;
|
return Components == null && Fields == null && Entries == null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ValidatorField
|
public sealed class ValidatorField
|
||||||
{
|
{
|
||||||
public readonly FieldInfo FieldInfo;
|
public readonly FieldInfo FieldInfo;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
@ -11,6 +12,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
private readonly Dictionary<Type, object> _attributeValidators = new();
|
private readonly Dictionary<Type, object> _attributeValidators = new();
|
||||||
private readonly Dictionary<Type, List<object>> _componentValidators = new();
|
private readonly Dictionary<Type, List<object>> _componentValidators = new();
|
||||||
public readonly List<IGameObjectValidator> GameObjectValidators = new();
|
public readonly List<IGameObjectValidator> GameObjectValidators = new();
|
||||||
|
public readonly Dictionary<Type, List<AssetValidator>> AssetValidators = new();
|
||||||
|
|
||||||
public void AddAttribute(Type type)
|
public void AddAttribute(Type type)
|
||||||
{
|
{
|
||||||
|
|
@ -75,6 +77,33 @@ namespace Module.ProjectValidator.Editor
|
||||||
Debug.LogException(e);
|
Debug.LogException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
public bool TryGetAttributeValidator(Type type, out object validatorInstance)
|
||||||
{
|
{
|
||||||
|
|
@ -85,5 +114,17 @@ namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
return _componentValidators.TryGetValue(type, out validatorInstances);
|
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,36 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
using UnityEditor.UIElements;
|
using UnityEditor.UIElements;
|
||||||
using UnityEditorInternal;
|
using UnityEditorInternal;
|
||||||
|
using UnityEngine.Pool;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace Module.ProjectValidator.Editor
|
namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
internal sealed class ProjectValidatorSettings : ScriptableObject
|
internal sealed class ProjectValidatorSettings : ScriptableObject
|
||||||
{
|
{
|
||||||
public List<string> assemblies = new();
|
public List<string> assemblies = new();
|
||||||
|
[NonReorderable]
|
||||||
|
public List<ValidatorEnabled> validators = new();
|
||||||
|
|
||||||
|
public const string MenuPath = "Project/Project Validator";
|
||||||
private const string AssetPath = "ProjectSettings/ProjectValidatorSettings.asset";
|
private const string AssetPath = "ProjectSettings/ProjectValidatorSettings.asset";
|
||||||
private const string StyleSheetName = "StyleSheetProjectValidatorSettings";
|
private const string StyleSheetName = "StyleSheetProjectValidatorSettings";
|
||||||
|
|
||||||
internal static ProjectValidatorSettings GetOrCreate()
|
internal static ProjectValidatorSettings GetOrCreate()
|
||||||
{
|
{
|
||||||
var objects = InternalEditorUtility.LoadSerializedFileAndForget(AssetPath);
|
var objects = InternalEditorUtility.LoadSerializedFileAndForget(AssetPath);
|
||||||
|
ProjectValidatorSettings settings;
|
||||||
|
|
||||||
if (objects.Length != 0)
|
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);
|
InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] { settings }, AssetPath, true);
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +38,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
[SettingsProvider]
|
[SettingsProvider]
|
||||||
public static SettingsProvider CreateProvider()
|
public static SettingsProvider CreateProvider()
|
||||||
{
|
{
|
||||||
return new SettingsProvider("Project/Project Validator", SettingsScope.Project)
|
return new SettingsProvider(MenuPath, SettingsScope.Project)
|
||||||
{
|
{
|
||||||
label = "Project Validator",
|
label = "Project Validator",
|
||||||
activateHandler = (_, root) =>
|
activateHandler = (_, root) =>
|
||||||
|
|
@ -37,16 +46,79 @@ namespace Module.ProjectValidator.Editor
|
||||||
var settings = GetOrCreate();
|
var settings = GetOrCreate();
|
||||||
var serializedObject = new SerializedObject(settings);
|
var serializedObject = new SerializedObject(settings);
|
||||||
var container = new VisualElement { style = { flexDirection = FlexDirection.Column } };
|
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));
|
var assemblyField = new PropertyField(serializedObject.FindProperty(nameof(assemblies)), "Assemblies");
|
||||||
propertyField.RegisterValueChangeCallback(_ => InternalEditorUtility.SaveToSerializedFileAndForget(new[] { serializedObject.targetObject }, AssetPath, true));
|
container.Add(assemblyField);
|
||||||
container.Add(propertyField);
|
|
||||||
|
var enabledField = new PropertyField(serializedObject.FindProperty(nameof(validators)), "Validators");
|
||||||
|
container.Add(enabledField);
|
||||||
|
|
||||||
root.Add(container);
|
root.Add(container);
|
||||||
root.Bind(serializedObject);
|
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));
|
root.styleSheets.Add(EditorAssetUtility.LoadFirstAsset<StyleSheet>(StyleSheetName));
|
||||||
},
|
},
|
||||||
keywords = new HashSet<string>(new[] { "Project", "Validator", "Assemblies" })
|
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].assemblyQualifiedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < list.Count; i++)
|
||||||
|
{
|
||||||
|
if (temp.Contains(list[i]))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var type = Type.GetType(list[i]);
|
||||||
|
var name = type != null ? type.Name : "Unknown Type";
|
||||||
|
settings.validators.Add(new ValidatorEnabled(name, 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].AssemblyQualifiedName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public sealed class ValidatorEnabled
|
||||||
|
{
|
||||||
|
public string name;
|
||||||
|
public string assemblyQualifiedName;
|
||||||
|
public bool enabled;
|
||||||
|
|
||||||
|
public ValidatorEnabled(string name, string assemblyQualifiedName, bool enabled)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.assemblyQualifiedName = assemblyQualifiedName;
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace Module.ProjectValidator.Editor
|
namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
|
|
@ -29,22 +31,39 @@ namespace Module.ProjectValidator.Editor
|
||||||
return list.ToArray();
|
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)
|
internal static GUID GetAssetGuid(Object obj)
|
||||||
{
|
{
|
||||||
var assetGuid = new GUID();
|
var assetPath = string.Empty;
|
||||||
|
|
||||||
if (obj is GameObject gameObject)
|
if (obj is GameObject gameObject)
|
||||||
{
|
{
|
||||||
if (gameObject.scene.isLoaded)
|
if (gameObject.scene.isLoaded)
|
||||||
GUID.TryParse(AssetDatabase.AssetPathToGUID(gameObject.scene.path), out assetGuid);
|
assetPath = gameObject.scene.path;
|
||||||
else if (PrefabUtility.IsPartOfPrefabAsset(gameObject))
|
else if (PrefabUtility.IsPartOfPrefabAsset(gameObject))
|
||||||
GUID.TryParse(AssetDatabase.AssetPathToGUID(gameObject.scene.path), out assetGuid);
|
assetPath = AssetDatabase.GetAssetPath(gameObject);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GUID.TryParse(AssetDatabase.GetAssetPath(obj), out assetGuid);
|
assetPath = AssetDatabase.GetAssetPath(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUID.TryParse(AssetDatabase.AssetPathToGUID(assetPath), out var assetGuid);
|
||||||
return assetGuid;
|
return assetGuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,14 @@ namespace Module.ProjectValidator.Editor
|
||||||
window.titleContent = new GUIContent("Project Validator");
|
window.titleContent = new GUIContent("Project Validator");
|
||||||
return window;
|
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)
|
internal static string GetGameObjectValidatorName(IGameObjectValidator validator)
|
||||||
{
|
{
|
||||||
|
|
@ -62,14 +70,17 @@ namespace Module.ProjectValidator.Editor
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void AppendToScenePath(GameObject gameObject, ref string scenePath)
|
internal static void AppendToRelativePath(GameObject gameObject, ref string relativePath, bool initial)
|
||||||
{
|
{
|
||||||
scenePath = string.IsNullOrEmpty(scenePath) ? gameObject.name : $"{scenePath}/{gameObject.name}";
|
if (string.IsNullOrEmpty(relativePath))
|
||||||
|
relativePath = gameObject.name;
|
||||||
|
else
|
||||||
|
relativePath = initial ? $"{relativePath}{gameObject.name}" : $"{relativePath}/{gameObject.name}";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ApplyRichTextToScenePath(string scenePath)
|
internal static string ApplyRichTextToRelativePath(string relativePath)
|
||||||
{
|
{
|
||||||
return scenePath.Replace("/", "<color=#00ff00><b>/</b></color>");
|
return relativePath.Replace("/", "<color=#00ff00><b>/</b></color>");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AppendToFieldPath(FieldInfo fieldInfo, ref string fieldPath)
|
public static void AppendToFieldPath(FieldInfo fieldInfo, ref string fieldPath)
|
||||||
|
|
@ -105,7 +116,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
var scene = SceneManager.GetSceneByPath(assetPath);
|
var scene = SceneManager.GetSceneByPath(assetPath);
|
||||||
|
|
||||||
if (scene.isLoaded && TryFindSceneObjectByPath(scene, entry.ScenePath, out var gameObject))
|
if (scene.isLoaded && TryFindSceneObjectByPath(scene, entry.RelativePath, out var gameObject))
|
||||||
EditorGUIUtility.PingObject(gameObject);
|
EditorGUIUtility.PingObject(gameObject);
|
||||||
else
|
else
|
||||||
EditorGUIUtility.PingObject(asset);
|
EditorGUIUtility.PingObject(asset);
|
||||||
|
|
@ -116,14 +127,14 @@ namespace Module.ProjectValidator.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryFindSceneObjectByPath(Scene scene, string scenePath, out GameObject gameObject)
|
private static bool TryFindSceneObjectByPath(Scene scene, string relativePath, out GameObject gameObject)
|
||||||
{
|
{
|
||||||
using var _ = ListPool<GameObject>.Get(out var rootObjects);
|
using var _ = ListPool<GameObject>.Get(out var rootObjects);
|
||||||
scene.GetRootGameObjects(rootObjects);
|
scene.GetRootGameObjects(rootObjects);
|
||||||
|
|
||||||
var index = scenePath.IndexOf('/');
|
var index = relativePath.IndexOf('/');
|
||||||
var rootName = index != -1 ? scenePath[..index] : scenePath;
|
var rootName = index != -1 ? relativePath[..index] : relativePath;
|
||||||
var childPath = index != -1 ? scenePath[(index + 1)..] : string.Empty;
|
var childPath = index != -1 ? relativePath[(index + 1)..] : string.Empty;
|
||||||
|
|
||||||
for (var i = 0; i < rootObjects.Count; i++)
|
for (var i = 0; i < rootObjects.Count; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -193,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)
|
internal static void RebuildSceneInstanceMapping(Report report, Dictionary<int, Report.MappingEntry> dictMapping)
|
||||||
{
|
{
|
||||||
dictMapping.Clear();
|
dictMapping.Clear();
|
||||||
|
|
@ -212,25 +310,26 @@ namespace Module.ProjectValidator.Editor
|
||||||
for (var j = 0; j < rootObjects.Count; j++)
|
for (var j = 0; j < rootObjects.Count; j++)
|
||||||
{
|
{
|
||||||
var rootObject = rootObjects[j];
|
var rootObject = rootObjects[j];
|
||||||
var scenePath = string.Empty;
|
var relativePath = string.Empty;
|
||||||
RebuildSceneInstanceMapping(report, dictMapping, rootObject, assetGuid, scenePath);
|
RebuildSceneInstanceMapping(report, dictMapping, rootObject, assetGuid, relativePath, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RebuildForAllParents(dictMapping);
|
RebuildForAllParents(dictMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RebuildSceneInstanceMapping(Report report, Dictionary<int, Report.MappingEntry> dictMapping, GameObject gameObject, GUID assetGuid, string scenePath)
|
|
||||||
|
private static void RebuildSceneInstanceMapping(Report report, Dictionary<int, Report.MappingEntry> dictMapping, GameObject gameObject, GUID assetGuid, string relativePath, bool initial)
|
||||||
{
|
{
|
||||||
var transform = gameObject.transform;
|
var transform = gameObject.transform;
|
||||||
AppendToScenePath(gameObject, ref scenePath);
|
AppendToRelativePath(gameObject, ref relativePath, initial);
|
||||||
|
|
||||||
if (report.TryGetSeverityFor(assetGuid, scenePath, out var mapping))
|
if (report.TryGetSeverityFor(assetGuid, relativePath, out var mapping))
|
||||||
dictMapping.Add(gameObject.GetInstanceID(), new Report.MappingEntry(mapping.Severity, false));
|
dictMapping.Add(gameObject.GetInstanceID(), new Report.MappingEntry(mapping.Severity, false));
|
||||||
|
|
||||||
for (var i = 0; i < transform.childCount; i++)
|
for (var i = 0; i < transform.childCount; i++)
|
||||||
{
|
{
|
||||||
RebuildSceneInstanceMapping(report, dictMapping, transform.GetChild(i).gameObject, assetGuid, scenePath);
|
RebuildSceneInstanceMapping(report, dictMapping, transform.GetChild(i).gameObject, assetGuid, relativePath, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,6 +376,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
dictMapping.Add(pair.Key, pair.Value);
|
dictMapping.Add(pair.Key, pair.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
internal static void RefreshUnityWindows()
|
internal static void RefreshUnityWindows()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
internal static class ValidatorRunner
|
internal static class ValidatorRunner
|
||||||
{
|
{
|
||||||
private static bool _initialized;
|
|
||||||
private static ValidatorList _validatorList;
|
private static ValidatorList _validatorList;
|
||||||
private static TypeTree _typeTree;
|
private static TypeTree _typeTree;
|
||||||
|
|
||||||
|
|
@ -30,6 +29,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
var report = new Report();
|
var report = new Report();
|
||||||
ValidateAllScenes(report);
|
ValidateAllScenes(report);
|
||||||
ValidateAllAssets(report);
|
ValidateAllAssets(report);
|
||||||
|
ValidateAllPrefabs(report);
|
||||||
report.RebuildAssetMapping();
|
report.RebuildAssetMapping();
|
||||||
report.RebuildInstanceMapping();
|
report.RebuildInstanceMapping();
|
||||||
report.SetAsActive();
|
report.SetAsActive();
|
||||||
|
|
@ -55,21 +55,19 @@ namespace Module.ProjectValidator.Editor
|
||||||
|
|
||||||
private static void Initialize()
|
private static void Initialize()
|
||||||
{
|
{
|
||||||
if (_initialized)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var settings = ProjectValidatorSettings.GetOrCreate();
|
var settings = ProjectValidatorSettings.GetOrCreate();
|
||||||
var assemblies = GetAssembliesFrom(settings);
|
var assemblies = GetAssembliesFrom(settings);
|
||||||
|
var enabled = GetEnabledValidators(settings);
|
||||||
|
|
||||||
_validatorList = new ValidatorList();
|
_validatorList = new ValidatorList();
|
||||||
_typeTree = new TypeTree();
|
_typeTree = new TypeTree();
|
||||||
|
|
||||||
FetchAllGameObjectValidators();
|
FetchAllGameObjectValidators(enabled);
|
||||||
FetchAllComponentValidators();
|
FetchAllComponentValidators(enabled);
|
||||||
FetchAllAttributeValidators();
|
FetchAllAttributeValidators(enabled);
|
||||||
|
FetchAllAssetValidators(enabled);
|
||||||
FetchAllTypesWithValidators<Component>(assemblies);
|
FetchAllTypesWithValidators<Component>(assemblies);
|
||||||
FetchAllTypesWithValidators<ScriptableObject>(assemblies);
|
FetchAllTypesWithValidators<ScriptableObject>(assemblies);
|
||||||
_initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Assembly[] GetAssembliesFrom(ProjectValidatorSettings settings)
|
private static Assembly[] GetAssembliesFrom(ProjectValidatorSettings settings)
|
||||||
|
|
@ -92,33 +90,72 @@ namespace Module.ProjectValidator.Editor
|
||||||
return assemblies.ToArray();
|
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].assemblyQualifiedName);
|
||||||
|
|
||||||
|
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<>));
|
var types = TypeCache.GetTypesDerivedFrom(typeof(IAttributeValidator<>));
|
||||||
|
|
||||||
for (var i = 0; i < types.Count; i++)
|
for (var i = 0; i < types.Count; i++)
|
||||||
{
|
{
|
||||||
_validatorList.AddAttribute(types[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));
|
var types = TypeCache.GetTypesDerivedFrom(typeof(IGameObjectValidator));
|
||||||
|
|
||||||
for (var i = 0; i < types.Count; i++)
|
for (var i = 0; i < types.Count; i++)
|
||||||
{
|
{
|
||||||
_validatorList.AddGameObject(types[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<>));
|
var types = TypeCache.GetTypesDerivedFrom(typeof(IComponentValidator<>));
|
||||||
|
|
||||||
for (var i = 0; i < types.Count; i++)
|
for (var i = 0; i < types.Count; i++)
|
||||||
{
|
{
|
||||||
_validatorList.AddComponent(types[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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,12 +179,12 @@ namespace Module.ProjectValidator.Editor
|
||||||
|
|
||||||
for (var i = 0; i < assets.Length; i++)
|
for (var i = 0; i < assets.Length; i++)
|
||||||
{
|
{
|
||||||
|
var assetPath = AssetDatabase.GetAssetPath(assets[i]);
|
||||||
|
var scene = SceneManager.GetSceneByPath(assetPath);
|
||||||
|
var isLoaded = scene.isLoaded;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var assetPath = AssetDatabase.GetAssetPath(assets[i]);
|
|
||||||
var scene = SceneManager.GetSceneByPath(assetPath);
|
|
||||||
var isLoaded = scene.isLoaded;
|
|
||||||
|
|
||||||
if (!isLoaded)
|
if (!isLoaded)
|
||||||
scene = EditorSceneManager.OpenScene(assetPath, OpenSceneMode.Additive);
|
scene = EditorSceneManager.OpenScene(assetPath, OpenSceneMode.Additive);
|
||||||
|
|
||||||
|
|
@ -155,22 +192,60 @@ namespace Module.ProjectValidator.Editor
|
||||||
|
|
||||||
for (var j = 0; j < rootObjects.Count; j++)
|
for (var j = 0; j < rootObjects.Count; j++)
|
||||||
{
|
{
|
||||||
ValidateGameObject(rootObjects[j], string.Empty, report);
|
ValidateGameObject(rootObjects[j], string.Empty, report, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isLoaded)
|
|
||||||
EditorSceneManager.CloseScene(scene, true);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogException(e);
|
Debug.LogException(e);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (!isLoaded && scene.isLoaded)
|
||||||
|
EditorSceneManager.CloseScene(scene, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateAllAssets(Report report)
|
private static void ValidateAllAssets(Report report)
|
||||||
{
|
{
|
||||||
ValidateAssetsBytype<ScriptableObject>(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)
|
||||||
|
{
|
||||||
|
var assets = EditorAssetUtility.LoadAllAssets<GameObject>();
|
||||||
|
|
||||||
|
for (var i = 0; i < assets.Length; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ValidateGameObject(assets[i], string.Empty, report, true);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateAssetsBytype<T>(Report report) where T : UnityEngine.Object
|
private static void ValidateAssetsBytype<T>(Report report) where T : UnityEngine.Object
|
||||||
|
|
@ -193,12 +268,13 @@ namespace Module.ProjectValidator.Editor
|
||||||
private static void ValidateUnityObject(UnityEngine.Object obj, Report report)
|
private static void ValidateUnityObject(UnityEngine.Object obj, Report report)
|
||||||
{
|
{
|
||||||
var assetGuid = EditorAssetUtility.ObjectToAssetGuid(obj);
|
var assetGuid = EditorAssetUtility.ObjectToAssetGuid(obj);
|
||||||
Validate(assetGuid, string.Empty, obj, report);
|
var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
|
||||||
|
Validate(assetGuid, assetPath, obj, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateGameObject(GameObject gameObject, string scenePath, Report report)
|
private static void ValidateGameObject(GameObject gameObject, string relativePath, Report report, bool initial)
|
||||||
{
|
{
|
||||||
ProjectValidatorUtility.AppendToScenePath(gameObject, ref scenePath);
|
ProjectValidatorUtility.AppendToRelativePath(gameObject, ref relativePath, initial);
|
||||||
|
|
||||||
var assetGuid = EditorAssetUtility.GetAssetGuid(gameObject);
|
var assetGuid = EditorAssetUtility.GetAssetGuid(gameObject);
|
||||||
using var _ = ListPool<ValidatorResult>.Get(out var results);
|
using var _ = ListPool<ValidatorResult>.Get(out var results);
|
||||||
|
|
@ -215,15 +291,15 @@ namespace Module.ProjectValidator.Editor
|
||||||
var result = results[j];
|
var result = results[j];
|
||||||
|
|
||||||
if (result.Severity != EValidatorSeverity.Valid)
|
if (result.Severity != EValidatorSeverity.Valid)
|
||||||
report.Add(assetGuid, scenePath, string.Empty, type, result.Severity, result.Message);
|
report.Add(assetGuid, relativePath, string.Empty, type, result.Severity, result.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidateComponents(gameObject, assetGuid, scenePath, report);
|
ValidateComponents(gameObject, assetGuid, relativePath, report);
|
||||||
ValidateChildren(gameObject, scenePath, report);
|
ValidateChildren(gameObject, relativePath, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateComponents(GameObject gameObject, GUID assetGuid, string scenePath, Report report)
|
private static void ValidateComponents(GameObject gameObject, GUID assetGuid, string relativePath, Report report)
|
||||||
{
|
{
|
||||||
using var _ = ListPool<Component>.Get(out var components);
|
using var _ = ListPool<Component>.Get(out var components);
|
||||||
gameObject.GetComponents(components);
|
gameObject.GetComponents(components);
|
||||||
|
|
@ -231,21 +307,44 @@ namespace Module.ProjectValidator.Editor
|
||||||
for (var i = 0; i < components.Count; i++)
|
for (var i = 0; i < components.Count; i++)
|
||||||
{
|
{
|
||||||
if (components[i] != null)
|
if (components[i] != null)
|
||||||
Validate(assetGuid, scenePath, components[i], report);
|
Validate(assetGuid, relativePath, components[i], report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 scenePath, Report report)
|
private static void ValidateChildren(GameObject gameObject, string relativePath, Report report)
|
||||||
{
|
{
|
||||||
var transform = gameObject.transform;
|
var transform = gameObject.transform;
|
||||||
|
|
||||||
for (var i = 0; i < transform.childCount; i++)
|
for (var i = 0; i < transform.childCount; i++)
|
||||||
{
|
{
|
||||||
ValidateGameObject(transform.GetChild(i).gameObject, scenePath, report);
|
ValidateGameObject(transform.GetChild(i).gameObject, relativePath, report, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Validate(GUID assetGuid, string scenePath, object obj, Report report)
|
private static void Validate(GUID assetGuid, string relativePath, object obj, Report report)
|
||||||
{
|
{
|
||||||
var type = obj.GetType();
|
var type = obj.GetType();
|
||||||
|
|
||||||
|
|
@ -253,10 +352,10 @@ namespace Module.ProjectValidator.Editor
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var fieldPath = obj.GetType().Name;
|
var fieldPath = obj.GetType().Name;
|
||||||
Validate(assetGuid, scenePath, fieldPath, obj, entry, report);
|
Validate(assetGuid, relativePath, fieldPath, obj, entry, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Validate(GUID assetGuid, string scenePath, string parentFieldPath, object obj, TypeTree.Entry entry, Report report)
|
private static void Validate(GUID assetGuid, string relativePath, string parentFieldPath, object obj, TypeTree.Entry entry, Report report)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return;
|
return;
|
||||||
|
|
@ -268,7 +367,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var component = entry.Components[i];
|
var component = entry.Components[i];
|
||||||
ValidateComponent(component, obj, assetGuid, scenePath, report);
|
ValidateComponent(component, obj, assetGuid, relativePath, report);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
@ -297,13 +396,13 @@ namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
var fieldPathArrElement = fieldPath;
|
var fieldPathArrElement = fieldPath;
|
||||||
ProjectValidatorUtility.AppendToFieldPath(idx, ref fieldPathArrElement);
|
ProjectValidatorUtility.AppendToFieldPath(idx, ref fieldPathArrElement);
|
||||||
ValidateField(field, eObj, assetGuid, scenePath, fieldPathArrElement, report);
|
ValidateField(field, eObj, assetGuid, relativePath, fieldPathArrElement, report);
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ValidateField(field, value, assetGuid, scenePath, fieldPath, report);
|
ValidateField(field, value, assetGuid, relativePath, fieldPath, report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -324,8 +423,18 @@ namespace Module.ProjectValidator.Editor
|
||||||
|
|
||||||
var fieldPath = parentFieldPath;
|
var fieldPath = parentFieldPath;
|
||||||
ProjectValidatorUtility.AppendToFieldPath(e.FieldInfo, ref fieldPath);
|
ProjectValidatorUtility.AppendToFieldPath(e.FieldInfo, ref fieldPath);
|
||||||
|
|
||||||
if (value is IEnumerable<object> ie)
|
if (value is Array arr)
|
||||||
|
{
|
||||||
|
for (var j = 0; j < arr.Length; j++)
|
||||||
|
{
|
||||||
|
var eObj = arr.GetValue(j);
|
||||||
|
var fieldPathArrElement = fieldPath;
|
||||||
|
ProjectValidatorUtility.AppendToFieldPath(j, ref fieldPathArrElement);
|
||||||
|
Validate(assetGuid, relativePath, fieldPathArrElement, eObj, e.Entry, report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (value is IEnumerable<object> ie)
|
||||||
{
|
{
|
||||||
var idx = 0;
|
var idx = 0;
|
||||||
|
|
||||||
|
|
@ -333,13 +442,13 @@ namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
var fieldPathArrElement = fieldPath;
|
var fieldPathArrElement = fieldPath;
|
||||||
ProjectValidatorUtility.AppendToFieldPath(idx, ref fieldPathArrElement);
|
ProjectValidatorUtility.AppendToFieldPath(idx, ref fieldPathArrElement);
|
||||||
Validate(assetGuid, scenePath, fieldPathArrElement, eObj, e.Entry, report);
|
Validate(assetGuid, relativePath, fieldPathArrElement, eObj, e.Entry, report);
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Validate(assetGuid, scenePath, fieldPath, value, e.Entry, report);
|
Validate(assetGuid, relativePath, fieldPath, value, e.Entry, report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -350,15 +459,15 @@ namespace Module.ProjectValidator.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateField(TypeTree.ValidatorField field, object value, GUID assetGuid, string scenePath, string fieldPath, Report report)
|
private static void ValidateField(TypeTree.ValidatorField field, object value, GUID assetGuid, string relativePath, string fieldPath, Report report)
|
||||||
{
|
{
|
||||||
var result = (ValidatorResult)field.ValidatorMethod.Invoke(field.Validator, new[] { field.Attribute, value });
|
var result = (ValidatorResult)field.ValidatorMethod.Invoke(field.Validator, new[] { field.Attribute, value });
|
||||||
|
|
||||||
if (result.Severity != EValidatorSeverity.Valid)
|
if (result.Severity != EValidatorSeverity.Valid)
|
||||||
report.Add(assetGuid, scenePath, fieldPath, field.Attribute, result.Severity, result.Message);
|
report.Add(assetGuid, relativePath, fieldPath, field.Attribute, result.Severity, result.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateComponent(TypeTree.ValidatorComponent component, object value, GUID assetGuid, string scenePath, Report report)
|
private static void ValidateComponent(TypeTree.ValidatorComponent component, object value, GUID assetGuid, string relativePath, Report report)
|
||||||
{
|
{
|
||||||
using var _ = ListPool<ValidatorResult>.Get(out var results);
|
using var _ = ListPool<ValidatorResult>.Get(out var results);
|
||||||
component.ValidatorMethod.Invoke(component.Validator, new[] { value, results });
|
component.ValidatorMethod.Invoke(component.Validator, new[] { value, results });
|
||||||
|
|
@ -369,7 +478,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
var result = results[i];
|
var result = results[i];
|
||||||
|
|
||||||
if (result.Severity != EValidatorSeverity.Valid)
|
if (result.Severity != EValidatorSeverity.Valid)
|
||||||
report.Add(assetGuid, scenePath, string.Empty, type, result.Severity, result.Message);
|
report.Add(assetGuid, relativePath, string.Empty, type, result.Severity, result.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
Editor/Validators/Assets.meta
Normal file
3
Editor/Validators/Assets.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ddbf30cd5a674751be0c125c1f4e917b
|
||||||
|
timeCreated: 1779623970
|
||||||
47
Editor/Validators/Assets/AssetValidatorMaterialShader.cs
Normal file
47
Editor/Validators/Assets/AssetValidatorMaterialShader.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
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);
|
||||||
|
var hasKeyword = false;
|
||||||
|
|
||||||
|
for (var i = 0; i < shader.passCount; i++)
|
||||||
|
{
|
||||||
|
var tagPass = shader.FindPassTagValue(i, tagSearch);
|
||||||
|
|
||||||
|
if (tagPass != ShaderTagId.none)
|
||||||
|
hasKeyword = true;
|
||||||
|
|
||||||
|
if (tagPass == tagPipeline)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !hasKeyword;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2218d247daff44bf84629756b63ea650
|
||||||
|
timeCreated: 1779623986
|
||||||
34
Editor/Validators/Assets/AssetValidatorMaterialTexture.cs
Normal file
34
Editor/Validators/Assets/AssetValidatorMaterialTexture.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
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);
|
||||||
|
var propertyFlags = obj.shader.GetPropertyFlags(i);
|
||||||
|
|
||||||
|
if (propertyType != ShaderPropertyType.Texture)
|
||||||
|
continue;
|
||||||
|
if ((propertyFlags & (ShaderPropertyFlags.PerRendererData | ShaderPropertyFlags.HideInInspector | ShaderPropertyFlags.NonModifiableTextureData)) != 0)
|
||||||
|
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
|
||||||
3
Editor/Validators/Attributes.meta
Normal file
3
Editor/Validators/Attributes.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0aa1d741049f4074bb863b76ed604d07
|
||||||
|
timeCreated: 1779214748
|
||||||
23
Editor/Validators/Attributes/AttributeValidatorMin.cs
Normal file
23
Editor/Validators/Attributes/AttributeValidatorMin.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Module.ProjectValidator.Editor
|
||||||
|
{
|
||||||
|
internal sealed class AttributeValidatorMin : IAttributeValidator<MinAttribute>
|
||||||
|
{
|
||||||
|
public ValidatorResult Validate(MinAttribute attribute, object value)
|
||||||
|
{
|
||||||
|
if (value is int iValue)
|
||||||
|
{
|
||||||
|
if (iValue < attribute.min)
|
||||||
|
return ValidatorResult.Create(EValidatorSeverity.Error, $"Value {iValue} is less than minimum value of {attribute.min}");
|
||||||
|
}
|
||||||
|
else if (value is float fValue)
|
||||||
|
{
|
||||||
|
if (fValue < attribute.min)
|
||||||
|
return ValidatorResult.Create(EValidatorSeverity.Error, $"Value {fValue} is less than minimum value of {attribute.min}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ValidatorResult.Valid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2015106b3c9b450e9efb1333e5239033
|
||||||
|
timeCreated: 1779214761
|
||||||
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
|
||||||
23
Editor/Validators/Attributes/AttributeValidatorRange.cs
Normal file
23
Editor/Validators/Attributes/AttributeValidatorRange.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Module.ProjectValidator.Editor
|
||||||
|
{
|
||||||
|
internal sealed class AttributeValidatorRange : IAttributeValidator<RangeAttribute>
|
||||||
|
{
|
||||||
|
public ValidatorResult Validate(RangeAttribute attribute, object value)
|
||||||
|
{
|
||||||
|
if (value is int iValue)
|
||||||
|
{
|
||||||
|
if (iValue < attribute.min || iValue > attribute.max)
|
||||||
|
return ValidatorResult.Create(EValidatorSeverity.Error, $"Value {iValue} is not in the range [{attribute.min};{attribute.max}]");
|
||||||
|
}
|
||||||
|
else if (value is float fValue)
|
||||||
|
{
|
||||||
|
if (fValue < attribute.min || fValue > attribute.max)
|
||||||
|
return ValidatorResult.Create(EValidatorSeverity.Error, $"Value {fValue} is not in the range [{attribute.min};{attribute.max}]");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ValidatorResult.Valid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3115c26bccfe4b1e964f784a3f9fdd55
|
||||||
|
timeCreated: 1779214908
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Pool;
|
||||||
|
|
||||||
|
namespace Module.ProjectValidator.Editor
|
||||||
|
{
|
||||||
|
internal sealed class GameObjectValidatorDuplicateComponents : IGameObjectValidator
|
||||||
|
{
|
||||||
|
public void Validate(GameObject gameObject, List<ValidatorResult> results)
|
||||||
|
{
|
||||||
|
using var _ = ListPool<Component>.Get(out var list);
|
||||||
|
gameObject.GetComponents(list);
|
||||||
|
list.Sort((c0, c1) => c0.GetType().GetHashCode().CompareTo(c1.GetType().GetHashCode()));
|
||||||
|
|
||||||
|
if (list.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var type = list[0].GetType();
|
||||||
|
var count = 1;
|
||||||
|
|
||||||
|
for (var i = 1; i < list.Count; i++)
|
||||||
|
{
|
||||||
|
var t = list[i].GetType();
|
||||||
|
|
||||||
|
if (type == t)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (count > 1 && IsMultipleComponentsAllowed(type))
|
||||||
|
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"GameObject has duplicate '{type.Name}' ({count}) components"));
|
||||||
|
|
||||||
|
type = t;
|
||||||
|
count = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > 1 && IsMultipleComponentsAllowed(type))
|
||||||
|
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"GameObject has duplicate '{type.Name}' ({count}) components"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsMultipleComponentsAllowed(Type type)
|
||||||
|
{
|
||||||
|
return type.GetCustomAttribute<DisallowMultipleComponent>(true) == null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b27a4e96523d4d3d97c11b32814f29d3
|
||||||
|
timeCreated: 1779213834
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Pool;
|
||||||
|
|
||||||
|
namespace Module.ProjectValidator.Editor
|
||||||
|
{
|
||||||
|
internal sealed class GameObjectValidatorObsoleteComponents : IGameObjectValidator
|
||||||
|
{
|
||||||
|
public void Validate(GameObject gameObject, List<ValidatorResult> results)
|
||||||
|
{
|
||||||
|
using var _ = ListPool<Component>.Get(out var list);
|
||||||
|
gameObject.GetComponents(list);
|
||||||
|
|
||||||
|
for (var i = 0; i < list.Count; i++)
|
||||||
|
{
|
||||||
|
var type = list[i].GetType();
|
||||||
|
|
||||||
|
if (type.GetCustomAttribute(typeof(ObsoleteAttribute)) != null)
|
||||||
|
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"GameObject has obsolete '{type.Name}' component"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ca678bbf72fa4c8f8c9b945535aacf44
|
||||||
|
timeCreated: 1779214145
|
||||||
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
|
||||||
|
|
@ -8,12 +8,18 @@ namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
internal sealed class EditorProjectValidatorWindow : EditorWindow
|
internal sealed class EditorProjectValidatorWindow : EditorWindow
|
||||||
{
|
{
|
||||||
|
private VisualElement _groupWarnings;
|
||||||
|
private Label _labelWarnings;
|
||||||
|
|
||||||
|
private VisualElement _groupErrors;
|
||||||
|
private Label _labelErrors;
|
||||||
|
|
||||||
private MultiColumnTreeView _treeView;
|
private MultiColumnTreeView _treeView;
|
||||||
private string _searchFilter;
|
private string _searchFilter;
|
||||||
|
|
||||||
private readonly List<TreeViewItemData<Report.Entry>> _list = new();
|
private readonly List<TreeViewItemData<Report.Entry>> _list = new();
|
||||||
private readonly List<TreeViewItemData<Report.Entry>> _filteredList = new();
|
private readonly List<TreeViewItemData<Report.Entry>> _filteredList = new();
|
||||||
|
|
||||||
public void CreateGUI()
|
public void CreateGUI()
|
||||||
{
|
{
|
||||||
var root = rootVisualElement;
|
var root = rootVisualElement;
|
||||||
|
|
@ -21,23 +27,33 @@ namespace Module.ProjectValidator.Editor
|
||||||
root.styleSheets.Add(EditorAssetUtility.LoadFirstAsset<StyleSheet>("StyleSheetEditorProjectValidatorWindow"));
|
root.styleSheets.Add(EditorAssetUtility.LoadFirstAsset<StyleSheet>("StyleSheetEditorProjectValidatorWindow"));
|
||||||
root.Add(asset.Instantiate());
|
root.Add(asset.Instantiate());
|
||||||
|
|
||||||
|
_groupWarnings = root.Q<VisualElement>("status-warnings");
|
||||||
|
_labelWarnings = _groupWarnings.Q<Label>("label-warnings");
|
||||||
|
|
||||||
|
_groupErrors = root.Q<VisualElement>("status-errors");
|
||||||
|
_labelErrors = _groupErrors.Q<Label>("label-errors");
|
||||||
|
|
||||||
|
_groupWarnings.style.display = DisplayStyle.None;
|
||||||
|
_groupErrors.style.display = DisplayStyle.None;
|
||||||
|
|
||||||
root.Q<ToolbarButton>("button-run").clicked += OnToolbarButtonRunClicked;
|
root.Q<ToolbarButton>("button-run").clicked += OnToolbarButtonRunClicked;
|
||||||
root.Q<ToolbarButton>("button-clear").clicked += OnToolbarButtonClearClicked;
|
root.Q<ToolbarButton>("button-clear").clicked += OnToolbarButtonClearClicked;
|
||||||
root.Q<ToolbarSearchField>().RegisterValueChangedCallback(OnToolbarSearchFieldChanged);
|
root.Q<ToolbarSearchField>().RegisterValueChangedCallback(OnToolbarSearchFieldChanged);
|
||||||
|
root.Q<ToolbarButton>("button-settings").clicked += OnToolbarButtonSettingsClicked;
|
||||||
|
|
||||||
_treeView = root.Q<MultiColumnTreeView>();
|
_treeView = root.Q<MultiColumnTreeView>();
|
||||||
_treeView.columns["asset"].makeCell = CreateObjectField;
|
_treeView.columns["asset"].makeCell = CreateObjectField;
|
||||||
_treeView.columns["type"].makeCell = CreateLabel;
|
_treeView.columns["type"].makeCell = CreateLabel;
|
||||||
_treeView.columns["severity"].makeCell = CreateLabel;
|
_treeView.columns["severity"].makeCell = CreateLabel;
|
||||||
_treeView.columns["severity-message"].makeCell = CreateLabel;
|
_treeView.columns["severity-message"].makeCell = CreateLabel;
|
||||||
_treeView.columns["scene-path"].makeCell = CreateLabel;
|
_treeView.columns["relative-path"].makeCell = CreateLabel;
|
||||||
_treeView.columns["field-path"].makeCell = CreateLabel;
|
_treeView.columns["field-path"].makeCell = CreateLabel;
|
||||||
|
|
||||||
_treeView.columns["asset"].bindCell = OnTreeViewBindCellAsset;
|
_treeView.columns["asset"].bindCell = OnTreeViewBindCellAsset;
|
||||||
_treeView.columns["type"].bindCell = OnTreeViewBindCellType;
|
_treeView.columns["type"].bindCell = OnTreeViewBindCellType;
|
||||||
_treeView.columns["severity"].bindCell = OnTreeViewBindCellSeverity;
|
_treeView.columns["severity"].bindCell = OnTreeViewBindCellSeverity;
|
||||||
_treeView.columns["severity-message"].bindCell = OnTreeViewBindCellSeverityMessage;
|
_treeView.columns["severity-message"].bindCell = OnTreeViewBindCellSeverityMessage;
|
||||||
_treeView.columns["scene-path"].bindCell = OnTreeViewBindCellScenePath;
|
_treeView.columns["relative-path"].bindCell = OnTreeViewBindCellRelativePath;
|
||||||
_treeView.columns["field-path"].bindCell = OnTreeViewBindCellFieldPath;
|
_treeView.columns["field-path"].bindCell = OnTreeViewBindCellFieldPath;
|
||||||
|
|
||||||
_treeView.columns["severity"].unbindCell = OnTreeViewUnbindCellSeverity;
|
_treeView.columns["severity"].unbindCell = OnTreeViewUnbindCellSeverity;
|
||||||
|
|
@ -46,7 +62,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
_treeView.columns["type"].comparison = OnTreeViewComparisonCellType;
|
_treeView.columns["type"].comparison = OnTreeViewComparisonCellType;
|
||||||
_treeView.columns["severity"].comparison = OnTreeViewComparisonCellSeverity;
|
_treeView.columns["severity"].comparison = OnTreeViewComparisonCellSeverity;
|
||||||
_treeView.columns["severity-message"].comparison = OnTreeViewComparisonCellSeverityMessage;
|
_treeView.columns["severity-message"].comparison = OnTreeViewComparisonCellSeverityMessage;
|
||||||
_treeView.columns["scene-path"].comparison = OnTreeViewComparisonCellScenePath;
|
_treeView.columns["relative-path"].comparison = OnTreeViewComparisonCellRelativePath;
|
||||||
_treeView.columns["field-path"].comparison = OnTreeViewComparisonCellFieldPath;
|
_treeView.columns["field-path"].comparison = OnTreeViewComparisonCellFieldPath;
|
||||||
|
|
||||||
_treeView.selectionChanged += OnTreeViewSelectionChanged;
|
_treeView.selectionChanged += OnTreeViewSelectionChanged;
|
||||||
|
|
@ -60,11 +76,26 @@ namespace Module.ProjectValidator.Editor
|
||||||
|
|
||||||
_list.Clear();
|
_list.Clear();
|
||||||
|
|
||||||
for (var i = 0; i < Report.Active.Entries.Count; i++)
|
var entries = Report.Active.Entries;
|
||||||
|
var warningCount = 0;
|
||||||
|
var errorCount = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < entries.Count; i++)
|
||||||
{
|
{
|
||||||
_list.Add(new TreeViewItemData<Report.Entry>(i, Report.Active.Entries[i]));
|
_list.Add(new TreeViewItemData<Report.Entry>(i, entries[i]));
|
||||||
|
|
||||||
|
if (entries[i].Severity == EValidatorSeverity.Warning)
|
||||||
|
warningCount++;
|
||||||
|
if (entries[i].Severity == EValidatorSeverity.Error)
|
||||||
|
errorCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_groupWarnings.style.display = warningCount > 0 ? DisplayStyle.Flex : DisplayStyle.None;
|
||||||
|
_labelWarnings.text = warningCount.ToString();
|
||||||
|
|
||||||
|
_groupErrors.style.display = errorCount > 0 ? DisplayStyle.Flex : DisplayStyle.None;
|
||||||
|
_labelErrors.text = errorCount.ToString();
|
||||||
|
|
||||||
Filter();
|
Filter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,9 +154,16 @@ namespace Module.ProjectValidator.Editor
|
||||||
|
|
||||||
private void OnToolbarButtonClearClicked()
|
private void OnToolbarButtonClearClicked()
|
||||||
{
|
{
|
||||||
|
_groupWarnings.style.display = DisplayStyle.None;
|
||||||
|
_groupErrors.style.display = DisplayStyle.None;
|
||||||
ValidatorRunner.Clear();
|
ValidatorRunner.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnToolbarButtonSettingsClicked()
|
||||||
|
{
|
||||||
|
SettingsService.OpenProjectSettings(ProjectValidatorSettings.MenuPath);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnToolbarSearchFieldChanged(ChangeEvent<string> evt)
|
private void OnToolbarSearchFieldChanged(ChangeEvent<string> evt)
|
||||||
{
|
{
|
||||||
_searchFilter = evt.newValue;
|
_searchFilter = evt.newValue;
|
||||||
|
|
@ -170,11 +208,11 @@ namespace Module.ProjectValidator.Editor
|
||||||
label.text = entry.SeverityResult;
|
label.text = entry.SeverityResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTreeViewBindCellScenePath(VisualElement ve, int index)
|
private void OnTreeViewBindCellRelativePath(VisualElement ve, int index)
|
||||||
{
|
{
|
||||||
var label = (Label)ve;
|
var label = (Label)ve;
|
||||||
var entry = _treeView.GetItemDataForIndex<Report.Entry>(index);
|
var entry = _treeView.GetItemDataForIndex<Report.Entry>(index);
|
||||||
label.text = entry.ScenePathRichText;
|
label.text = entry.RelativePathRichText;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTreeViewBindCellFieldPath(VisualElement ve, int index)
|
private void OnTreeViewBindCellFieldPath(VisualElement ve, int index)
|
||||||
|
|
@ -222,11 +260,11 @@ namespace Module.ProjectValidator.Editor
|
||||||
return string.Compare(entry0.SeverityResult, entry1.SeverityResult, StringComparison.Ordinal);
|
return string.Compare(entry0.SeverityResult, entry1.SeverityResult, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int OnTreeViewComparisonCellScenePath(int index0, int index1)
|
private int OnTreeViewComparisonCellRelativePath(int index0, int index1)
|
||||||
{
|
{
|
||||||
var entry0 = _treeView.GetItemDataForIndex<Report.Entry>(index0);
|
var entry0 = _treeView.GetItemDataForIndex<Report.Entry>(index0);
|
||||||
var entry1 = _treeView.GetItemDataForIndex<Report.Entry>(index1);
|
var entry1 = _treeView.GetItemDataForIndex<Report.Entry>(index1);
|
||||||
return string.Compare(entry0.ScenePath, entry1.ScenePath, StringComparison.Ordinal);
|
return string.Compare(entry0.RelativePath, entry1.RelativePath, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int OnTreeViewComparisonCellFieldPath(int index0, int index1)
|
private int OnTreeViewComparisonCellFieldPath(int index0, int index1)
|
||||||
|
|
|
||||||
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.name));
|
||||||
|
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 }, enabledSelf = false };
|
||||||
|
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
|
||||||
|
|
@ -16,4 +16,39 @@
|
||||||
-unity-font-style: bold;
|
-unity-font-style: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-icon {
|
||||||
|
background-image: url("project://database/Packages/com.module.project-validator/Editor/Icons/editor_project_validator_warning.png?fileID=2800000&guid=5dce0f250980ffb459470fac33dfab59&type=3#editor_project_validator_warning");
|
||||||
|
width: 16px;
|
||||||
|
min-width: 16px;
|
||||||
|
max-width: 16px;
|
||||||
|
max-height: 16px;
|
||||||
|
min-height: 16px;
|
||||||
|
height: 16px;
|
||||||
|
-unity-background-scale-mode: scale-to-fit;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-icon {
|
||||||
|
background-image: url("project://database/Packages/com.module.project-validator/Editor/Icons/editor_project_validator_error.png?fileID=2800000&guid=7b6c61a2cf824b74c87cb49759531c79&type=3#editor_project_validator_error");
|
||||||
|
width: 16px;
|
||||||
|
min-width: 16px;
|
||||||
|
max-width: 16px;
|
||||||
|
max-height: 16px;
|
||||||
|
min-height: 16px;
|
||||||
|
height: 16px;
|
||||||
|
-unity-background-scale-mode: scale-to-fit;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,29 @@
|
||||||
<uie:Toolbar name="toolbar">
|
<uie:Toolbar name="toolbar">
|
||||||
<uie:ToolbarButton text="Run" name="button-run" style="margin-left: 2px;"/>
|
<uie:ToolbarButton text="Run" name="button-run" style="margin-left: 2px;"/>
|
||||||
<uie:ToolbarButton text="Clear" name="button-clear"/>
|
<uie:ToolbarButton text="Clear" name="button-clear"/>
|
||||||
<uie:ToolbarSpacer style="flex-grow: 1;"/>
|
<uie:ToolbarSpacer name="spacing" style="flex-grow: 1;"/>
|
||||||
|
<ui:VisualElement name="status-errors" style="flex-grow: 0; flex-direction: row; align-self: center; margin-left: 4px;">
|
||||||
|
<ui:Label text="9999" name="label-errors" double-click-selects-word="false" triple-click-selects-line="false" display-tooltip-when-elided="false" style="flex-grow: 1; -unity-text-align: middle-center;"/>
|
||||||
|
<ui:VisualElement name="icon" class="error-icon" style="flex-grow: 1;"/>
|
||||||
|
</ui:VisualElement>
|
||||||
|
<ui:VisualElement name="status-warnings" style="flex-grow: 0; flex-direction: row; align-self: center; margin-right: 4px;">
|
||||||
|
<ui:Label text="9999" name="label-warnings" double-click-selects-word="false" triple-click-selects-line="false" display-tooltip-when-elided="false" style="flex-grow: 1; -unity-text-align: middle-center;"/>
|
||||||
|
<ui:VisualElement name="icon" class="warning-icon" style="flex-grow: 1;"/>
|
||||||
|
</ui:VisualElement>
|
||||||
|
<uie:ToolbarSpacer name="spacing" style="flex-grow: 1;"/>
|
||||||
<uie:ToolbarSearchField name="search-field"/>
|
<uie:ToolbarSearchField name="search-field"/>
|
||||||
|
<uie:ToolbarButton text="" name="button-settings" class="toolbar-button-settings"/>
|
||||||
</uie:Toolbar>
|
</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: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">
|
<ui:Columns reorderable="false" primary-column-name="severity">
|
||||||
<ui:Column name="severity" title="Severity" min-width="80px" optional="true"/>
|
<ui:Column name="severity" title="Severity" min-width="80px" optional="true"/>
|
||||||
<ui:Column name="type" title="Type" min-width="42px" width="120px"/>
|
<ui:Column name="type" title="Type" min-width="42px" width="120px"/>
|
||||||
<ui:Column name="asset" title="Asset" optional="true" min-width="80px" width="200px"/>
|
<ui:Column name="asset" title="Asset" optional="true" min-width="80px" width="200px"/>
|
||||||
<ui:Column optional="true" name="scene-path" title="Scene Path" min-width="40px" width="200px"/>
|
<ui:Column optional="true" name="relative-path" title="Path" min-width="40px" width="200px"/>
|
||||||
<ui:Column name="field-path" title="Field Path" min-width="70px" width="200px"/>
|
<ui:Column name="field-path" title="Field Path" min-width="70px" width="200px"/>
|
||||||
<ui:Column optional="true" name="severity-message" title="Message" stretchable="true"/>
|
<ui:Column optional="true" name="severity-message" title="Message" stretchable="true"/>
|
||||||
</ui:Columns>
|
</ui:Columns>
|
||||||
<ui:SortColumnDescriptions/>
|
<ui:SortColumnDescriptions/>
|
||||||
</ui:MultiColumnTreeView>
|
</ui:MultiColumnTreeView>
|
||||||
|
<ui:Image/>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
|
|
|
||||||
45
README.md
45
README.md
|
|
@ -1,15 +1,50 @@
|
||||||
# Description
|
# 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
|
```csharp
|
||||||
public sealed class GameObjectValidatorBrokenPrefab : IGameObjectValidator
|
public sealed class GameObjectValidatorBrokenPrefab : IGameObjectValidator
|
||||||
|
|
@ -22,7 +57,7 @@ public sealed class GameObjectValidatorBrokenPrefab : IGameObjectValidator
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Component Validators
|
### Component Validators
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public sealed class ComponentValidatorMeshCollider : IComponentValidator<MeshCollider>
|
public sealed class ComponentValidatorMeshCollider : IComponentValidator<MeshCollider>
|
||||||
|
|
@ -35,7 +70,7 @@ public sealed class ComponentValidatorMeshCollider : IComponentValidator<MeshCol
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Attribute Validators
|
### Attribute Validators
|
||||||
|
|
||||||
The field attribute:
|
The field attribute:
|
||||||
```csharp
|
```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",
|
"name": "com.module.project-validator",
|
||||||
"version": "0.3.0",
|
"version": "1.0.3",
|
||||||
"displayName": "Module.ProjectValidator",
|
"displayName": "Module.ProjectValidator",
|
||||||
"description": "",
|
"description": "",
|
||||||
"unity": "6000.3",
|
"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 |
117
~Images/editor-project-settings.png.meta
Normal file
117
~Images/editor-project-settings.png.meta
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 094f9567dcf756b468ea41cd471b65d7
|
||||||
|
TextureImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 13
|
||||||
|
mipmaps:
|
||||||
|
mipMapMode: 0
|
||||||
|
enableMipMap: 1
|
||||||
|
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: 0
|
||||||
|
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:
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
Loading…
Add table
Add a link
Reference in a new issue