更新
This commit is contained in:
@@ -22,12 +22,12 @@ namespace Cielonos.MainGame
|
||||
public partial class VFXData
|
||||
{
|
||||
//Runtime
|
||||
|
||||
[NonSerialized]
|
||||
private Transform executorTransform;
|
||||
[NonSerialized] private CharacterBase executor;
|
||||
[NonSerialized] private Transform executorTransform;
|
||||
|
||||
public void Initialize(CharacterBase character)
|
||||
{
|
||||
executor = character;
|
||||
executorTransform = character.transform;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Cielonos.MainGame
|
||||
VFXUnit vfxUnit = Get(vfxName);
|
||||
|
||||
Transform startTransform = overrideStartTransform ?? executorTransform;
|
||||
GameObject vfxInstance = LeanPool.Spawn(vfxUnit.mainVFX, startTransform);
|
||||
GameObject vfxInstance = VFXObject.Spawn(vfxUnit.mainVFX, executor, startTransform);
|
||||
Transform vfxTransform = vfxInstance.transform;
|
||||
|
||||
vfxTransform.localPosition = vfxUnit.localPosition;
|
||||
@@ -53,12 +53,12 @@ namespace Cielonos.MainGame
|
||||
|
||||
public GameObject SpawnMuzzleVFX(string effectName, Transform muzzleTransform)
|
||||
{
|
||||
return LeanPool.Spawn(Get(effectName).muzzleVFX, muzzleTransform);
|
||||
return VFXObject.Spawn(Get(effectName).muzzleVFX, executor, muzzleTransform);
|
||||
}
|
||||
|
||||
public GameObject SpawnHitVFX(string effectName, Vector3 hitPosition)
|
||||
{
|
||||
return LeanPool.Spawn(Get(effectName).muzzleVFX, hitPosition, Quaternion.identity);
|
||||
return VFXObject.Spawn(Get(effectName).muzzleVFX, executor, hitPosition, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
87
Assets/Scripts/MainGame/Effects/VFXObject.cs
Normal file
87
Assets/Scripts/MainGame/Effects/VFXObject.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cielonos.MainGame.Characters;
|
||||
using Lean.Pool;
|
||||
using Sirenix.OdinInspector;
|
||||
using SLSFramework.LeanPoolAssistance;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public class VFXObject : PooledObject
|
||||
{
|
||||
[NonSerialized]
|
||||
public CharacterBase creator;
|
||||
|
||||
public List<ParticleSystem> particles = new List<ParticleSystem>();
|
||||
|
||||
[NonSerialized]
|
||||
public List<ParticleSystem.MainModule> particleMainModules = new List<ParticleSystem.MainModule>();
|
||||
|
||||
public static GameObject Spawn(GameObject vfxPrefab, CharacterBase creator, Transform parent = null)
|
||||
{
|
||||
VFXObject vfxObject = LeanPool.Spawn(vfxPrefab, parent).GetComponent<VFXObject>();
|
||||
vfxObject.SetCreator(creator);
|
||||
return vfxObject.gameObject;
|
||||
}
|
||||
|
||||
public static GameObject Spawn(GameObject vfxPrefab, CharacterBase creator, Vector3 position, Quaternion rotation, Transform parent = null)
|
||||
{
|
||||
VFXObject vfxObject = LeanPool.Spawn(vfxPrefab, position, rotation, parent).GetComponent<VFXObject>();
|
||||
vfxObject.SetCreator(creator);
|
||||
return vfxObject.gameObject;
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
CollectParticles();
|
||||
}
|
||||
|
||||
public override void OnSpawn()
|
||||
{
|
||||
if (spawnExecuted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.OnSpawn();
|
||||
particleMainModules = new List<ParticleSystem.MainModule>();
|
||||
foreach (var ps in particles)
|
||||
{
|
||||
particleMainModules.Add(ps.main);
|
||||
}
|
||||
}
|
||||
|
||||
[Button("Collect Particles")]
|
||||
private void CollectParticles()
|
||||
{
|
||||
particles.Clear();
|
||||
|
||||
ParticleSystem[] foundParticles = GetComponentsInChildren<ParticleSystem>();
|
||||
foreach (var ps in foundParticles)
|
||||
{
|
||||
particles.Add(ps);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
float deltaTime = Time.deltaTime;
|
||||
float timeScale = 1f;
|
||||
|
||||
if (creator != null)
|
||||
{
|
||||
deltaTime = creator.selfTimeSm.DeltaTime;
|
||||
timeScale = creator.selfTimeSm.timeScaleCoefficient.Value;
|
||||
}
|
||||
|
||||
UpdateTimer(deltaTime);
|
||||
particleMainModules.ForEach(main => main.simulationSpeed = timeScale);
|
||||
}
|
||||
|
||||
public void SetCreator(CharacterBase character)
|
||||
{
|
||||
creator = character;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/MainGame/Effects/VFXObject.cs.meta
Normal file
2
Assets/Scripts/MainGame/Effects/VFXObject.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5dc3f30af6da99e4aa3cece3b17619f8
|
||||
Reference in New Issue
Block a user