using System;
using System.Collections.Generic;
using UnityEngine;
///
/// Check Property is used to validate field using other filds.
///
[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = true)]
public class vCheckPropertyAttribute : PropertyAttribute
{
[Serializable]
public struct CheckValue
{
public string property;
public object value;
public bool isValid => value != null;
public CheckValue(string property, object value)
{
this.property = property;
this.value = value;
}
}
public List checkValues = new List();
public bool hideInInspector;
///
/// Check Property is used to validate field using other filds.
///
/// Properties names separated by "," (comma) Exemple "PropertyA,PropertyB". Only Enum and Boolean is accepted.
/// The values to compare, you need to set all values to compare with all properties
public vCheckPropertyAttribute(string propertyNames, params object[] values)
{
checkValues.Clear();
var _props = propertyNames.Split(',');
for (int i = 0; i < _props.Length; i++)
{
try
{
checkValues.Add(new CheckValue(_props[i], values[i]));
}
catch
{
break;
}
}
}
}