Compare commits
No commits in common. "main" and "0.2.0" have entirely different histories.
50 changed files with 121 additions and 1312 deletions
|
|
@ -10,32 +10,19 @@ 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())
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 595 B |
|
|
@ -1,117 +0,0 @@
|
||||||
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,7 +1,6 @@
|
||||||
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
|
||||||
{
|
{
|
||||||
|
|
@ -12,28 +11,23 @@ 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 relativePath, string fieldPath, Attribute attribute, EValidatorSeverity severity, string message)
|
public void Add(GUID assetGuid, string scenePath, string fieldPath, Attribute attribute, EValidatorSeverity severity, string message)
|
||||||
{
|
{
|
||||||
var type = ProjectValidatorUtility.GetAttributeShortName(attribute);
|
var type = ProjectValidatorUtility.GetAttributeShortName(attribute);
|
||||||
Add(assetGuid, relativePath, fieldPath, type, severity, message);
|
Add(assetGuid, scenePath, fieldPath, type, severity, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(GUID assetGuid, string relativePath, string fieldPath, string type, EValidatorSeverity severity, string message)
|
public void Add(GUID assetGuid, string scenePath, 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),
|
||||||
RelativePath = relativePath,
|
ScenePath = scenePath,
|
||||||
FieldPath = fieldPath,
|
FieldPath = fieldPath,
|
||||||
RelativePathRichText = ProjectValidatorUtility.ApplyRichTextToRelativePath(relativePath),
|
ScenePathRichText = ProjectValidatorUtility.ApplyRichTextToScenePath(scenePath),
|
||||||
FieldPathRichText = ProjectValidatorUtility.ApplyRichTextToFieldPath(fieldPath),
|
FieldPathRichText = ProjectValidatorUtility.ApplyRichTextToFieldPath(fieldPath),
|
||||||
Type = type,
|
Type = type,
|
||||||
Severity = severity,
|
Severity = severity,
|
||||||
|
|
@ -70,17 +64,7 @@ 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))
|
||||||
|
|
@ -89,9 +73,8 @@ namespace Module.ProjectValidator.Editor
|
||||||
mapping = new MappingEntry();
|
mapping = new MappingEntry();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
public bool TryGetSeverityFor(GUID assetGuid, string relativePath, out MappingEntry mapping)
|
public bool TryGetSeverityFor(GUID assetGuid, string scenePath, out MappingEntry mapping)
|
||||||
{
|
{
|
||||||
if (!_assetToSeverityMapping.TryGetValue(assetGuid, out mapping))
|
if (!_assetToSeverityMapping.TryGetValue(assetGuid, out mapping))
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -100,7 +83,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].RelativePath != relativePath || Entries[i].Severity <= mapping.Severity)
|
if (Entries[i].AssetGuid != assetGuid || Entries[i].ScenePath != scenePath || Entries[i].Severity <= mapping.Severity)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mapping = new MappingEntry(Entries[i].Severity, false);
|
mapping = new MappingEntry(Entries[i].Severity, false);
|
||||||
|
|
@ -127,10 +110,10 @@ namespace Module.ProjectValidator.Editor
|
||||||
public GUID AssetGuid;
|
public GUID AssetGuid;
|
||||||
public string AssetName;
|
public string AssetName;
|
||||||
|
|
||||||
public string RelativePath;
|
public string ScenePath;
|
||||||
public string FieldPath;
|
public string FieldPath;
|
||||||
|
|
||||||
public string RelativePathRichText;
|
public string ScenePathRichText;
|
||||||
public string FieldPathRichText;
|
public string FieldPathRichText;
|
||||||
|
|
||||||
public string Type;
|
public string Type;
|
||||||
|
|
@ -141,7 +124,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) ||
|
||||||
RelativePath.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
ScenePath.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,16 +31,9 @@ namespace Module.ProjectValidator.Editor
|
||||||
if (!IsFieldSerializable(fi))
|
if (!IsFieldSerializable(fi))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var fieldAttributes = fi.GetCustomAttributes();
|
var attributes = fi.GetCustomAttributes();
|
||||||
var fieldTypeAttributes = fi.FieldType.GetCustomAttributes();
|
|
||||||
|
|
||||||
foreach (var attribute in fieldAttributes)
|
foreach (var attribute in attributes)
|
||||||
{
|
|
||||||
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);
|
||||||
|
|
@ -171,7 +164,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,7 +1,6 @@
|
||||||
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,8 +10,6 @@ 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 Dictionary<Type, List<AssetValidator>> AssetValidators = new();
|
|
||||||
|
|
||||||
public void AddAttribute(Type type)
|
public void AddAttribute(Type type)
|
||||||
{
|
{
|
||||||
|
|
@ -62,49 +59,6 @@ namespace Module.ProjectValidator.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddGameObject(Type type)
|
|
||||||
{
|
|
||||||
if (type.IsInterface || type.IsAbstract)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var instance = (IGameObjectValidator)FormatterServices.GetUninitializedObject(type);
|
|
||||||
GameObjectValidators.Add(instance);
|
|
||||||
}
|
|
||||||
catch (Exception 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)
|
||||||
{
|
{
|
||||||
return _attributeValidators.TryGetValue(type, out validatorInstance);
|
return _attributeValidators.TryGetValue(type, out validatorInstance);
|
||||||
|
|
@ -114,17 +68,5 @@ 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,36 +1,27 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
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)
|
||||||
settings = (ProjectValidatorSettings)objects[0];
|
return (ProjectValidatorSettings)objects[0];
|
||||||
else
|
|
||||||
settings = CreateInstance<ProjectValidatorSettings>();
|
|
||||||
|
|
||||||
PopulateValidatorList(settings);
|
var settings = CreateInstance<ProjectValidatorSettings>();
|
||||||
InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] { settings }, AssetPath, true);
|
InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] { settings }, AssetPath, true);
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +29,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
[SettingsProvider]
|
[SettingsProvider]
|
||||||
public static SettingsProvider CreateProvider()
|
public static SettingsProvider CreateProvider()
|
||||||
{
|
{
|
||||||
return new SettingsProvider(MenuPath, SettingsScope.Project)
|
return new SettingsProvider("Project/Project Validator", SettingsScope.Project)
|
||||||
{
|
{
|
||||||
label = "Project Validator",
|
label = "Project Validator",
|
||||||
activateHandler = (_, root) =>
|
activateHandler = (_, root) =>
|
||||||
|
|
@ -46,79 +37,16 @@ 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");
|
||||||
var assemblyField = new PropertyField(serializedObject.FindProperty(nameof(assemblies)), "Assemblies");
|
propertyField.RegisterCallback<ChangeEvent<string>>(_ => InternalEditorUtility.SaveToSerializedFileAndForget(new[] { serializedObject.targetObject }, AssetPath, true));
|
||||||
container.Add(assemblyField);
|
propertyField.RegisterValueChangeCallback(_ => InternalEditorUtility.SaveToSerializedFileAndForget(new[] { serializedObject.targetObject }, AssetPath, true));
|
||||||
|
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,9 +1,7 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
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
|
||||||
{
|
{
|
||||||
|
|
@ -31,39 +29,22 @@ 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 assetPath = string.Empty;
|
var assetGuid = new GUID();
|
||||||
|
|
||||||
if (obj is GameObject gameObject)
|
if (obj is GameObject gameObject)
|
||||||
{
|
{
|
||||||
if (gameObject.scene.isLoaded)
|
if (gameObject.scene.isLoaded)
|
||||||
assetPath = gameObject.scene.path;
|
GUID.TryParse(AssetDatabase.AssetPathToGUID(gameObject.scene.path), out assetGuid);
|
||||||
else if (PrefabUtility.IsPartOfPrefabAsset(gameObject))
|
else if (PrefabUtility.IsPartOfPrefabAsset(gameObject))
|
||||||
assetPath = AssetDatabase.GetAssetPath(gameObject);
|
GUID.TryParse(AssetDatabase.AssetPathToGUID(gameObject.scene.path), out assetGuid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assetPath = AssetDatabase.GetAssetPath(obj);
|
GUID.TryParse(AssetDatabase.GetAssetPath(obj), out assetGuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
GUID.TryParse(AssetDatabase.AssetPathToGUID(assetPath), out var assetGuid);
|
|
||||||
return assetGuid;
|
return assetGuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,30 +37,6 @@ 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)
|
|
||||||
{
|
|
||||||
var str = validator.GetType().Name;
|
|
||||||
str = str.Replace("GameObjectValidator", string.Empty);
|
|
||||||
str = ObjectNames.NicifyVariableName(str);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string GetComponentValidatorShortName(object obj)
|
|
||||||
{
|
|
||||||
var str = obj.GetType().Name;
|
|
||||||
str = str.Replace("ComponentValidator", string.Empty);
|
|
||||||
str = ObjectNames.NicifyVariableName(str);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string GetAttributeShortName(Attribute attribute)
|
internal static string GetAttributeShortName(Attribute attribute)
|
||||||
{
|
{
|
||||||
|
|
@ -69,18 +45,23 @@ namespace Module.ProjectValidator.Editor
|
||||||
str = ObjectNames.NicifyVariableName(str);
|
str = ObjectNames.NicifyVariableName(str);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void AppendToRelativePath(GameObject gameObject, ref string relativePath, bool initial)
|
internal static string GetComponentValidatorShortName(object obj)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(relativePath))
|
var str = obj.GetType().Name;
|
||||||
relativePath = gameObject.name;
|
str = str.Replace("ComponentValidator", string.Empty);
|
||||||
else
|
str = ObjectNames.NicifyVariableName(str);
|
||||||
relativePath = initial ? $"{relativePath}{gameObject.name}" : $"{relativePath}/{gameObject.name}";
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void AppendToScenePath(GameObject gameObject, ref string scenePath)
|
||||||
|
{
|
||||||
|
scenePath = string.IsNullOrEmpty(scenePath) ? gameObject.name : $"{scenePath}/{gameObject.name}";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ApplyRichTextToRelativePath(string relativePath)
|
internal static string ApplyRichTextToScenePath(string scenePath)
|
||||||
{
|
{
|
||||||
return relativePath.Replace("/", "<color=#00ff00><b>/</b></color>");
|
return scenePath.Replace("/", "<color=#00ff00><b>/</b></color>");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AppendToFieldPath(FieldInfo fieldInfo, ref string fieldPath)
|
public static void AppendToFieldPath(FieldInfo fieldInfo, ref string fieldPath)
|
||||||
|
|
@ -116,7 +97,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
var scene = SceneManager.GetSceneByPath(assetPath);
|
var scene = SceneManager.GetSceneByPath(assetPath);
|
||||||
|
|
||||||
if (scene.isLoaded && TryFindSceneObjectByPath(scene, entry.RelativePath, out var gameObject))
|
if (scene.isLoaded && TryFindSceneObjectByPath(scene, entry.ScenePath, out var gameObject))
|
||||||
EditorGUIUtility.PingObject(gameObject);
|
EditorGUIUtility.PingObject(gameObject);
|
||||||
else
|
else
|
||||||
EditorGUIUtility.PingObject(asset);
|
EditorGUIUtility.PingObject(asset);
|
||||||
|
|
@ -127,14 +108,14 @@ namespace Module.ProjectValidator.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryFindSceneObjectByPath(Scene scene, string relativePath, out GameObject gameObject)
|
private static bool TryFindSceneObjectByPath(Scene scene, string scenePath, 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 = relativePath.IndexOf('/');
|
var index = scenePath.IndexOf('/');
|
||||||
var rootName = index != -1 ? relativePath[..index] : relativePath;
|
var rootName = index != -1 ? scenePath[..index] : scenePath;
|
||||||
var childPath = index != -1 ? relativePath[(index + 1)..] : string.Empty;
|
var childPath = index != -1 ? scenePath[(index + 1)..] : string.Empty;
|
||||||
|
|
||||||
for (var i = 0; i < rootObjects.Count; i++)
|
for (var i = 0; i < rootObjects.Count; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -204,93 +185,6 @@ 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();
|
||||||
|
|
@ -310,26 +204,25 @@ 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 relativePath = string.Empty;
|
var scenePath = string.Empty;
|
||||||
RebuildSceneInstanceMapping(report, dictMapping, rootObject, assetGuid, relativePath, true);
|
RebuildSceneInstanceMapping(report, dictMapping, rootObject, assetGuid, scenePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
AppendToRelativePath(gameObject, ref relativePath, initial);
|
AppendToScenePath(gameObject, ref scenePath);
|
||||||
|
|
||||||
if (report.TryGetSeverityFor(assetGuid, relativePath, out var mapping))
|
if (report.TryGetSeverityFor(assetGuid, scenePath, 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, relativePath, false);
|
RebuildSceneInstanceMapping(report, dictMapping, transform.GetChild(i).gameObject, assetGuid, scenePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -376,7 +269,6 @@ 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,6 +13,7 @@ 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;
|
||||||
|
|
||||||
|
|
@ -29,7 +30,6 @@ 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();
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
ProjectValidatorUtility.OpenWindow();
|
ProjectValidatorUtility.OpenWindow();
|
||||||
|
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
Debug.Log($"Validator took {stopwatch.Elapsed.TotalMilliseconds}ms");
|
Debug.Log(stopwatch.Elapsed.TotalMilliseconds + "ms");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,19 +55,20 @@ 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(enabled);
|
FetchAllAttributeValidators();
|
||||||
FetchAllComponentValidators(enabled);
|
FetchAllComponentValidators();
|
||||||
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)
|
||||||
|
|
@ -90,72 +91,23 @@ namespace Module.ProjectValidator.Editor
|
||||||
return assemblies.ToArray();
|
return assemblies.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashSet<Type> GetEnabledValidators(ProjectValidatorSettings settings)
|
private static void FetchAllAttributeValidators()
|
||||||
{
|
|
||||||
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++)
|
||||||
{
|
{
|
||||||
if (enabled.Contains(types[i]))
|
_validatorList.AddAttribute(types[i]);
|
||||||
_validatorList.AddAttribute(types[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void FetchAllGameObjectValidators(HashSet<Type> enabled)
|
|
||||||
{
|
|
||||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IGameObjectValidator));
|
|
||||||
|
|
||||||
for (var i = 0; i < types.Count; i++)
|
|
||||||
{
|
|
||||||
if (enabled.Contains(types[i]))
|
|
||||||
_validatorList.AddGameObject(types[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FetchAllComponentValidators(HashSet<Type> enabled)
|
private static void FetchAllComponentValidators()
|
||||||
{
|
{
|
||||||
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++)
|
||||||
{
|
{
|
||||||
if (enabled.Contains(types[i]))
|
_validatorList.AddComponent(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]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,12 +131,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);
|
||||||
|
|
||||||
|
|
@ -192,60 +144,22 @@ 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, true);
|
ValidateGameObject(rootObjects[j], string.Empty, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -268,83 +182,39 @@ 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);
|
||||||
var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
|
Validate(assetGuid, string.Empty, obj, report);
|
||||||
Validate(assetGuid, assetPath, obj, report);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateGameObject(GameObject gameObject, string relativePath, Report report, bool initial)
|
private static void ValidateGameObject(GameObject gameObject, string scenePath, Report report)
|
||||||
{
|
{
|
||||||
ProjectValidatorUtility.AppendToRelativePath(gameObject, ref relativePath, initial);
|
ProjectValidatorUtility.AppendToScenePath(gameObject, ref scenePath);
|
||||||
|
ValidateComponents(gameObject, scenePath, report);
|
||||||
var assetGuid = EditorAssetUtility.GetAssetGuid(gameObject);
|
ValidateChildren(gameObject, scenePath, report);
|
||||||
using var _ = ListPool<ValidatorResult>.Get(out var results);
|
|
||||||
|
|
||||||
for (var i = 0; i < _validatorList.GameObjectValidators.Count; i++)
|
|
||||||
{
|
|
||||||
results.Clear();
|
|
||||||
|
|
||||||
_validatorList.GameObjectValidators[i].Validate(gameObject, results);
|
|
||||||
var type = ProjectValidatorUtility.GetGameObjectValidatorName(_validatorList.GameObjectValidators[i]);
|
|
||||||
|
|
||||||
for (var j = 0; j < results.Count; j++)
|
|
||||||
{
|
|
||||||
var result = results[j];
|
|
||||||
|
|
||||||
if (result.Severity != EValidatorSeverity.Valid)
|
|
||||||
report.Add(assetGuid, relativePath, string.Empty, type, result.Severity, result.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ValidateComponents(gameObject, assetGuid, relativePath, report);
|
|
||||||
ValidateChildren(gameObject, relativePath, report);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateComponents(GameObject gameObject, GUID assetGuid, string relativePath, Report report)
|
private static void ValidateComponents(GameObject gameObject, string scenePath, Report report)
|
||||||
{
|
{
|
||||||
using var _ = ListPool<Component>.Get(out var components);
|
using var _ = ListPool<Component>.Get(out var components);
|
||||||
|
var assetGuid = EditorAssetUtility.GetAssetGuid(gameObject);
|
||||||
gameObject.GetComponents(components);
|
gameObject.GetComponents(components);
|
||||||
|
|
||||||
for (var i = 0; i < components.Count; i++)
|
for (var i = 0; i < components.Count; i++)
|
||||||
{
|
{
|
||||||
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 relativePath, Report report)
|
private static void ValidateChildren(GameObject gameObject, string scenePath, 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, relativePath, report, false);
|
ValidateGameObject(transform.GetChild(i).gameObject, scenePath, report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Validate(GUID assetGuid, string relativePath, object obj, Report report)
|
private static void Validate(GUID assetGuid, string scenePath, object obj, Report report)
|
||||||
{
|
{
|
||||||
var type = obj.GetType();
|
var type = obj.GetType();
|
||||||
|
|
||||||
|
|
@ -352,10 +222,10 @@ namespace Module.ProjectValidator.Editor
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var fieldPath = obj.GetType().Name;
|
var fieldPath = obj.GetType().Name;
|
||||||
Validate(assetGuid, relativePath, fieldPath, obj, entry, report);
|
Validate(assetGuid, scenePath, fieldPath, obj, entry, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Validate(GUID assetGuid, string relativePath, string parentFieldPath, object obj, TypeTree.Entry entry, Report report)
|
private static void Validate(GUID assetGuid, string scenePath, string parentFieldPath, object obj, TypeTree.Entry entry, Report report)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return;
|
return;
|
||||||
|
|
@ -367,7 +237,7 @@ namespace Module.ProjectValidator.Editor
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var component = entry.Components[i];
|
var component = entry.Components[i];
|
||||||
ValidateComponent(component, obj, assetGuid, relativePath, report);
|
ValidateComponent(component, obj, assetGuid, scenePath, report);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
@ -396,13 +266,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, relativePath, fieldPathArrElement, report);
|
ValidateField(field, eObj, assetGuid, scenePath, fieldPathArrElement, report);
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ValidateField(field, value, assetGuid, relativePath, fieldPath, report);
|
ValidateField(field, value, assetGuid, scenePath, fieldPath, report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -423,18 +293,8 @@ 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 Array arr)
|
if (value is IEnumerable<object> ie)
|
||||||
{
|
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -442,13 +302,13 @@ namespace Module.ProjectValidator.Editor
|
||||||
{
|
{
|
||||||
var fieldPathArrElement = fieldPath;
|
var fieldPathArrElement = fieldPath;
|
||||||
ProjectValidatorUtility.AppendToFieldPath(idx, ref fieldPathArrElement);
|
ProjectValidatorUtility.AppendToFieldPath(idx, ref fieldPathArrElement);
|
||||||
Validate(assetGuid, relativePath, fieldPathArrElement, eObj, e.Entry, report);
|
Validate(assetGuid, scenePath, fieldPathArrElement, eObj, e.Entry, report);
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Validate(assetGuid, relativePath, fieldPath, value, e.Entry, report);
|
Validate(assetGuid, scenePath, fieldPath, value, e.Entry, report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -459,15 +319,15 @@ namespace Module.ProjectValidator.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateField(TypeTree.ValidatorField field, object value, GUID assetGuid, string relativePath, string fieldPath, Report report)
|
private static void ValidateField(TypeTree.ValidatorField field, object value, GUID assetGuid, string scenePath, 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, relativePath, fieldPath, field.Attribute, result.Severity, result.Message);
|
report.Add(assetGuid, scenePath, fieldPath, field.Attribute, result.Severity, result.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValidateComponent(TypeTree.ValidatorComponent component, object value, GUID assetGuid, string relativePath, Report report)
|
private static void ValidateComponent(TypeTree.ValidatorComponent component, object value, GUID assetGuid, string scenePath, 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 });
|
||||||
|
|
@ -478,7 +338,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, relativePath, string.Empty, type, result.Severity, result.Message);
|
report.Add(assetGuid, scenePath, string.Empty, type, result.Severity, result.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: ddbf30cd5a674751be0c125c1f4e917b
|
|
||||||
timeCreated: 1779623970
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 2218d247daff44bf84629756b63ea650
|
|
||||||
timeCreated: 1779623986
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
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"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: cfeb4b29a9cd4ea79c1e9325b8122e17
|
|
||||||
timeCreated: 1779627240
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 0aa1d741049f4074bb863b76ed604d07
|
|
||||||
timeCreated: 1779214748
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 2015106b3c9b450e9efb1333e5239033
|
|
||||||
timeCreated: 1779214761
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 982ac4e898cc2ca438e98a2f0034a8d3
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 3115c26bccfe4b1e964f784a3f9fdd55
|
|
||||||
timeCreated: 1779214908
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Module.ProjectValidator.Editor
|
|
||||||
{
|
|
||||||
internal sealed class ComponentValidatorSkinnedMeshRenderer : IComponentValidator<SkinnedMeshRenderer>
|
|
||||||
{
|
|
||||||
public void Validate(SkinnedMeshRenderer component, List<ValidatorResult> results)
|
|
||||||
{
|
|
||||||
var materials = component.sharedMaterials;
|
|
||||||
|
|
||||||
for (var i = 0; i < materials.Length; i++)
|
|
||||||
{
|
|
||||||
if (materials[i] == null)
|
|
||||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, $"Missing material in slot #{i}"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component.sharedMesh == null)
|
|
||||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, "Missing mesh"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 1610561c53a0aa84aaa903e5dde29694
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 45fa253dcfa349d5b1e9bd56ebac7c98
|
|
||||||
timeCreated: 1779133809
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Module.ProjectValidator.Editor
|
|
||||||
{
|
|
||||||
internal sealed class GameObjectValidatorBrokenPrefab : IGameObjectValidator
|
|
||||||
{
|
|
||||||
public void Validate(GameObject gameObject, List<ValidatorResult> results)
|
|
||||||
{
|
|
||||||
if (PrefabUtility.IsPrefabAssetMissing(gameObject))
|
|
||||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, "GameObject is missing prefab asset"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 8fd1dfcd3d564622a918e2175499318d
|
|
||||||
timeCreated: 1779133864
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: b27a4e96523d4d3d97c11b32814f29d3
|
|
||||||
timeCreated: 1779213834
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Module.ProjectValidator.Editor
|
|
||||||
{
|
|
||||||
internal sealed class GameObjectValidatorMissingComponents : IGameObjectValidator
|
|
||||||
{
|
|
||||||
public void Validate(GameObject gameObject, List<ValidatorResult> results)
|
|
||||||
{
|
|
||||||
var count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(gameObject);
|
|
||||||
|
|
||||||
if (count != 0)
|
|
||||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, $"GameObject is missing {count} component(s)"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 66cbc43729ec4e81a9e353e537b3ccf0
|
|
||||||
timeCreated: 1779133947
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
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"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: ca678bbf72fa4c8f8c9b945535aacf44
|
|
||||||
timeCreated: 1779214145
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 727d5de59b004deb8c192337bcee132e
|
|
||||||
timeCreated: 1779628852
|
|
||||||
|
|
@ -8,18 +8,12 @@ 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;
|
||||||
|
|
@ -27,33 +21,23 @@ 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["relative-path"].makeCell = CreateLabel;
|
_treeView.columns["scene-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["relative-path"].bindCell = OnTreeViewBindCellRelativePath;
|
_treeView.columns["scene-path"].bindCell = OnTreeViewBindCellScenePath;
|
||||||
_treeView.columns["field-path"].bindCell = OnTreeViewBindCellFieldPath;
|
_treeView.columns["field-path"].bindCell = OnTreeViewBindCellFieldPath;
|
||||||
|
|
||||||
_treeView.columns["severity"].unbindCell = OnTreeViewUnbindCellSeverity;
|
_treeView.columns["severity"].unbindCell = OnTreeViewUnbindCellSeverity;
|
||||||
|
|
@ -62,7 +46,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["relative-path"].comparison = OnTreeViewComparisonCellRelativePath;
|
_treeView.columns["scene-path"].comparison = OnTreeViewComparisonCellScenePath;
|
||||||
_treeView.columns["field-path"].comparison = OnTreeViewComparisonCellFieldPath;
|
_treeView.columns["field-path"].comparison = OnTreeViewComparisonCellFieldPath;
|
||||||
|
|
||||||
_treeView.selectionChanged += OnTreeViewSelectionChanged;
|
_treeView.selectionChanged += OnTreeViewSelectionChanged;
|
||||||
|
|
@ -76,26 +60,11 @@ namespace Module.ProjectValidator.Editor
|
||||||
|
|
||||||
_list.Clear();
|
_list.Clear();
|
||||||
|
|
||||||
var entries = Report.Active.Entries;
|
for (var i = 0; i < Report.Active.Entries.Count; i++)
|
||||||
var warningCount = 0;
|
|
||||||
var errorCount = 0;
|
|
||||||
|
|
||||||
for (var i = 0; i < entries.Count; i++)
|
|
||||||
{
|
{
|
||||||
_list.Add(new TreeViewItemData<Report.Entry>(i, entries[i]));
|
_list.Add(new TreeViewItemData<Report.Entry>(i, Report.Active.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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,16 +123,9 @@ 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;
|
||||||
|
|
@ -208,11 +170,11 @@ namespace Module.ProjectValidator.Editor
|
||||||
label.text = entry.SeverityResult;
|
label.text = entry.SeverityResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTreeViewBindCellRelativePath(VisualElement ve, int index)
|
private void OnTreeViewBindCellScenePath(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.RelativePathRichText;
|
label.text = entry.ScenePathRichText;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTreeViewBindCellFieldPath(VisualElement ve, int index)
|
private void OnTreeViewBindCellFieldPath(VisualElement ve, int index)
|
||||||
|
|
@ -260,11 +222,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 OnTreeViewComparisonCellRelativePath(int index0, int index1)
|
private int OnTreeViewComparisonCellScenePath(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.RelativePath, entry1.RelativePath, StringComparison.Ordinal);
|
return string.Compare(entry0.ScenePath, entry1.ScenePath, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int OnTreeViewComparisonCellFieldPath(int index0, int index1)
|
private int OnTreeViewComparisonCellFieldPath(int index0, int index1)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: a22633e08b3d4c0fbbea654a8a8cd287
|
|
||||||
timeCreated: 1779637991
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: e6c8cb829f514028b705bf121373c67c
|
|
||||||
timeCreated: 1779638011
|
|
||||||
|
|
@ -16,39 +16,4 @@
|
||||||
-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,29 +2,18 @@
|
||||||
<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 name="spacing" style="flex-grow: 1;"/>
|
<uie:ToolbarSpacer 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="relative-path" title="Path" min-width="40px" width="200px"/>
|
<ui:Column optional="true" name="scene-path" title="Scene 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>
|
||||||
|
|
|
||||||
62
README.md
62
README.md
|
|
@ -1,65 +1,17 @@
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
A tool to help validate data across scenes, prefabs, scriptable objects and assets.
|
A tool to help validate data across scenes, prefabs and scriptable objects.
|
||||||
|
|
||||||

|

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

|

|
||||||

|

|
||||||
|
|
||||||
## Settings
|
## Component Validators
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
## Validators
|
|
||||||
|
|
||||||
### Asset Validators
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
public sealed class AssetValidatorMaterialTexture : IAssetValidator<Material>
|
|
||||||
{
|
|
||||||
public void Validate(Material obj, List<ValidatorResult> results)
|
|
||||||
{
|
|
||||||
if (obj.shader == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var count = obj.shader.GetPropertyCount();
|
|
||||||
|
|
||||||
for (var i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
var propertyType = obj.shader.GetPropertyType(i);
|
|
||||||
|
|
||||||
if (propertyType != ShaderPropertyType.Texture)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var propertyName = obj.shader.GetPropertyName(i);
|
|
||||||
var propertyValue = obj.GetTexture(propertyName);
|
|
||||||
|
|
||||||
if (propertyValue == null)
|
|
||||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"Texture property '{propertyName}' is Null"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Game Object Validators
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
public sealed class GameObjectValidatorBrokenPrefab : IGameObjectValidator
|
|
||||||
{
|
|
||||||
public void Validate(GameObject gameObject, List<ValidatorResult> results)
|
|
||||||
{
|
|
||||||
if (PrefabUtility.IsPrefabAssetMissing(gameObject))
|
|
||||||
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, "GameObject is missing prefab asset"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Component Validators
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
public sealed class ComponentValidatorMeshCollider : IComponentValidator<MeshCollider>
|
public sealed class ComponentValidatorMeshCollider : IComponentValidator<MeshCollider>
|
||||||
{
|
{
|
||||||
public void Validate(MeshCollider component, List<ValidatorResult> results)
|
public void Validate(MeshCollider component, List<ValidatorResult> results)
|
||||||
|
|
@ -70,10 +22,10 @@ public sealed class ComponentValidatorMeshCollider : IComponentValidator<MeshCol
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Attribute Validators
|
## Attribute Validators
|
||||||
|
|
||||||
The field attribute:
|
The field attrribute:
|
||||||
```csharp
|
```
|
||||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
|
||||||
public sealed class RequiredAttribute : Attribute
|
public sealed class RequiredAttribute : Attribute
|
||||||
{
|
{
|
||||||
|
|
@ -93,7 +45,7 @@ public sealed class RequiredAttribute : Attribute
|
||||||
|
|
||||||
The validator implements `IAttributeValidator<T>`, where `T` is the attribute and will automatically be found by the validator.
|
The validator implements `IAttributeValidator<T>`, where `T` is the attribute and will automatically be found by the validator.
|
||||||
|
|
||||||
```csharp
|
```
|
||||||
public sealed class Validator : IAttributeValidator<RequiredAttribute>
|
public sealed class Validator : IAttributeValidator<RequiredAttribute>
|
||||||
{
|
{
|
||||||
public ValidatorResult Validate(RequiredAttribute attribute, object value)
|
public ValidatorResult Validate(RequiredAttribute attribute, object value)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Module.ProjectValidator
|
|
||||||
{
|
|
||||||
public interface IAssetValidator<in T> where T : Object
|
|
||||||
{
|
|
||||||
void Validate(T obj, List<ValidatorResult> results);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 24ee414b7fa14a368a48cab1b608ee3b
|
|
||||||
timeCreated: 1779624012
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Module.ProjectValidator
|
|
||||||
{
|
|
||||||
public interface IGameObjectValidator
|
|
||||||
{
|
|
||||||
void Validate(GameObject gameObject, List<ValidatorResult> results);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: f7513a02611842029edd675cb64989ad
|
|
||||||
timeCreated: 1779133097
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.module.project-validator",
|
"name": "com.module.project-validator",
|
||||||
"version": "1.0.3",
|
"version": "0.2.0",
|
||||||
"displayName": "Module.ProjectValidator",
|
"displayName": "Module.ProjectValidator",
|
||||||
"description": "",
|
"description": "",
|
||||||
"unity": "6000.3",
|
"unity": "6000.3",
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 34 KiB |
|
|
@ -1,117 +0,0 @@
|
||||||
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: 232 KiB |
Loading…
Add table
Add a link
Reference in a new issue