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

123 lines
3.5 KiB
C#
Raw Normal View History

2023-09-13 05:07:40 +00:00
// Distant Lands 2022.
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace DistantLands.Cozy.Data
{
[System.Serializable]
[CreateAssetMenu(menuName = "Distant Lands/Cozy/FX/Particle FX", order = 361)]
public class ParticleFX : FXProfile
{
public CozyParticles particleSystem;
private CozyParticles runtimeRef;
public bool autoScale;
public override void PlayEffect(float intensity)
{
2024-01-03 06:34:33 +00:00
if (!runtimeRef)
if (InitializeEffect(weatherSphere) == false)
return;
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
if (autoScale)
runtimeRef.transform.localScale = weatherSphere.transform.GetChild(0).localScale;
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
if (intensity == 0)
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
runtimeRef.Stop();
2023-09-13 05:07:40 +00:00
return;
}
runtimeRef.Play(transitionTimeModifier.Evaluate(intensity));
}
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)
2023-09-13 05:07:40 +00:00
return false;
2024-01-03 06:34:33 +00:00
base.InitializeEffect(weather);
2023-09-13 05:07:40 +00:00
if (runtimeRef == null)
{
2024-01-03 06:34:33 +00:00
runtimeRef = weather.GetFXRuntimeRef<CozyParticles>(name);
if (runtimeRef)
return true;
2023-09-13 05:07:40 +00:00
runtimeRef = Instantiate(particleSystem).GetComponent<CozyParticles>();
runtimeRef.gameObject.name = name;
2024-01-03 06:34:33 +00:00
runtimeRef.transform.parent = weather.particleFXParent;
runtimeRef.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
runtimeRef.SetupTriggers();
if (autoScale)
runtimeRef.transform.localScale *= weather.transform.GetChild(0).localScale.x;
2023-09-13 05:07:40 +00:00
}
return true;
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(ParticleFX))]
[CanEditMultipleObjects]
public class E_ParticleFX : E_FXProfile
{
void OnEnable()
{
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(serializedObject.FindProperty("particleSystem"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("autoScale"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("transitionTimeModifier"));
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);
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);
serializedObject.Update();
EditorGUI.PropertyField(propPosA, serializedObject.FindProperty("particleSystem"));
EditorGUI.PropertyField(propPosB, serializedObject.FindProperty("autoScale"));
EditorGUI.PropertyField(propPosC, serializedObject.FindProperty("transitionTimeModifier"));
serializedObject.ApplyModifiedProperties();
}
public override float GetLineHeight()
{
return 3;
}
}
#endif
}