using System.Collections.Generic; namespace GameplayIngredients.Interactions { public static class InteractionManager { static List s_Interactives = new List(); public static void RegisterInteractive(Interactive interactive) { s_Interactives.Add(interactive); } public static void RemoveInteractive(Interactive interactive) { s_Interactives.Remove(interactive); } public static void Interact(InteractiveUser user) { foreach(var interactive in GetCandidates(user)) { if (interactive.Interact(user)) break; } } private static Interactive[] GetCandidates(InteractiveUser user) { List candidates = new List(); foreach(var interactive in s_Interactives) { // Filter interactives at user's reach if (interactive.CanInteract(user)) candidates.Add(interactive); } return user.SortCandidates(candidates.ToArray()); } } }