190 lines
4.9 KiB
C#
190 lines
4.9 KiB
C#
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
public class lightningCameraVolumeCloudsSM_SRP : MonoBehaviour
|
|
{
|
|
public bool useSecondLightning;
|
|
|
|
public GameObject LightningBoxPrefab;
|
|
|
|
public bool setupLightning;
|
|
|
|
public bool weatherTransition = true;
|
|
|
|
public SkyMasterManager SkyManager;
|
|
|
|
public CloudScript fullvolumeCloudsScript;
|
|
|
|
public GameObject LightningPrefab;
|
|
|
|
public bool EnableLightning;
|
|
|
|
public bool useLocalLightLightn;
|
|
|
|
private float last_lightning_time;
|
|
|
|
public float lightning_every = 15f;
|
|
|
|
public float max_lightning_time = 2f;
|
|
|
|
public float lightning_rate_offset = 5f;
|
|
|
|
private Transform LightningOne;
|
|
|
|
private Transform LightningTwo;
|
|
|
|
public Transform LightningBox;
|
|
|
|
private Light LightA;
|
|
|
|
private Light LightB;
|
|
|
|
private void Start()
|
|
{
|
|
setupLightning = true;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
createLightningBox();
|
|
if (Application.isPlaying)
|
|
{
|
|
LightningUpdate();
|
|
}
|
|
if (weatherTransition)
|
|
{
|
|
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.LightningStorm)
|
|
{
|
|
EnableLightning = true;
|
|
}
|
|
else
|
|
{
|
|
EnableLightning = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void createLightningBox()
|
|
{
|
|
if (!setupLightning)
|
|
{
|
|
return;
|
|
}
|
|
if (LightningBox == null)
|
|
{
|
|
if (LightningBoxPrefab == null)
|
|
{
|
|
GameObject lightningPrefab = Resources.Load("Volume Clouds Lightning Prefab") as GameObject;
|
|
LightningPrefab = lightningPrefab;
|
|
GameObject gameObject = Resources.Load("Volume Clouds Lightning Bounding Box") as GameObject;
|
|
Debug.Log(gameObject.name);
|
|
LightningBoxPrefab = gameObject;
|
|
LightningBox = gameObject.transform;
|
|
}
|
|
else
|
|
{
|
|
GameObject gameObject2 = Object.Instantiate(LightningBoxPrefab);
|
|
LightningBox = gameObject2.transform;
|
|
}
|
|
}
|
|
setupLightning = false;
|
|
}
|
|
|
|
public void LightningUpdate()
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
return;
|
|
}
|
|
if (EnableLightning)
|
|
{
|
|
if (LightningOne == null)
|
|
{
|
|
LightningOne = Object.Instantiate(LightningPrefab).transform;
|
|
LightA = LightningOne.GetComponentInChildren<ChainLightning_SKYMASTER>().startLight;
|
|
LightningOne.gameObject.SetActive(value: false);
|
|
}
|
|
if (LightningTwo == null)
|
|
{
|
|
LightningTwo = Object.Instantiate(LightningPrefab).transform;
|
|
LightB = LightningTwo.GetComponentInChildren<ChainLightning_SKYMASTER>().startLight;
|
|
LightningTwo.gameObject.SetActive(value: false);
|
|
}
|
|
if (!(LightningBox != null))
|
|
{
|
|
return;
|
|
}
|
|
if (Time.fixedTime - last_lightning_time > lightning_every - Random.Range(0f - lightning_rate_offset, lightning_rate_offset))
|
|
{
|
|
Vector2 vector = LightningBox.position.x * Vector2.one + LightningBox.localScale.x / 2f * new Vector2(-1f, 1f);
|
|
Vector2 vector2 = LightningBox.position.y * Vector2.one + LightningBox.localScale.y / 2f * new Vector2(-1f, 1f);
|
|
Vector2 vector3 = LightningBox.position.z * Vector2.one + LightningBox.localScale.z / 2f * new Vector2(-1f, 1f);
|
|
LightningOne.position = new Vector3(Random.Range(vector.x, vector.y), Random.Range(vector2.x, vector2.y), Random.Range(vector3.x, vector3.y));
|
|
if (!(SkyManager != null) || Random.Range(0f, SkyManager.WeatherSeverity + 1f) != 1f)
|
|
{
|
|
LightningOne.gameObject.SetActive(value: true);
|
|
if (fullvolumeCloudsScript != null)
|
|
{
|
|
fullvolumeCloudsScript.localLight = LightA;
|
|
}
|
|
}
|
|
if (useSecondLightning)
|
|
{
|
|
LightningTwo.position = new Vector3(Random.Range(vector.x, vector.y), Random.Range(vector2.x, vector2.y), Random.Range(vector3.x, vector3.y));
|
|
if (Random.Range(0f, SkyManager.WeatherSeverity + 1f) != 1f)
|
|
{
|
|
LightningTwo.gameObject.SetActive(value: true);
|
|
if (fullvolumeCloudsScript != null)
|
|
{
|
|
fullvolumeCloudsScript.localLight = LightB;
|
|
}
|
|
}
|
|
}
|
|
last_lightning_time = Time.fixedTime;
|
|
}
|
|
else
|
|
{
|
|
if (!(Time.fixedTime - last_lightning_time > max_lightning_time))
|
|
{
|
|
return;
|
|
}
|
|
if (LightningOne != null && LightningOne.gameObject.activeInHierarchy)
|
|
{
|
|
LightningOne.gameObject.SetActive(value: false);
|
|
if (fullvolumeCloudsScript != null)
|
|
{
|
|
fullvolumeCloudsScript.localLight = null;
|
|
}
|
|
}
|
|
if (LightningTwo != null && LightningTwo.gameObject.activeInHierarchy)
|
|
{
|
|
LightningTwo.gameObject.SetActive(value: false);
|
|
if (fullvolumeCloudsScript != null)
|
|
{
|
|
fullvolumeCloudsScript.localLight = null;
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
if (LightningOne != null && LightningOne.gameObject.activeInHierarchy)
|
|
{
|
|
LightningOne.gameObject.SetActive(value: false);
|
|
if (fullvolumeCloudsScript != null)
|
|
{
|
|
fullvolumeCloudsScript.localLight = null;
|
|
}
|
|
}
|
|
if (LightningTwo != null && LightningTwo.gameObject.activeInHierarchy)
|
|
{
|
|
LightningTwo.gameObject.SetActive(value: false);
|
|
if (fullvolumeCloudsScript != null)
|
|
{
|
|
fullvolumeCloudsScript.localLight = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|