mirror of
https://github.com/maxartz15/Validator.git
synced 2024-11-14 00:25:34 +01:00
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
|
using System.Collections.Generic;
|
||
|
using UnityEditor;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
|
||
|
namespace Validator.Editor
|
||
|
{
|
||
|
public class SceneValidator : IValidator
|
||
|
{
|
||
|
public Report Validate()
|
||
|
{
|
||
|
Report report = new Report("SceneValidator");
|
||
|
|
||
|
List<IValidatable> objects = FindAllObjectsOfType<IValidatable>();
|
||
|
for (int i = 0; i < objects.Count; i++)
|
||
|
{
|
||
|
EditorUtility.DisplayProgressBar("SceneValidator", "Validate...", (float)i / objects.Count);
|
||
|
|
||
|
objects[i].Validate(report);
|
||
|
}
|
||
|
EditorUtility.ClearProgressBar();
|
||
|
|
||
|
return report;
|
||
|
}
|
||
|
|
||
|
private static List<GameObject> GetAllRootGameObjects()
|
||
|
{
|
||
|
List<GameObject> gameObjects = new List<GameObject>();
|
||
|
|
||
|
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||
|
{
|
||
|
EditorUtility.DisplayProgressBar("SceneValidator", "GetAllRootGameObjects...", (float)i / SceneManager.sceneCount);
|
||
|
gameObjects.AddRange(SceneManager.GetSceneAt(i).GetRootGameObjects());
|
||
|
}
|
||
|
EditorUtility.ClearProgressBar();
|
||
|
|
||
|
return gameObjects;
|
||
|
}
|
||
|
|
||
|
private static List<T> FindAllObjectsOfType<T>()
|
||
|
{
|
||
|
List<T> objects = new List<T>();
|
||
|
|
||
|
List<GameObject> gameObjects = GetAllRootGameObjects();
|
||
|
for (int i = 0; i < gameObjects.Count; i++)
|
||
|
{
|
||
|
EditorUtility.DisplayProgressBar("SceneValidator", "FindAllObjectsOfType...", (float)i / gameObjects.Count);
|
||
|
objects.AddRange(gameObjects[i].GetComponentsInChildren<T>(true));
|
||
|
}
|
||
|
EditorUtility.ClearProgressBar();
|
||
|
|
||
|
return objects;
|
||
|
}
|
||
|
}
|
||
|
}
|