1
0
mirror of https://github.com/maxartz15/Validator.git synced 2024-11-14 16:45:35 +01:00
Validator/Editor/Validators/AssetValidator.cs

50 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Validator.Editor
{
public class AssetValidator : IValidator
{
2021-12-29 23:46:52 +01:00
public string MenuName => nameof(AssetValidator);
public Report Validate()
{
2021-12-29 23:46:52 +01:00
Report report = new Report(nameof(AssetValidator));
List<Object> objects = FindAssetsByType<Object>();
for (int i = 0; i < objects.Count; i++)
{
EditorUtility.DisplayProgressBar("AssetValidator", "Validate...", (float)i / objects.Count);
if (objects[i] is IValidatable validatable)
{
2021-12-29 16:18:44 +01:00
validatable.Validate(report);
}
}
EditorUtility.ClearProgressBar();
2021-12-29 16:18:44 +01:00
return report;
}
public static List<T> FindAssetsByType<T>() where T : Object
{
List<T> assets = new List<T>();
string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T)));
for (int i = 0; i < guids.Length; i++)
{
EditorUtility.DisplayProgressBar("AssetValidator", "FindAssetsByType...", (float)i / guids.Length);
string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
T asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
if (asset != null)
{
assets.Add(asset);
}
}
EditorUtility.ClearProgressBar();
return assets;
}
}
}