using System; using System.Collections.Generic; using UnityEngine; [Serializable] public struct Condition { [Serializable] struct ConditionElement { public T condition; public bool mustMatch; } [SerializeField] ConditionElement[] conditions; [SerializeField] int shouldMatchCount; public bool CheckCondition(IReadOnlyList currentState) { if(shouldMatchCount == 0) shouldMatchCount = conditions.Length; var currentRemainConditions = new List(); int mustMatchCount = 0; for(int i = 0; i < conditions.Length; i++) { currentRemainConditions.Add(conditions[i]); if (conditions[i].mustMatch) mustMatchCount++; } int currentMatchCount = 0; for (int i = 0; i < currentState.Count; i++) { int targetIdx = currentRemainConditions.FindIndex(x => x.condition.Equals(currentState[i])); if (targetIdx == -1) continue; if(currentRemainConditions[targetIdx].mustMatch) currentMatchCount--; currentMatchCount++; currentRemainConditions.RemoveAt(targetIdx); } return mustMatchCount <= 0 && currentMatchCount >= shouldMatchCount; } }