34 lines
803 B
C#
34 lines
803 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace BITKit
|
|
{
|
|
public sealed class MonoConditions : MonoBehaviour,ICondition
|
|
{
|
|
[SerializeReference,SubclassSelector] private ICondition[] conditions;
|
|
[SerializeReference,SubclassSelector] private IReference[] customReason;
|
|
public bool OnCheck() => conditions.All(OnCheck);
|
|
|
|
public string Reason
|
|
{
|
|
get
|
|
{
|
|
return customReason switch
|
|
{
|
|
not null when customReason.Length > 0 => string.Join("\n", customReason.Select(x => x.Value)),
|
|
_ => string.Join("\n", conditions.Where(OnCheck))
|
|
};
|
|
}
|
|
}
|
|
private static bool OnCheck(ICondition condition) => condition.Allow;
|
|
|
|
[BIT]
|
|
private void ManualCheck()
|
|
{
|
|
Debug.Log(OnCheck() ? "Success" : Reason);
|
|
}
|
|
}
|
|
}
|