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

80 lines
2.2 KiB
C#

using UnityEngine;
namespace Artngame.TEM
{
public class TornadoDustTop : MonoBehaviour
{
public GameObject groundPSObj;
public GameObject debugCylinder;
public float rotationSpeed = 10f;
public float bottomRadius = 15f;
public float topRadius = 50f;
public float height = 40f;
public float tornadoHeight;
public AnimationCurve dustShape;
private ParticleSystem groundPS;
private ParticleSystem.Particle[] m_Particles;
private Vector3 oldCenterPos;
private void Start()
{
groundPS = groundPSObj.GetComponent<ParticleSystem>();
m_Particles = new ParticleSystem.Particle[groundPS.main.maxParticles];
oldCenterPos = base.transform.position;
}
private void LateUpdate()
{
ParticleSystem.ShapeModule shape = groundPS.shape;
shape.radius = bottomRadius;
debugCylinder.transform.localScale = new Vector3(bottomRadius * 2f, 1f, bottomRadius * 2f);
RotateParticles();
oldCenterPos = base.transform.position;
}
private void RotateParticles()
{
int particles = groundPS.GetParticles(m_Particles);
for (int i = 0; i < particles; i++)
{
Vector3 position = m_Particles[i].position;
float y = position.y;
if (y > height + tornadoHeight + 20f)
{
m_Particles[i].remainingLifetime = -1f;
continue;
}
if (y > height + tornadoHeight)
{
Color32 startColor = m_Particles[i].startColor;
startColor.a = 150;
m_Particles[i].startColor = startColor;
}
Vector3 position2 = base.transform.position;
Vector3 vector = position2 - oldCenterPos;
position += vector;
float num = dustShape.Evaluate((y - tornadoHeight) / height) * (topRadius - bottomRadius) + bottomRadius;
position = TornadoMath.CheckRadius(position, position2, num);
Vector3 vector2 = position - position2;
float angle = TornadoMath.GetAngle(vector2.x, vector2.z);
float num2 = (1f - dustShape.Evaluate((y - tornadoHeight) / height)) * rotationSpeed;
position = TornadoMath.GetParticlePos(position2, angle, num, num2);
position.y = y;
m_Particles[i].position = position;
m_Particles[i].startSize = 150f * dustShape.Evaluate((y - tornadoHeight) / height) + 45f;
}
groundPS.SetParticles(m_Particles, particles);
}
}
}