Initial Commit
This commit is contained in:
commit
ee5c2f922d
2255 changed files with 547750 additions and 0 deletions
36
Assets/Scripts/Util/ParticleSystemFactory.cs
Normal file
36
Assets/Scripts/Util/ParticleSystemFactory.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using Zenject;
|
||||
using Hash128 = Unity.Entities.Hash128;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public class ParticleSystemFactory : IFactory<Hash128, AsyncOperationWrapper<GameObject>>
|
||||
{
|
||||
private readonly Dictionary<Hash128, AsyncOperationWrapper<GameObject>> loadingSystems =
|
||||
new Dictionary<Hash128, AsyncOperationWrapper<GameObject>>();
|
||||
|
||||
private readonly Dictionary<Hash128, ParticleSystem> particleSystems = new Dictionary<Hash128, ParticleSystem>();
|
||||
|
||||
public AsyncOperationWrapper<GameObject> Create(Hash128 param)
|
||||
{
|
||||
if (particleSystems.TryGetValue(param, out var system))
|
||||
{
|
||||
return new AsyncOperationWrapper<GameObject>(system.gameObject);
|
||||
}
|
||||
if (loadingSystems.TryGetValue(param, out var systemLoading))
|
||||
{
|
||||
return systemLoading;
|
||||
}
|
||||
systemLoading = new AsyncOperationWrapper<GameObject>(Addressables.InstantiateAsync(param.ToString()));
|
||||
systemLoading.Completed += operation =>
|
||||
{
|
||||
loadingSystems.Remove(param);
|
||||
particleSystems.Add(param, operation.Result.GetComponent<ParticleSystem>());
|
||||
};
|
||||
loadingSystems.Add(param, systemLoading);
|
||||
return systemLoading;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue