1
This commit is contained in:
63
Src/Unity/Scripts/VFX/VFXService.cs
Normal file
63
Src/Unity/Scripts/VFX/VFXService.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
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<ScriptableImpact> _scriptableImpacts;
|
||||
|
||||
public VFXService(IEntitiesService entitiesService)
|
||||
{
|
||||
_entitiesService = entitiesService;
|
||||
_scriptableImpacts = _entitiesService.QueryComponents<ScriptableImpact>();
|
||||
}
|
||||
|
||||
public AudioClip GetAudioClip(IReadOnlyCollection<string> tags)
|
||||
{
|
||||
var bestMatches = Search(tags);
|
||||
|
||||
return bestMatches.AudioClip;
|
||||
}
|
||||
|
||||
public Transform GetPrefab(IReadOnlyCollection<string> tags)
|
||||
{
|
||||
var bestMatches = Search(tags);
|
||||
return bestMatches.Prefab;
|
||||
}
|
||||
|
||||
private ScriptableImpact Search(IReadOnlyCollection<string> tags)
|
||||
{
|
||||
var maxPoint = 0;
|
||||
var max = new HashSet<ScriptableImpact>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user