Files
Cielonos/Assets/Scripts/MainGame/Effects/VFX/VFXObject.cs

88 lines
2.8 KiB
C#
Raw Normal View History

2025-12-17 04:19:38 -05:00
using System;
using System.Collections.Generic;
using Cielonos.MainGame.Characters;
using Lean.Pool;
using Sirenix.OdinInspector;
2026-02-13 09:22:11 -05:00
using SLSUtilities.LeanPoolAssistance;
2025-12-17 04:19:38 -05:00
using UnityEngine;
namespace Cielonos.MainGame
{
public class VFXObject : PooledObject
{
[NonSerialized]
public CharacterBase creator;
2025-12-22 18:36:29 -05:00
public bool affectedByCreatorTimeScale = true;
2026-04-18 13:57:19 -04:00
public float DeltaTime => affectedByCreatorTimeScale && creator != null ? creator.selfTimeSm.DeltaTime : Time.deltaTime;
public float TimeScale => affectedByCreatorTimeScale && creator != null ? creator.selfTimeSm.TimeScale : 1f;
2025-12-22 18:36:29 -05:00
2025-12-17 04:19:38 -05:00
public List<ParticleSystem> particles = new List<ParticleSystem>();
2026-05-10 11:47:55 -04:00
[Tooltip("需要特殊标记的部分")]
public Dictionary<string, GameObject> parts = new Dictionary<string, GameObject>();
2025-12-17 04:19:38 -05:00
2025-12-22 18:36:29 -05:00
[NonSerialized] private List<ParticleSystem.MainModule> particleMainModules;
2025-12-17 04:19:38 -05:00
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;
}
2026-05-23 08:27:50 -04:00
public static GameObject Spawn(GameObject vfxPrefab, CharacterBase creator, Vector3 position,
Quaternion rotation, Transform parent = null)
2025-12-17 04:19:38 -05:00
{
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();
2025-12-22 18:36:29 -05:00
2026-05-23 08:27:50 -04:00
particleMainModules = new List<ParticleSystem.MainModule>();
foreach (var ps in particles)
2025-12-17 04:19:38 -05:00
{
2026-05-23 08:27:50 -04:00
particleMainModules.Add(ps.main);
2025-12-17 04:19:38 -05:00
}
}
[Button("Collect Particles")]
private void CollectParticles()
{
particles.Clear();
ParticleSystem[] foundParticles = GetComponentsInChildren<ParticleSystem>();
foreach (var ps in foundParticles)
{
particles.Add(ps);
}
}
2025-12-22 18:36:29 -05:00
2025-12-17 04:19:38 -05:00
protected override void Update()
{
2026-04-18 13:57:19 -04:00
UpdateTimer(DeltaTime);
2025-12-22 18:36:29 -05:00
if (affectedByCreatorTimeScale)
{
2026-04-18 13:57:19 -04:00
particleMainModules.ForEach(main => main.simulationSpeed = TimeScale);
2025-12-22 18:36:29 -05:00
}
2025-12-17 04:19:38 -05:00
}
2025-12-22 18:36:29 -05:00
2025-12-17 04:19:38 -05:00
public void SetCreator(CharacterBase character)
{
creator = character;
}
}
}