137 lines
3.6 KiB
C#
137 lines
3.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Artngame.TEM
|
|
{
|
|
public class TornadoDust : MonoBehaviour
|
|
{
|
|
public GameObject groundPSObj;
|
|
|
|
public GameObject debugCylinder;
|
|
|
|
public GameObject debugSphere;
|
|
|
|
public float rotationSpeed = 10f;
|
|
|
|
public float radius = 15f;
|
|
|
|
public float tornadoHeight;
|
|
|
|
public float topRadius;
|
|
|
|
[NonSerialized]
|
|
public Transform[] skeletonPiecesArray;
|
|
|
|
private Vector3[] lastSkeletonPiecesPosArray;
|
|
|
|
[NonSerialized]
|
|
public AnimationCurve tornadoShape;
|
|
|
|
[NonSerialized]
|
|
public Transform tornadoTrans;
|
|
|
|
private ParticleSystem groundPS;
|
|
|
|
private ParticleSystem.Particle[] m_Particles;
|
|
|
|
private float lastRotY;
|
|
|
|
public bool isJunk;
|
|
|
|
private void Start()
|
|
{
|
|
groundPS = groundPSObj.GetComponent<ParticleSystem>();
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (lastSkeletonPiecesPosArray == null)
|
|
{
|
|
lastSkeletonPiecesPosArray = new Vector3[skeletonPiecesArray.Length];
|
|
for (int i = 0; i < skeletonPiecesArray.Length; i++)
|
|
{
|
|
lastSkeletonPiecesPosArray[i] = skeletonPiecesArray[i].position;
|
|
}
|
|
}
|
|
Vector3 position = skeletonPiecesArray[skeletonPiecesArray.Length - 1].position;
|
|
position.y = 0f;
|
|
base.transform.position = position;
|
|
debugCylinder.transform.localScale = new Vector3(radius * 2f, 1f, radius * 2f);
|
|
m_Particles = new ParticleSystem.Particle[groundPS.main.maxParticles];
|
|
RotateParticles();
|
|
for (int j = 0; j < skeletonPiecesArray.Length; j++)
|
|
{
|
|
lastSkeletonPiecesPosArray[j] = skeletonPiecesArray[j].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 > tornadoHeight)
|
|
{
|
|
m_Particles[i].remainingLifetime = -1f;
|
|
continue;
|
|
}
|
|
int num = FindIndex(position);
|
|
Vector3 position2 = skeletonPiecesArray[num].position;
|
|
Vector3 vector = position2;
|
|
if (num != skeletonPiecesArray.Length - 1)
|
|
{
|
|
Vector3 position3 = skeletonPiecesArray[num + 1].position;
|
|
vector = TornadoMath.CalculateProgress(position2, position3, position) * (position3 - position2) + position2;
|
|
}
|
|
Vector3 vector2 = lastSkeletonPiecesPosArray[num];
|
|
Vector3 vector3 = vector2;
|
|
if (num != skeletonPiecesArray.Length - 1)
|
|
{
|
|
Vector3 vector4 = lastSkeletonPiecesPosArray[num + 1];
|
|
vector3 = TornadoMath.CalculateProgress(vector2, vector4, position) * (vector4 - vector2) + vector2;
|
|
}
|
|
Vector3 vector5 = vector - vector3;
|
|
position += vector5;
|
|
float num2 = tornadoShape.Evaluate(y / tornadoHeight) * topRadius + 0f;
|
|
if (isJunk)
|
|
{
|
|
num2 += 12f;
|
|
}
|
|
position = TornadoMath.CheckRadius(position, vector, num2);
|
|
Vector3 vector6 = position - vector;
|
|
float angle = TornadoMath.GetAngle(vector6.x, vector6.z);
|
|
position = TornadoMath.GetParticlePos(vector, angle, num2, rotationSpeed);
|
|
position.y = y;
|
|
m_Particles[i].position = position;
|
|
if (!isJunk)
|
|
{
|
|
m_Particles[i].startSize = 10f + 35f * tornadoShape.Evaluate(y / tornadoHeight);
|
|
}
|
|
}
|
|
groundPS.SetParticles(m_Particles, particles);
|
|
}
|
|
|
|
public int FindIndex(Vector3 particlePos)
|
|
{
|
|
int num = 0;
|
|
float num2 = float.PositiveInfinity;
|
|
for (int i = 0; i < skeletonPiecesArray.Length; i++)
|
|
{
|
|
float num3 = Mathf.Abs(skeletonPiecesArray[i].position.y - particlePos.y);
|
|
if (num3 < num2)
|
|
{
|
|
num2 = num3;
|
|
num = i;
|
|
}
|
|
}
|
|
if (particlePos.y < skeletonPiecesArray[num].position.y)
|
|
{
|
|
num--;
|
|
}
|
|
return Mathf.Clamp(num, 0, skeletonPiecesArray.Length - 1);
|
|
}
|
|
}
|
|
}
|