OldBlueWater/BlueWater/Assets/Distant Lands/Cozy Weather/Contents/Scripts/Data/FX/ThunderFX.cs

164 lines
6.2 KiB
C#
Raw Normal View History

2024-01-03 06:34:33 +00:00
// Distant Lands 2023.
2023-09-13 05:07:40 +00:00
using System.Collections;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace DistantLands.Cozy.Data
{
[System.Serializable]
[CreateAssetMenu(menuName = "Distant Lands/Cozy/FX/Thunder FX", order = 361)]
public class ThunderFX : FXProfile
{
public Vector2 timeBetweenStrikes;
2024-01-03 06:34:33 +00:00
public GameObject thunderPrefab = null;
2023-09-13 05:07:40 +00:00
public float weight;
2024-01-03 06:34:33 +00:00
public CozyThunderManager runtimeRef;
public float minimumDistance = 700;
public float maximumDistance = 1200;
public float minScreenXmultiplier = 0.1f;
public float maxScreenXmultiplier = 0.9f;
public float minScreenYmultiplier = 0.0f;
public float maxScreenYmultiplier = 0.1f;
[Range(0, 1)]
[Tooltip("What percentage of the time should the lightning and thunder be forced to spawn in the camera's view?")]
public float spawnInFrustumPercentage = 0.5f;
public override void PlayEffect(float weight)
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
if (!runtimeRef)
if (InitializeEffect(weatherSphere) == false)
2023-09-13 05:07:40 +00:00
return;
2024-01-03 06:34:33 +00:00
runtimeRef.PlayEffect(transitionTimeModifier.Evaluate(weight));
2023-09-13 05:07:40 +00:00
}
2024-01-03 06:34:33 +00:00
public override bool InitializeEffect(CozyWeather weather)
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
if (!Application.isPlaying)
return false;
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
base.InitializeEffect(weather);
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
if (runtimeRef == null)
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
if (weather.GetFXRuntimeRef<CozyThunderManager>(name))
{
runtimeRef = weather.GetFXRuntimeRef<CozyThunderManager>(name);
return true;
}
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
runtimeRef = new GameObject().AddComponent<CozyThunderManager>();
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
runtimeRef.gameObject.name = name;
runtimeRef.transform.parent = weather.thunderFXParent;
runtimeRef.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
runtimeRef.weatherSphere = weather;
runtimeRef.thunderFX = this;
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
}
2023-09-13 05:07:40 +00:00
return true;
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(ThunderFX))]
[CanEditMultipleObjects]
public class E_ThunderFX : E_FXProfile
{
void OnEnable()
{
}
public override void OnInspectorGUI()
{
serializedObject.Update();
2024-01-03 06:34:33 +00:00
EditorGUILayout.PropertyField(serializedObject.FindProperty("thunderPrefab"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("timeBetweenStrikes"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("minimumDistance"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("maximumDistance"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("spawnInFrustumPercentage"));
float min = serializedObject.FindProperty("minScreenXmultiplier").floatValue;
float max = serializedObject.FindProperty("maxScreenXmultiplier").floatValue;
EditorGUILayout.MinMaxSlider("Frustum Placement X", ref min, ref max, 0, 1);
serializedObject.FindProperty("minScreenXmultiplier").floatValue = min;
serializedObject.FindProperty("maxScreenXmultiplier").floatValue = max;
min = serializedObject.FindProperty("minScreenYmultiplier").floatValue;
max = serializedObject.FindProperty("maxScreenYmultiplier").floatValue;
EditorGUILayout.MinMaxSlider("Frustum Placement Y", ref min, ref max, 0, 1);
serializedObject.FindProperty("minScreenYmultiplier").floatValue = min;
serializedObject.FindProperty("maxScreenYmultiplier").floatValue = max;
2023-09-13 05:07:40 +00:00
serializedObject.ApplyModifiedProperties();
}
public override void RenderInWindow(Rect pos)
{
float space = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
var propPosA = new Rect(pos.x, pos.y + space, pos.width, EditorGUIUtility.singleLineHeight);
2024-01-03 06:34:33 +00:00
var propPosB = new Rect(pos.x, pos.y + space * 2, pos.width, EditorGUIUtility.singleLineHeight);
var propPosC = new Rect(pos.x, pos.y + space * 3, pos.width, EditorGUIUtility.singleLineHeight);
var propPosD = new Rect(pos.x, pos.y + space * 4, pos.width, EditorGUIUtility.singleLineHeight);
var propPosE = new Rect(pos.x, pos.y + space * 5, pos.width, EditorGUIUtility.singleLineHeight);
var propPosF = new Rect(pos.x, pos.y + space * 6, pos.width, EditorGUIUtility.singleLineHeight);
var propPosG = new Rect(pos.x, pos.y + space * 7, pos.width, EditorGUIUtility.singleLineHeight);
2023-09-13 05:07:40 +00:00
serializedObject.Update();
2024-01-03 06:34:33 +00:00
EditorGUI.PropertyField(propPosA, serializedObject.FindProperty("thunderPrefab"));
EditorGUI.PropertyField(propPosB, serializedObject.FindProperty("timeBetweenStrikes"));
EditorGUI.PropertyField(propPosC, serializedObject.FindProperty("minimumDistance"));
EditorGUI.PropertyField(propPosD, serializedObject.FindProperty("maximumDistance"));
EditorGUI.PropertyField(propPosE, serializedObject.FindProperty("spawnInFrustumPercentage"));
float min = serializedObject.FindProperty("minScreenXmultiplier").floatValue;
float max = serializedObject.FindProperty("maxScreenXmultiplier").floatValue;
EditorGUI.MinMaxSlider(propPosF, "Frustum Placement X", ref min, ref max, 0, 1);
serializedObject.FindProperty("minScreenXmultiplier").floatValue = min;
serializedObject.FindProperty("maxScreenXmultiplier").floatValue = max;
min = serializedObject.FindProperty("minScreenYmultiplier").floatValue;
max = serializedObject.FindProperty("maxScreenYmultiplier").floatValue;
EditorGUI.MinMaxSlider(propPosG, "Frustum Placement Y", ref min, ref max, 0, 1);
serializedObject.FindProperty("minScreenYmultiplier").floatValue = min;
serializedObject.FindProperty("maxScreenYmultiplier").floatValue = max;
2023-09-13 05:07:40 +00:00
serializedObject.ApplyModifiedProperties();
}
public override float GetLineHeight()
{
2024-01-03 06:34:33 +00:00
return 7;
2023-09-13 05:07:40 +00:00
}
}
#endif
}