This commit is contained in:
CortexCore
2025-03-09 13:38:23 +08:00
parent 8261a458e2
commit 18239a5ae4
67 changed files with 8573 additions and 831 deletions

View 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();
}
}
}