mirror of
https://github.com/maxartz15/Validator.git
synced 2025-07-04 14:36:05 +02:00
Compare commits
4 Commits
b13cf47fbf
...
master
Author | SHA1 | Date | |
---|---|---|---|
5b70e24c32 | |||
15808ce035 | |||
8399d043f5 | |||
b4dd8744df |
@ -1,4 +1,10 @@
|
||||
# Change Log:
|
||||
## 0.1.4
|
||||
- Fix attribute validator..?
|
||||
## 0.1.3
|
||||
- Fix attribute validator..?
|
||||
## 0.1.2
|
||||
- ...
|
||||
## 0.1.1
|
||||
- First prototype of Attribute validator.
|
||||
## 0.1.1
|
||||
|
@ -8,18 +8,21 @@ namespace Validator.Editor
|
||||
{
|
||||
public class RequiredAttributeAssetValidator : IValidator
|
||||
{
|
||||
public string MenuName => "Attributes/RequiredAttributeAssetValidator";
|
||||
public string MenuName => nameof(RequiredAttributeAssetValidator);
|
||||
|
||||
private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
||||
|
||||
public Report Validate()
|
||||
{
|
||||
Report report = new Report(nameof(RequiredAttributeAssetValidator));
|
||||
|
||||
List<Object> objects = AssetValidator.FindAssetsByType<Object>();
|
||||
List<Object> objects = ValidatableAssetValidator.FindAssetsByType<Object>();
|
||||
|
||||
for (int i = 0; i < objects.Count; i++)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("RequiredAttributeAssetValidator", "RequiredAttribute...", (float)i / objects.Count);
|
||||
IEnumerable<(FieldInfo FieldInfo, RequiredAttribute Attribute)> fieldsWithRequiredAttribute = from fi in objects[i].GetType().GetFields()
|
||||
|
||||
IEnumerable<(FieldInfo FieldInfo, RequiredAttribute Attribute)> fieldsWithRequiredAttribute = from fi in objects[i].GetType().GetFields(flags)
|
||||
let attr = fi.GetCustomAttributes(typeof(RequiredAttribute), true)
|
||||
where attr.Length == 1
|
||||
select (FieldInfo: fi, Attribute: attr.First() as RequiredAttribute);
|
||||
@ -41,18 +44,20 @@ namespace Validator.Editor
|
||||
|
||||
public class RequiredAttributeSceneValidator : IValidator
|
||||
{
|
||||
public string MenuName => "Attributes/RequiredAttributeSceneValidator";
|
||||
public string MenuName => nameof(RequiredAttributeSceneValidator);
|
||||
|
||||
private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
||||
|
||||
public Report Validate()
|
||||
{
|
||||
Report report = new Report(nameof(RequiredAttributeSceneValidator));
|
||||
|
||||
List<MonoBehaviour> objects = SceneValidator.FindAllObjectsOfType<MonoBehaviour>();
|
||||
List<MonoBehaviour> objects = ValidatableSceneValidator.FindAllObjectsOfType<MonoBehaviour>();
|
||||
|
||||
for (int i = 0; i < objects.Count; i++)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("RequiredAttributeSceneValidator", "RequiredAttribute...", (float)i / objects.Count);
|
||||
IEnumerable<(FieldInfo FieldInfo, RequiredAttribute Attribute)> fieldsWithRequiredAttribute = from fi in objects[i].GetType().GetFields()
|
||||
IEnumerable<(FieldInfo FieldInfo, RequiredAttribute Attribute)> fieldsWithRequiredAttribute = from fi in objects[i].GetType().GetFields(flags)
|
||||
let attr = fi.GetCustomAttributes(typeof(RequiredAttribute), true)
|
||||
where attr.Length == 1
|
||||
select (FieldInfo: fi, Attribute: attr.First() as RequiredAttribute);
|
||||
|
@ -1,57 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Validator.Editor
|
||||
{
|
||||
public class SceneValidator : IValidator
|
||||
{
|
||||
public string MenuName => nameof(SceneValidator);
|
||||
|
||||
public Report Validate()
|
||||
{
|
||||
Report report = new Report(nameof(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;
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,13 +4,13 @@ using UnityEngine;
|
||||
|
||||
namespace Validator.Editor
|
||||
{
|
||||
public class AssetValidator : IValidator
|
||||
public class ValidatableAssetValidator : IValidator
|
||||
{
|
||||
public string MenuName => nameof(AssetValidator);
|
||||
public string MenuName => nameof(ValidatableAssetValidator);
|
||||
|
||||
public Report Validate()
|
||||
{
|
||||
Report report = new Report(nameof(AssetValidator));
|
||||
Report report = new Report(nameof(ValidatableAssetValidator));
|
||||
|
||||
List<Object> objects = FindAssetsByType<Object>();
|
||||
for (int i = 0; i < objects.Count; i++)
|
57
Editor/Validators/ValidatableSceneValidator.cs
Normal file
57
Editor/Validators/ValidatableSceneValidator.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Validator.Editor
|
||||
{
|
||||
public class ValidatableSceneValidator : IValidator
|
||||
{
|
||||
public string MenuName => nameof(ValidatableSceneValidator);
|
||||
|
||||
public Report Validate()
|
||||
{
|
||||
Report report = new Report(nameof(ValidatableSceneValidator));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.vertexcolor.validator",
|
||||
"displayName": "Validator",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.4",
|
||||
"unity": "2019.3",
|
||||
"description": "Unity project validator framework.",
|
||||
"category": "Tool",
|
||||
|
Reference in New Issue
Block a user