1
0
mirror of https://github.com/maxartz15/Validator.git synced 2024-11-14 00:25:34 +01:00
Validator/README.md

48 lines
1.3 KiB
Markdown
Raw Normal View History

# Validator
2021-12-26 02:15:37 +01:00
2022-01-01 20:33:46 +01:00
![ValidatorWindow](Documentation~/Images/ValidatorWindow_01.png)
Unity project validator framework.
## Getting Started
2022-01-01 20:33:46 +01:00
Add a custom validate check using the `IValidatable` interface:
```C#
using Validator;
public class MyBehaviour : MonoBehaviour, IValidatable
{
[SerializeField] private float startHealth = 10; // If someone was to put it to low <= 0, it would be invalid.
#if UNITY_EDITOR
public void Validate(Report report)
{
2022-01-02 15:21:39 +01:00
// Check if health is valid.
if(startHealth <= 0)
{
2022-01-02 15:21:39 +01:00
// If not, log it.
report.Log(this, WarningType.Warning, ReportCategories.Design, $"{nameof(startHealth)} is to low", $"Make value > 0");
}
}
#endif
}
```
2021-12-26 02:15:37 +01:00
2022-01-01 20:33:46 +01:00
Add a validate check using `[Required]` attribute:
```C#
[SerializeField, Required] private GameObject playerPrefab = null; // If someone forgets to assign it, it would be invalid.
```
2021-12-26 02:15:37 +01:00
2022-01-01 20:33:46 +01:00
Open Validator Window:
> Window -> General -> Validator
2021-12-26 02:15:37 +01:00
2022-01-01 20:33:46 +01:00
Run the validator:
> Click the 'run/play' button and wait for the report to be generated.
2021-12-26 02:15:37 +01:00
2022-01-01 20:33:46 +01:00
## Install
[Installing from a Git URL](https://docs.unity3d.com/Manual/upm-ui-giturl.html)
2021-12-26 02:15:37 +01:00
## LICENSE
2022-01-02 15:21:39 +01:00
Overall package is licensed under [MIT](/LICENSE.md), unless otherwise noted in the [3rd party licenses](/THIRD%20PARTY%20NOTICES.md) file and/or source code.