using System.Collections; using System.Collections.Generic; using UnityEngine; namespace ProceduralWorlds.HDRPTOD { public class HDRPTimeOfDayAPI { #if HDPipeline && UNITY_2021_2_OR_NEWER /// /// Gets the time of day system instance in the scene /// /// public static HDRPTimeOfDay GetTimeOfDay() { return HDRPTimeOfDay.Instance; } /// /// Refreshes the time of day system by processing the time of day code /// public static void RefreshTimeOfDay() { if (IsPresent()) { GetTimeOfDay().ProcessTimeOfDay(); } } /// /// Starts the weather effect from the index selected. This is not an instant effect /// /// public static void StartWeather(int weatherProfileIndex) { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (weatherProfileIndex <= timeOfDay.WeatherProfiles.Count - 1 && weatherProfileIndex >= 0) { timeOfDay.StartWeather(weatherProfileIndex); } } } /// /// Stops the current active weather. This is an instant effect /// public static void StopWeather() { if (IsPresent()) { GetTimeOfDay().StopWeather(); } } /// /// Returns the time of day system, will return -1 if the time of day system is not present. /// /// public static float GetCurrentTime() { if (IsPresent()) { return GetTimeOfDay().TimeOfDay; } else { return -1f; } } /// /// Sets the time of day. /// If is0To1 is set to true you must provide a 0-1 value and not a 0-24 value the value will be multiplied by 24. /// /// /// public static void SetCurrentTime(float time, bool is0To1 = false) { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (is0To1) { timeOfDay.TimeOfDay = Mathf.Clamp(time * 24f, 0f, 24f); } else { timeOfDay.TimeOfDay = Mathf.Clamp(time, 0f, 24f); } } } /// /// Sets the direction of the system on the y axis /// /// public static void SetDirection(float direction) { if (IsPresent()) { GetTimeOfDay().DirectionY = direction; } } /// /// Sets if you want to use post processing based on the state bool /// /// public static void SetPostProcessingState(bool state) { if (IsPresent()) { GetTimeOfDay().UsePostFX = state; } } /// /// Sets if you want to use ambient audio based on the state bool /// /// public static void SetAmbientAudioState(bool state) { if (IsPresent()) { GetTimeOfDay().UseAmbientAudio = state; } } /// /// Sets if you want to use underwater overrides based on the state bool /// /// /// public static void SetUnderwaterState(bool state, UnderwaterOverrideSystemType mode) { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); timeOfDay.TimeOfDayProfile.UnderwaterOverrideData.m_useOverrides = state; timeOfDay.TimeOfDayProfile.UnderwaterOverrideData.m_systemType = mode; } } /// /// Sets if you want to use weather system based on the state bool /// /// public static void SetWeatherState(bool state) { if (IsPresent()) { GetTimeOfDay().UseWeatherFX = state; } } /// /// Sets the shadow distance multiplier /// /// public static void SetGlobalShadowMultiplier(float value) { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (timeOfDay.TimeOfDayProfile != null) { timeOfDay.TimeOfDayProfile.TimeOfDayData.m_shadowDistanceMultiplier = value; RefreshTimeOfDay(); } } } /// /// Gets the shadow distance multiplier /// /// public static float GetGlobalShadowMultiplier() { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (timeOfDay.TimeOfDayProfile != null) { return timeOfDay.TimeOfDayProfile.TimeOfDayData.m_shadowDistanceMultiplier; } } return 1f; } /// /// Sets the fog distance multiplier /// /// public static void SetGlobalFogMultiplier(float value) { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (timeOfDay.TimeOfDayProfile != null) { timeOfDay.TimeOfDayProfile.TimeOfDayData.m_globalFogMultiplier = value; RefreshTimeOfDay(); } } } /// /// Gets the fog distance multiplier /// /// public static float GetGlobalFogMultiplier() { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (timeOfDay.TimeOfDayProfile != null) { return timeOfDay.TimeOfDayProfile.TimeOfDayData.m_globalFogMultiplier; } } return 1f; } /// /// Sets the sun distance multiplier /// /// public static void SetGlobalSunMultiplier(float value) { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (timeOfDay.TimeOfDayProfile != null) { timeOfDay.TimeOfDayProfile.TimeOfDayData.m_globalLightMultiplier = value; RefreshTimeOfDay(); } } } /// /// Gets the sun distance multiplier /// /// public static float GetGlobalSunMultiplier() { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (timeOfDay.TimeOfDayProfile != null) { return timeOfDay.TimeOfDayProfile.TimeOfDayData.m_globalLightMultiplier; } } return 1f; } /// /// Sets the auto update multiplier /// /// public static void SetAutoUpdateMultiplier(bool autoUpdate, float value) { if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (timeOfDay.TimeOfDayProfile != null) { timeOfDay.m_enableTimeOfDaySystem = autoUpdate; timeOfDay.m_timeOfDayMultiplier = value; } } } /// /// Gets the auto update multiplier /// /// public static void GetAutoUpdateMultiplier(out bool autoUpdate, out float value) { autoUpdate = false; value = 1f; if (IsPresent()) { HDRPTimeOfDay timeOfDay = GetTimeOfDay(); if (timeOfDay.TimeOfDayProfile != null) { autoUpdate = timeOfDay.m_enableTimeOfDaySystem; value = timeOfDay.m_timeOfDayMultiplier; } } } /// /// Retrns true if the system is present /// /// private static bool IsPresent() { return HDRPTimeOfDay.Instance; } #endif } }