-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoolAggregation.cs
More file actions
28 lines (25 loc) · 886 Bytes
/
BoolAggregation.cs
File metadata and controls
28 lines (25 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Linq;
using UnityEngine;
using Xprees.Variables.Base;
namespace Xprees.Variables.Aggregations
{
[CreateAssetMenu(menuName = "Variables/Aggregations/Bool", fileName = "BoolVarAgg")]
public class BoolAggregation : VariableAggregationBaseSO<bool>
{
[SerializeField] protected BoolAggregator aggregator = BoolAggregator.And;
protected override bool AggregateValue(VariableBaseSO<bool>[] variableBases) => aggregator switch
{
BoolAggregator.And => variables.All(v => v.CurrentValue),
BoolAggregator.Or => variables.Any(v => v.CurrentValue),
BoolAggregator.Xor => variables.Aggregate(false, (current, v) => current ^ v.CurrentValue),
_ => throw new ArgumentOutOfRangeException()
};
}
public enum BoolAggregator
{
And,
Or,
Xor,
}
}