88 lines
2.8 KiB
C#
88 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Cielonos.MainGame.Characters;
|
|
using Lean.Pool;
|
|
using Sirenix.OdinInspector;
|
|
using SLSUtilities.LeanPoolAssistance;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame
|
|
{
|
|
public class VFXObject : PooledObject
|
|
{
|
|
[NonSerialized]
|
|
public CharacterBase creator;
|
|
|
|
public bool affectedByCreatorTimeScale = true;
|
|
public float DeltaTime => affectedByCreatorTimeScale && creator != null ? creator.selfTimeSm.DeltaTime : Time.deltaTime;
|
|
public float TimeScale => affectedByCreatorTimeScale && creator != null ? creator.selfTimeSm.TimeScale : 1f;
|
|
|
|
public List<ParticleSystem> particles = new List<ParticleSystem>();
|
|
[Tooltip("需要特殊标记的部分")]
|
|
public Dictionary<string, GameObject> parts = new Dictionary<string, GameObject>();
|
|
|
|
[NonSerialized] private List<ParticleSystem.MainModule> particleMainModules;
|
|
|
|
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()
|
|
{
|
|
UpdateTimer(DeltaTime);
|
|
if (affectedByCreatorTimeScale)
|
|
{
|
|
particleMainModules.ForEach(main => main.simulationSpeed = TimeScale);
|
|
}
|
|
}
|
|
|
|
public void SetCreator(CharacterBase character)
|
|
{
|
|
creator = character;
|
|
}
|
|
}
|
|
} |