221 lines
5.5 KiB
C#
221 lines
5.5 KiB
C#
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
public class ChainLightningShuriken_SM : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
|
|
private GameObject[] target1;
|
|
|
|
public int zigs = 100;
|
|
|
|
public float speed = 1f;
|
|
|
|
public float scale = 1f;
|
|
|
|
public Light startLight;
|
|
|
|
public Light endLight;
|
|
|
|
private PerlinSKYMASTER noise;
|
|
|
|
private float oneOverZigs;
|
|
|
|
private ParticleSystem.Particle[] particles;
|
|
|
|
private ParticleSystem Emitter;
|
|
|
|
public bool Energized;
|
|
|
|
public bool is_parent;
|
|
|
|
public int current_depth;
|
|
|
|
public int max_depth;
|
|
|
|
private int current_target_count;
|
|
|
|
public int max_target_count = 3;
|
|
|
|
public bool Random_target;
|
|
|
|
public float Affect_dist = 10f;
|
|
|
|
private float Time_count;
|
|
|
|
public float Change_target_delay = 0.5f;
|
|
|
|
public float Particle_energy = 1f;
|
|
|
|
public int optimize_factor = 5;
|
|
|
|
private void Start()
|
|
{
|
|
if (zigs == 0)
|
|
{
|
|
zigs = 1;
|
|
}
|
|
oneOverZigs = 1f / (float)zigs;
|
|
Emitter = GetComponent<ParticleSystem>();
|
|
if (Emitter != null)
|
|
{
|
|
Emitter.Emit(zigs);
|
|
particles = new ParticleSystem.Particle[zigs];
|
|
Emitter.GetParticles(particles);
|
|
target1 = GameObject.FindGameObjectsWithTag("Conductor");
|
|
if ((bool)endLight)
|
|
{
|
|
endLight.enabled = false;
|
|
endLight.gameObject.SetActive(value: false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Emitter == null)
|
|
{
|
|
Start();
|
|
if (Emitter == null)
|
|
{
|
|
Debug.Log("Add a Shuriken particle to the object with the Lighting script first");
|
|
return;
|
|
}
|
|
}
|
|
if (noise == null)
|
|
{
|
|
noise = new PerlinSKYMASTER();
|
|
}
|
|
if (is_parent | (!is_parent & Energized & (current_depth < max_depth)))
|
|
{
|
|
target1 = GameObject.FindGameObjectsWithTag("Conductor");
|
|
if (target1 == null || target1.Length == 0)
|
|
{
|
|
return;
|
|
}
|
|
int num = Random.Range(0, target1.Length);
|
|
if (Random_target)
|
|
{
|
|
if (Time.fixedTime - Time_count > Change_target_delay)
|
|
{
|
|
if (Vector3.Distance(target1[num].transform.position, base.transform.position) < Affect_dist)
|
|
{
|
|
target = target1[num].transform;
|
|
}
|
|
else
|
|
{
|
|
Emitter.Clear();
|
|
}
|
|
Time_count = Time.fixedTime;
|
|
if (!is_parent & Energized & (current_depth < max_depth) & (current_target_count > max_target_count))
|
|
{
|
|
Energized = false;
|
|
}
|
|
current_target_count++;
|
|
}
|
|
if (target != null && Vector3.Distance(target.position, base.transform.position) > Affect_dist)
|
|
{
|
|
target = null;
|
|
Emitter.Clear();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
target = null;
|
|
Emitter.Clear();
|
|
int num2 = 0;
|
|
GameObject[] array = target1;
|
|
foreach (GameObject gameObject in array)
|
|
{
|
|
if (Vector3.Distance(gameObject.transform.position, base.transform.position) < Affect_dist)
|
|
{
|
|
target = gameObject.transform;
|
|
}
|
|
num2++;
|
|
}
|
|
if (!is_parent & Energized & (current_depth < max_depth) & (current_target_count > max_target_count))
|
|
{
|
|
Energized = false;
|
|
}
|
|
current_target_count++;
|
|
}
|
|
float num3 = Time.time * speed * 0.1365143f;
|
|
float num4 = Time.time * speed * 1.21688f;
|
|
float num5 = Time.time * speed * 2.5564f;
|
|
if (target != null)
|
|
{
|
|
for (int j = 0; j < particles.Length; j++)
|
|
{
|
|
Vector3 position = Vector3.Lerp(base.transform.position, target.position, oneOverZigs * (float)j);
|
|
Vector3 vector = new Vector3(noise.Noise(num3 + position.x, num3 + position.y, num3 + position.z), noise.Noise(num4 + position.x, num4 + position.y, num4 + position.z), noise.Noise(num5 + position.x, num5 + position.y, num5 + position.z));
|
|
position += vector * scale * ((float)j * oneOverZigs);
|
|
particles[j].position = position;
|
|
particles[j].startColor = Color.white;
|
|
particles[j].startLifetime = Particle_energy;
|
|
}
|
|
ChainLightningShuriken_SM chainLightningShuriken_SM = target.gameObject.GetComponent(typeof(ChainLightningShuriken_SM)) as ChainLightningShuriken_SM;
|
|
if (chainLightningShuriken_SM == null)
|
|
{
|
|
chainLightningShuriken_SM = target.gameObject.GetComponentInChildren(typeof(ChainLightningShuriken_SM)) as ChainLightningShuriken_SM;
|
|
}
|
|
if (chainLightningShuriken_SM != null && !chainLightningShuriken_SM.is_parent)
|
|
{
|
|
chainLightningShuriken_SM.Energized = true;
|
|
chainLightningShuriken_SM.max_depth = max_depth;
|
|
chainLightningShuriken_SM.current_depth = current_depth + 1;
|
|
}
|
|
Emitter.SetParticles(particles, particles.Length);
|
|
if (particles.Length >= 2)
|
|
{
|
|
if ((bool)startLight)
|
|
{
|
|
startLight.transform.position = particles[0].position;
|
|
}
|
|
int num6 = 1;
|
|
num6 = Random.Range(1, optimize_factor);
|
|
if ((bool)endLight)
|
|
{
|
|
if ((num6 == 1) & (target != null))
|
|
{
|
|
endLight.enabled = true;
|
|
endLight.gameObject.SetActive(value: true);
|
|
endLight.transform.position = particles[particles.Length - 1].position;
|
|
}
|
|
else
|
|
{
|
|
endLight.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
endLight.enabled = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int k = 0; k < particles.Length; k++)
|
|
{
|
|
particles[k].position = Vector3.zero;
|
|
}
|
|
Emitter.SetParticles(particles, particles.Length);
|
|
}
|
|
if ((bool)endLight & (target == null))
|
|
{
|
|
endLight.enabled = false;
|
|
endLight.gameObject.SetActive(value: false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int l = 0; l < particles.Length; l++)
|
|
{
|
|
particles[l].position = Vector3.zero;
|
|
}
|
|
Emitter.SetParticles(particles, particles.Length);
|
|
}
|
|
}
|
|
}
|
|
}
|