using System; using System.Collections; using System.Collections.Generic; using System.Linq; using BITKit; using BITKit.Entities; using Net.BITKit.Impact; using UnityEngine; namespace Net.BITKit.VFX { public class VFXService { private readonly IEntitiesService _entitiesService; private readonly IReadOnlyCollection _scriptableImpacts; public VFXService(IEntitiesService entitiesService) { _entitiesService = entitiesService; _scriptableImpacts = _entitiesService.QueryComponents().ToArray(); } public AudioClip GetAudioClip(IReadOnlyCollection tags) { var bestMatches = Search(tags); return bestMatches.AudioClip; } public Transform GetPrefab(IReadOnlyCollection tags) { var bestMatches = Search(tags); return bestMatches.Prefab; } private ScriptableImpact Search(IReadOnlyCollection tags) { var maxPoint = 0; var max = new HashSet(); foreach (var impact in _scriptableImpacts) { var point = impact.Tags.Intersect(tags).Count(); if (point > maxPoint) { maxPoint = point; max.Clear(); max.Add(impact); }else if (point == maxPoint) { max.Add(impact); } } if (max.Count is 1) { return max.First(); } return max.OrderByDescending(x => x.Priority).First(); } } }