1
This commit is contained in:
33
Src/Unity/Scripts/Node/MonoConditions.cs
Normal file
33
Src/Unity/Scripts/Node/MonoConditions.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user