360 lines
12 KiB
C#
360 lines
12 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
public class ParticleCollisionsSKYMASTER : MonoBehaviour
|
|
{
|
|
public GameObject ParticlePOOL;
|
|
|
|
private ParticlePropagationSKYMASTER Propagator;
|
|
|
|
private ParticleCollisionEvent[][] collisionEvents;
|
|
|
|
public float Flame_force = 0.5f;
|
|
|
|
private Transform p11Transform;
|
|
|
|
public List<GameObject> Systems_To_override;
|
|
|
|
private List<ParticlePropagationSKYMASTER> systems_To_override;
|
|
|
|
public float cut_off_dist = 0.1f;
|
|
|
|
public bool inner_particle_collision;
|
|
|
|
public GameObject thrower_to_check;
|
|
|
|
public GameObject Collider_OBJ;
|
|
|
|
public List<GameObject> Gameobj_instances;
|
|
|
|
public float min_check_dist = 10f;
|
|
|
|
public int divide_factor = 10;
|
|
|
|
private ParticleSystem.Particle[] ParticleList;
|
|
|
|
public ParticleSystem p11;
|
|
|
|
public bool end_of_life;
|
|
|
|
public float life_factor_upper = 0.8f;
|
|
|
|
public float life_factor_lower = 0.1f;
|
|
|
|
public float min_source_dist = 5f;
|
|
|
|
public bool is_fire;
|
|
|
|
public bool is_ice;
|
|
|
|
public bool enable_LocalWind;
|
|
|
|
public bool enable_flyaway;
|
|
|
|
public bool Overide_Color;
|
|
|
|
public Color New_Color = Color.black;
|
|
|
|
private void Start()
|
|
{
|
|
p11 = base.gameObject.GetComponent<ParticleSystem>();
|
|
p11Transform = base.gameObject.transform;
|
|
if (ParticlePOOL != null)
|
|
{
|
|
Propagator = ParticlePOOL.GetComponent(typeof(ParticlePropagationSKYMASTER)) as ParticlePropagationSKYMASTER;
|
|
}
|
|
collisionEvents = new ParticleCollisionEvent[1][];
|
|
if (Gameobj_instances != null)
|
|
{
|
|
Gameobj_instances.Clear();
|
|
}
|
|
systems_To_override = new List<ParticlePropagationSKYMASTER>();
|
|
if (Systems_To_override != null && Systems_To_override.Count > 0)
|
|
{
|
|
for (int i = 0; i < Systems_To_override.Count; i++)
|
|
{
|
|
systems_To_override.Add(Systems_To_override[i].GetComponent(typeof(ParticlePropagationSKYMASTER)) as ParticlePropagationSKYMASTER);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!inner_particle_collision)
|
|
{
|
|
return;
|
|
}
|
|
if (p11 == null)
|
|
{
|
|
p11 = base.gameObject.GetComponent<ParticleSystem>();
|
|
p11Transform = base.gameObject.transform;
|
|
}
|
|
ParticleList = new ParticleSystem.Particle[p11.particleCount];
|
|
p11.GetParticles(ParticleList);
|
|
int num = 0;
|
|
for (int i = 0; i < ParticleList.Length; i += divide_factor)
|
|
{
|
|
if (Gameobj_instances.Count < ParticleList.Length / divide_factor)
|
|
{
|
|
GameObject gameObject = Object.Instantiate(Collider_OBJ, ParticleList[i].position, Quaternion.identity);
|
|
Gameobj_instances.Add(gameObject);
|
|
gameObject.transform.position = ParticleList[i].position;
|
|
gameObject.transform.parent = base.gameObject.transform;
|
|
}
|
|
if (num < Gameobj_instances.Count)
|
|
{
|
|
Gameobj_instances[num].transform.position = ParticleList[i].position;
|
|
if (end_of_life)
|
|
{
|
|
if ((ParticleList[i].remainingLifetime < life_factor_upper * ParticleList[i].startLifetime) & (ParticleList[i].remainingLifetime > life_factor_lower * ParticleList[i].startLifetime) & (Vector3.Distance(ParticleList[i].position, p11Transform.position) > min_source_dist) & p11.emission.enabled)
|
|
{
|
|
Gameobj_instances[num].GetComponent<Collider>().enabled = true;
|
|
}
|
|
else
|
|
{
|
|
Gameobj_instances[num].GetComponent<Collider>().enabled = false;
|
|
}
|
|
}
|
|
}
|
|
num++;
|
|
}
|
|
}
|
|
|
|
private void OnParticleCollision(GameObject other)
|
|
{
|
|
bool flag = false;
|
|
if (Propagator != null && Propagator.Grow_ice_mesh)
|
|
{
|
|
_ = other.tag == "Flammable";
|
|
}
|
|
bool flag2 = true;
|
|
if (Propagator == null)
|
|
{
|
|
flag2 = false;
|
|
}
|
|
bool flag3 = false;
|
|
if (Propagator != null)
|
|
{
|
|
flag3 = Propagator.use_particle_collisions;
|
|
}
|
|
if (!((flag2 && flag3 && !flag) || !flag2))
|
|
{
|
|
return;
|
|
}
|
|
bool flag4 = false;
|
|
if (flag2)
|
|
{
|
|
for (int i = 0; i < Propagator.Layers.Count; i++)
|
|
{
|
|
int num = LayerMask.NameToLayer(Propagator.Layers[i]);
|
|
if (other.layer == num)
|
|
{
|
|
flag4 = true;
|
|
}
|
|
}
|
|
}
|
|
bool flag5 = false;
|
|
bool flag6 = false;
|
|
bool flag7 = false;
|
|
if (flag2)
|
|
{
|
|
flag5 = Propagator.is_fire;
|
|
flag6 = Propagator.is_ice;
|
|
flag7 = Propagator.By_layer;
|
|
}
|
|
if (((!flag2 || (flag7 && !(flag7 && flag4))) && flag2) || ((!flag2 || ((flag5 || is_fire) && other.layer == LayerMask.NameToLayer("FireParticlesCollision")) || ((flag6 || is_ice) && other.layer == LayerMask.NameToLayer("IceParticlesCollision"))) && flag2))
|
|
{
|
|
return;
|
|
}
|
|
int num2 = 0;
|
|
if (flag2)
|
|
{
|
|
num2 = Propagator.p11.main.maxParticles;
|
|
}
|
|
for (int j = 0; j < collisionEvents.Length; j++)
|
|
{
|
|
collisionEvents[j] = new ParticleCollisionEvent[p11.GetSafeCollisionEventSize()];
|
|
}
|
|
for (int k = 0; k < collisionEvents.Length; k++)
|
|
{
|
|
List<ParticleCollisionEvent> list = new List<ParticleCollisionEvent>();
|
|
list.AddRange(collisionEvents[k]);
|
|
p11.GetCollisionEvents(other, list);
|
|
collisionEvents[k] = list.ToArray();
|
|
}
|
|
for (int l = 0; l < collisionEvents.Length; l++)
|
|
{
|
|
for (int m = 0; m < collisionEvents[l].Length; m++)
|
|
{
|
|
if (systems_To_override != null)
|
|
{
|
|
for (int n = 0; n < systems_To_override.Count; n++)
|
|
{
|
|
if (!systems_To_override[n].enable_overides)
|
|
{
|
|
continue;
|
|
}
|
|
for (int num3 = 0; num3 < systems_To_override[n].Registered_paint_positions.Count; num3++)
|
|
{
|
|
if (!(Vector3.Distance(collisionEvents[l][m].intersection, systems_To_override[n].Registered_paint_positions[num3]) < cut_off_dist))
|
|
{
|
|
continue;
|
|
}
|
|
if (Overide_Color)
|
|
{
|
|
systems_To_override[n].Particle_color[num3] = New_Color;
|
|
}
|
|
if (flag2)
|
|
{
|
|
if (Propagator.is_fire & systems_To_override[n].is_ice)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 1;
|
|
}
|
|
if (Propagator.is_ice & systems_To_override[n].is_fire)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 1;
|
|
}
|
|
if (Propagator.enable_flyaway & systems_To_override[n].is_butterfly & systems_To_override[n].is_fire)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 3;
|
|
}
|
|
else if (Propagator.enable_flyaway & systems_To_override[n].is_butterfly)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 2;
|
|
}
|
|
if (Propagator.enable_LocalWind & systems_To_override[n].is_grass)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 4;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (is_fire & systems_To_override[n].is_ice)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 1;
|
|
}
|
|
if (is_ice & systems_To_override[n].is_fire)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 1;
|
|
}
|
|
if (enable_flyaway & systems_To_override[n].is_butterfly & systems_To_override[n].is_fire)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 3;
|
|
}
|
|
else if (enable_flyaway & systems_To_override[n].is_butterfly)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 2;
|
|
}
|
|
if (enable_LocalWind & systems_To_override[n].is_grass)
|
|
{
|
|
systems_To_override[n].LocalOverrides[num3] = 4;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!flag2)
|
|
{
|
|
continue;
|
|
}
|
|
if (!Propagator.Erase_mode)
|
|
{
|
|
if (Propagator.Registered_paint_positions == null || Propagator.Registered_paint_positions.Count > num2 / 2 || !(collisionEvents[l][m].colliderComponent != null) || !(collisionEvents[l][m].colliderComponent.GetComponent<Collider>() != null) || !(collisionEvents[l][m].colliderComponent.GetComponent<Collider>().gameObject != null))
|
|
{
|
|
continue;
|
|
}
|
|
if ((bool)other.GetComponent<Rigidbody>() && !other.GetComponent<Rigidbody>().isKinematic)
|
|
{
|
|
float num4 = Flame_force * 300f;
|
|
other.GetComponent<Rigidbody>().AddForceAtPosition((other.transform.position - p11Transform.position).normalized * num4, other.transform.position);
|
|
}
|
|
int num5 = 0;
|
|
if (Random.Range(1, Propagator.propagation_chance_factor + 1) == Propagator.propagation_chance_factor)
|
|
{
|
|
num5 = 1;
|
|
}
|
|
if (num5 != 1)
|
|
{
|
|
continue;
|
|
}
|
|
Propagator.Registered_paint_positions.Add(collisionEvents[l][m].intersection);
|
|
Propagator.Registered_paint_rotations.Add(collisionEvents[l][m].normal);
|
|
Propagator.Registered_paint_times.Add(Time.fixedTime);
|
|
if (!Propagator.gameobject_mode)
|
|
{
|
|
Propagator.Registered_paint_size.Add(Propagator.p11.main.startSize.constant + Propagator.Random_size_factor);
|
|
}
|
|
Propagator.Updated_Registered_paint_positions.Add(collisionEvents[l][m].intersection);
|
|
Propagator.Particle_color.Add(new Vector4(0f, 0f, 0f, 999f));
|
|
if (Propagator.gameobject_mode & Application.isPlaying)
|
|
{
|
|
if (Propagator.Gameobj_instances.Count < Propagator.particle_count)
|
|
{
|
|
GameObject gameObject = Object.Instantiate(Propagator.Gameobj, Propagator.Registered_paint_positions[Propagator.Registered_paint_positions.Count - 1], Quaternion.identity);
|
|
if (gameObject.GetComponent<Collider>() != null)
|
|
{
|
|
if (Propagator.Remove_colliders)
|
|
{
|
|
gameObject.GetComponent<Collider>().enabled = false;
|
|
}
|
|
else
|
|
{
|
|
gameObject.GetComponent<Collider>().enabled = true;
|
|
}
|
|
}
|
|
Propagator.Gameobj_instances.Add(gameObject.transform);
|
|
gameObject.transform.position = Propagator.Registered_paint_positions[Propagator.Registered_paint_positions.Count - 1];
|
|
if (Propagator.Angled)
|
|
{
|
|
gameObject.transform.localEulerAngles = Propagator.Registered_paint_rotations[Propagator.Registered_paint_positions.Count - 1];
|
|
}
|
|
gameObject.transform.parent = Propagator.Parent_OBJ.transform;
|
|
Propagator.Updated_gameobject_positions.Add(gameObject.transform.position);
|
|
Propagator.Registered_paint_size.Add(Propagator.Gameobj_instances[Propagator.Gameobj_instances.Count - 1].localScale.x);
|
|
}
|
|
else
|
|
{
|
|
Propagator.Registered_paint_size.Add(Propagator.p11.main.startSize.constant + Propagator.Random_size_factor);
|
|
}
|
|
}
|
|
Propagator.LocalOverrides.Add(0);
|
|
Propagator.PaintTypes.Add(ParticlePropagationSKYMASTER.PaintType.ParticleCollision);
|
|
Propagator.Emitter_objects.Add(collisionEvents[l][m].colliderComponent.GetComponent<Collider>().gameObject.transform);
|
|
Propagator.Registered_initial_positions.Add(collisionEvents[l][m].colliderComponent.GetComponent<Collider>().gameObject.transform.position);
|
|
Propagator.Registered_initial_scale.Add(collisionEvents[l][m].colliderComponent.GetComponent<Collider>().gameObject.transform.localScale);
|
|
Propagator.Registered_initial_rotation.Add(collisionEvents[l][m].colliderComponent.GetComponent<Collider>().gameObject.transform.rotation);
|
|
continue;
|
|
}
|
|
for (int num6 = 0; num6 < Propagator.Updated_Registered_paint_positions.Count; num6++)
|
|
{
|
|
if (Vector3.Distance(collisionEvents[l][m].intersection, Propagator.Updated_Registered_paint_positions[num6]) < 0.5f * Propagator.brush_size)
|
|
{
|
|
if (Propagator.gameobject_mode & Application.isPlaying)
|
|
{
|
|
Object.Destroy(Propagator.Gameobj_instances[num6].gameObject);
|
|
Propagator.Gameobj_instances.RemoveAt(num6);
|
|
Propagator.Updated_gameobject_positions.RemoveAt(num6);
|
|
}
|
|
Propagator.LocalOverrides.RemoveAt(num6);
|
|
Propagator.PaintTypes.RemoveAt(num6);
|
|
Propagator.Emitter_objects.RemoveAt(num6);
|
|
Propagator.Updated_Registered_paint_positions.RemoveAt(num6);
|
|
Propagator.Particle_color.RemoveAt(num6);
|
|
Propagator.Registered_paint_rotations.RemoveAt(num6);
|
|
Propagator.Registered_paint_times.RemoveAt(num6);
|
|
Propagator.Registered_paint_size.RemoveAt(num6);
|
|
Propagator.Registered_paint_positions.RemoveAt(num6);
|
|
Propagator.Registered_initial_positions.RemoveAt(num6);
|
|
Propagator.Registered_initial_rotation.RemoveAt(num6);
|
|
Propagator.Registered_initial_scale.RemoveAt(num6);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|