2021-12-27 00:52:50 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Validator.Editor
|
|
|
|
{
|
|
|
|
public class AssetValidator : IValidator
|
|
|
|
{
|
|
|
|
public Report Validate()
|
|
|
|
{
|
2021-12-29 16:18:44 +01:00
|
|
|
Report report = new Report("AssetValidator");
|
2021-12-27 00:52:50 +01:00
|
|
|
|
|
|
|
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);
|
2021-12-27 00:52:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
2021-12-29 16:18:44 +01:00
|
|
|
return report;
|
2021-12-27 00:52:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|