Files
2026-03-04 10:03:45 +08:00

105 lines
2.9 KiB
C#

using UnityEngine;
namespace Artngame.SKYMASTER
{
public class manageParticleRotationSM : MonoBehaviour
{
private ParticleSystem ShurikenParticle;
private ParticleSystemRenderer PrenderS;
public bool StableRollMethod2;
public bool StableRollAllAxis;
private int psize;
private Transform Cam_transf;
private Vector3 Prev_cam_rot;
private ParticleSystem.Particle[] particles;
private void Start()
{
Cam_transf = Camera.main.transform;
Prev_cam_rot = Cam_transf.eulerAngles;
ParticleSystem.MainModule main = GetComponent<ParticleSystem>().main;
psize = main.maxParticles;
ParticleSystem.Particle[] array = new ParticleSystem.Particle[main.maxParticles];
GetComponent<ParticleSystem>().GetParticles(array);
if (GetComponent<ParticleSystem>() != null)
{
PrenderS = base.gameObject.GetComponent<ParticleSystemRenderer>();
ShurikenParticle = GetComponent<ParticleSystem>();
}
if (PrenderS != null)
{
PrenderS.sortMode = ParticleSystemSortMode.Distance;
}
}
private void LateUpdate()
{
float num = Cam_transf.eulerAngles.z - Prev_cam_rot.z;
float y = Cam_transf.eulerAngles.y;
float num2 = y - Prev_cam_rot.y;
if (Mathf.Abs(num2) > 180f)
{
num2 = 360f - Mathf.Abs(num2);
}
float num3 = 0f;
float num4 = 0f;
if (StableRollMethod2)
{
num3 = Mathf.Abs(Vector3.Angle(Cam_transf.forward, Mathf.Sign(Cam_transf.forward.y) * Vector3.up));
num4 = (0f - Mathf.Sign(Cam_transf.forward.y)) * Vector3.Dot(Cam_transf.forward, Mathf.Sign(Cam_transf.forward.y) * Vector3.up);
}
if (particles == null)
{
particles = new ParticleSystem.Particle[ShurikenParticle.main.maxParticles];
}
ShurikenParticle.GetParticles(particles);
for (int i = 0; i < particles.Length; i++)
{
if (StableRollMethod2)
{
if (!StableRollAllAxis)
{
float num5 = Cam_transf.eulerAngles.z - Prev_cam_rot.z;
float y2 = Cam_transf.eulerAngles.y;
if (num5 == 0f && y2 != Prev_cam_rot.y && Mathf.Abs(Vector3.Angle(Cam_transf.forward, Vector3.up)) < 65f)
{
float num6 = y2 - Prev_cam_rot.y;
particles[i].rotation = particles[i].rotation + num6;
}
else if (!(Mathf.Abs(Vector3.Angle(Cam_transf.forward, Vector3.up)) < 45f))
{
particles[i].rotation = particles[i].rotation + num5;
}
}
else if (num == 0f && y != Prev_cam_rot.y && num3 < 65f)
{
particles[i].rotation = particles[i].rotation - num2 * num4;
}
else
{
Mathf.Abs(Vector3.Angle(Cam_transf.forward, Vector3.up));
_ = 45f;
particles[i].rotation = particles[i].rotation + num - num2 * num4;
}
}
if (!(Prev_cam_rot == Cam_transf.eulerAngles))
{
Prev_cam_rot = Cam_transf.eulerAngles;
}
}
if (Prev_cam_rot != Cam_transf.eulerAngles)
{
Prev_cam_rot = Cam_transf.eulerAngles;
}
ShurikenParticle.SetParticles(particles, particles.Length);
}
}
}