Second commit
This commit is contained in:
commit
36840f3ad4
999 files changed
+61364
No files matched your search
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.Particles
|
||||
{
|
||||
public interface IParticleService
|
||||
{
|
||||
UniTaskVoid EmitOneShot(ParticlePartitionIDPair pair, int particleCount, Vector3 position, Quaternion rotation);
|
||||
UniTaskVoid EmitTillCancelled(ParticlePartitionIDPair pair, CancellationToken token, Vector3 position, Quaternion rotation);
|
||||
}
|
||||
|
||||
public class ParticleService : IParticleService
|
||||
{
|
||||
[Inject] private IParticlePoolManagerForService _poolManagerForService;
|
||||
[Inject] private IParticleLoader _particleLoader;
|
||||
|
||||
public async UniTaskVoid EmitOneShot(ParticlePartitionIDPair pair, int particleCount, Vector3 position, Quaternion rotation)
|
||||
{
|
||||
var particleSystem = _poolManagerForService.GetParticleSystem(pair.ParticlePartition, pair.ID);
|
||||
|
||||
particleSystem.transform.position = position;
|
||||
particleSystem.transform.rotation = rotation;
|
||||
|
||||
particleSystem.Emit(particleCount);
|
||||
|
||||
await UniTask.WaitWhile(() => particleSystem.particleCount > 0);
|
||||
|
||||
_poolManagerForService.ReleaseParticleSystem(pair.ParticlePartition, pair.ID, particleSystem);
|
||||
}
|
||||
public async UniTaskVoid EmitTillCancelled(ParticlePartitionIDPair pair, CancellationToken token, Vector3 position, Quaternion rotation)
|
||||
{
|
||||
var particleSystem = _poolManagerForService.GetParticleSystem(pair.ParticlePartition, pair.ID);
|
||||
|
||||
particleSystem.transform.position = position;
|
||||
particleSystem.transform.rotation = rotation;
|
||||
|
||||
particleSystem.Play();
|
||||
try
|
||||
{
|
||||
await UniTask.WaitUntilCanceled(cancellationToken: token);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
particleSystem.Stop();
|
||||
|
||||
_poolManagerForService.ReleaseParticleSystem(pair.ParticlePartition, pair.ID, particleSystem);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user