66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace Artngame.TEM
|
|
{
|
|
public class GroundDust : MonoBehaviour
|
|
{
|
|
public GameObject groundPSObj;
|
|
|
|
public GameObject debugCylinder;
|
|
|
|
public float rotationSpeed = 10f;
|
|
|
|
public float bottomRadius = 15f;
|
|
|
|
public float height = 20f;
|
|
|
|
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()
|
|
{
|
|
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)
|
|
{
|
|
m_Particles[i].remainingLifetime = -1f;
|
|
continue;
|
|
}
|
|
Vector3 position2 = base.transform.position;
|
|
Vector3 vector = position2 - oldCenterPos;
|
|
position += vector;
|
|
float num = dustShape.Evaluate(y / height) * bottomRadius + 0.5f;
|
|
position = TornadoMath.CheckRadius(position, position2, num);
|
|
Vector3 vector2 = position - position2;
|
|
float angle = TornadoMath.GetAngle(vector2.x, vector2.z);
|
|
position = TornadoMath.GetParticlePos(position2, angle, num, rotationSpeed);
|
|
position.y = y;
|
|
m_Particles[i].position = position;
|
|
}
|
|
groundPS.SetParticles(m_Particles, particles);
|
|
}
|
|
}
|
|
}
|