37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using Sirenix.OdinInspector.Editor.Validation;
|
|
using UnityEngine;
|
|
using VOID.Editor.AttributeValidator;
|
|
using VOID.Generic;
|
|
using VOID.Generic.Triggers;
|
|
|
|
[assembly: RegisterValidator(typeof(DynamicTriggerValidator))]
|
|
|
|
namespace VOID.Editor.AttributeValidator
|
|
{
|
|
public class DynamicTriggerValidator : ValueValidator<IDynamicTrigger>
|
|
{
|
|
protected override void Validate(ValidationResult result)
|
|
{
|
|
if (Value is not Component component) return;
|
|
|
|
ValidateLayer(result, component);
|
|
ValidateCollider(result, component);
|
|
}
|
|
|
|
private void ValidateLayer(ValidationResult result, Component component)
|
|
{
|
|
if (LayerManager.CodeInMask(component.gameObject.layer, LayerManager.Trigger)) return;
|
|
|
|
result.AddError(
|
|
$"This component uses <u>{nameof(IDynamicTrigger)}</u> which requires layer <u>{nameof(LayerManager.Trigger)}</u>!");
|
|
}
|
|
|
|
private void ValidateCollider(ValidationResult result, Component component)
|
|
{
|
|
if (component.GetComponentInChildren<Collider>()) return;
|
|
|
|
result.AddError(
|
|
$"This component uses <u>{nameof(IDynamicTrigger)}</u> which requires at least one <u>collider</u>!");
|
|
}
|
|
}
|
|
} |