2023-09-13 05:07:40 +00:00
using System.Collections ;
using UnityEngine ;
using UnityEngine.Rendering ;
#if UNITY_EDITOR
using UnityEditor ;
#endif
#if BUTO
using OccaSoftware.Buto.Runtime ;
#endif
namespace DistantLands.Cozy
{
[ExecuteAlways]
public class CozyButoModule : CozyModule
{
#if BUTO
[SerializeField]
private ButoVolumetricFog fog ;
[SerializeField]
private VolumeProfile volumeProfile ;
[Range(0, 2)] public float fogBrightnessMultiplier ;
[Range(0, 2)] public float fogDensityMultiplier ;
void Awake ( )
{
TryFindFog ( ) ;
}
void Update ( )
{
2024-01-03 06:34:33 +00:00
2023-09-13 05:07:40 +00:00
if ( weatherSphere = = null )
2024-01-03 06:34:33 +00:00
base . InitializeModule ( ) ;
2023-09-13 05:07:40 +00:00
if ( volumeProfile = = null )
fog = null ;
2024-01-03 06:34:33 +00:00
2023-09-13 05:07:40 +00:00
if ( weatherSphere . freezeUpdateInEditMode & & ! Application . isPlaying )
return ;
if ( fog )
{
fog . colorInfluence . Override ( 1 ) ;
fog . litColor . Override ( weatherSphere . fogColor5 * fogBrightnessMultiplier ) ;
fog . shadowedColor . Override ( weatherSphere . fogColor5 * 0.5f * fogBrightnessMultiplier ) ;
fog . fogDensity . Override ( fogDensityMultiplier * 10 * weatherSphere . fogDensity ) ;
}
else
{
TryFindFog ( ) ;
}
}
void TryFindFog ( )
{
if ( volumeProfile )
{
foreach ( VolumeComponent component in volumeProfile . components )
{
2024-01-03 06:34:33 +00:00
if ( component is ButoVolumetricFog )
2023-09-13 05:07:40 +00:00
{
fog = ( ButoVolumetricFog ) component ;
return ;
}
}
}
else
{
foreach ( Volume vol in FindObjectsOfType < Volume > ( ) )
{
foreach ( VolumeComponent component in vol . profile . components )
{
2024-01-03 06:34:33 +00:00
if ( component is ButoVolumetricFog )
2023-09-13 05:07:40 +00:00
{
fog = ( ButoVolumetricFog ) component ;
volumeProfile = vol . profile ;
return ;
}
}
}
}
}
#endif
}
#if UNITY_EDITOR
[CustomEditor(typeof(CozyButoModule))]
[CanEditMultipleObjects]
public class E_CozyButoModule : E_CozyModule
{
public override GUIContent GetGUIContent ( )
{
//Place your module's GUI content here.
2024-01-03 06:34:33 +00:00
return new GUIContent ( " Buto" , ( Texture ) Resources . Load ( "Occa" ) , "Control Buto Volumetric Fog within the COZY system." ) ;
2023-09-13 05:07:40 +00:00
}
2024-01-03 06:34:33 +00:00
public override void OpenDocumentationURL ( )
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
Application . OpenURL ( "https://distant-lands.gitbook.io/cozy-stylized-weather-documentation/how-it-works/modules/buto-module" ) ;
2023-09-13 05:07:40 +00:00
}
public override void DisplayInCozyWindow ( )
{
serializedObject . Update ( ) ;
EditorGUI . indentLevel + + ;
EditorGUILayout . HelpBox ( "Please make sure the \"Import for Buto Integration\" unity package is installed for the shaders to properly recompile." , MessageType . Info ) ;
2024-01-03 06:34:33 +00:00
2023-09-13 05:07:40 +00:00
#if BUTO
2024-01-03 06:34:33 +00:00
if ( serializedObject . FindProperty ( "fog" ) . objectReferenceValue = = null )
{
EditorGUILayout . HelpBox ( "Could not find any instance of Buto in your scene! You will have to set the profile manually in the module settings." , MessageType . Warning ) ;
}
EditorGUILayout . Space ( 20 ) ;
2023-09-13 05:07:40 +00:00
if ( serializedObject . FindProperty ( "volumeProfile" ) . objectReferenceValue = = null )
EditorGUILayout . PropertyField ( serializedObject . FindProperty ( "volumeProfile" ) ) ;
EditorGUILayout . PropertyField ( serializedObject . FindProperty ( "fogBrightnessMultiplier" ) ) ;
EditorGUILayout . PropertyField ( serializedObject . FindProperty ( "fogDensityMultiplier" ) ) ;
EditorGUILayout . Space ( 20 ) ;
#else
EditorGUILayout . HelpBox ( "Buto Volumetric Fog is not currently in this project! Please make sure that it has been properly downloaded before using this module." , MessageType . Warning ) ;
EditorGUI . indentLevel - - ;
#endif
serializedObject . ApplyModifiedProperties ( ) ;
}
}
#endif
}