예제 #1
0
        /// <summary>
        /// Starts a global weather transition. Set the index to -1 if you want to back the global weather to the default weather profile.
        /// </summary>
        public void SetNewWeatherProfile(int index)
        {
            switch (index)
            {
            // Back to the default weather profile currently in use
            case -1:
                if (m_defaultWeatherProfile)
                {
                    m_targetWeatherProfile    = m_defaultWeatherProfile;
                    m_weatherTransitionLength = m_defaultWeatherTransitionLength;
                    m_weatherIndex            = -1;
                }
                break;

            // Changes the global weather to the corresponding profile index on the global weather list
            default:
                if (m_globalWeatherProfilesList[index].profile)
                {
                    m_targetWeatherProfile    = m_globalWeatherProfilesList[index].profile;
                    m_weatherTransitionLength = m_globalWeatherProfilesList[index].transitionLength;
                    m_weatherIndex            = index;
                }
                break;
            }

            // Starts the global weather transition progress
            m_weatherTransitionProgress = 0.0f;
            m_weatherTransitionStart    = Time.time;
            m_isWeatherChanging         = true;
        }
예제 #2
0
 private void Awake()
 {
     m_azureTimeController = GetComponent <AzureTimeController>();
     RefreshOverrideTargets();
     m_defaultWeatherProfile = m_defaultWeatherProfilesList[0];
     m_currentWeatherProfile = m_defaultWeatherProfile;
     m_targetWeatherProfile  = m_defaultWeatherProfile;
     EvaluateWeatherProfiles();
 }
예제 #3
0
        /// <summary>
        /// Changes the current weather profile with transition.
        /// </summary>
        public void SetNewWeatherProfile(AzureWeatherProfile profile, float transitionTime)
        {
            m_targetWeatherProfile    = profile;
            m_weatherTransitionLength = transitionTime;

            // Starts the global weather transition progress
            m_weatherTransitionProgress = 0.0f;
            m_weatherTransitionStart    = Time.time;
            m_isWeatherChanging         = true;
        }
예제 #4
0
 /// <summary>
 /// Set the default weather to a random profile from the default weather profiles list.
 /// You can use this on the 'OnDayChange' event of the 'Azure Time Controller' component.
 /// </summary>
 public void SetRandomDefaultWeather(float transitionLength)
 {
     m_defaultWeatherProfile = m_defaultWeatherProfilesList[Random.Range(0, m_defaultWeatherProfilesList.Count)];
     if (m_weatherIndex < 0 && m_isWeatherChanging == false)
     {
         m_targetWeatherProfile = m_defaultWeatherProfile;
         if (m_targetWeatherProfile != m_currentWeatherProfile)
         {
             m_weatherTransitionLength   = transitionLength;
             m_weatherTransitionProgress = 0.0f;
             m_weatherTransitionStart    = Time.time;
             m_isWeatherChanging         = true;
         }
     }
 }
예제 #5
0
 private void Update()
 {
     // Editor only
     #if UNITY_EDITOR
     if (!Application.isPlaying)
     {
         m_defaultWeatherProfile = m_defaultWeatherProfilesList[0];
         m_currentWeatherProfile = m_defaultWeatherProfile;
         if (overrideObject.customPropertyList.Count != m_overridePropertyList.Count)
         {
             UpdateOverridePropertyListSize();
         }
         EvaluateWeatherProfiles();
     }
     #endif
 }
예제 #6
0
        /// <summary>
        /// Computes local weather zones influence.
        /// </summary>
        private void ApplyWeatherZonesInfluence(AzureWeatherProfile localZoneProfile, float t)
        {
            // Loop through the override property list
            for (int index = 0; index < overrideObject.customPropertyList.Count; index++)
            {
                switch (overrideObject.customPropertyList[index].outputType)
                {
                case AzureOutputType.Float:
                    m_overridePropertyList[index].floatOutput = FloatInterpolation(m_overridePropertyList[index].floatOutput, localZoneProfile.profilePropertyList[index].GetFloatOutput(m_timeOfDay, m_sunElevation, m_moonElevation), t);
                    // Loop through the setup property list within the override property list
                    for (int innerIndex = 0; innerIndex < m_overridePropertyList[index].overridePropertySetupList.Count; innerIndex++)
                    {
                        m_profileMultiplier = m_overridePropertyList[index].overridePropertySetupList[innerIndex].multiplier;
                        switch (m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetType)
                        {
                        case AzureOverrideType.Field:
                            m_targetField     = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetField;
                            m_targetComponent = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetComponent;
                            if (m_targetField != null)
                            {
                                m_targetField.SetValue(m_targetComponent, m_overridePropertyList[index].floatOutput * m_profileMultiplier);
                            }
                            break;

                        case AzureOverrideType.Property:
                            m_targetProperty  = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetProperty;
                            m_targetComponent = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetComponent;
                            if (m_targetProperty != null)
                            {
                                m_targetProperty.SetValue(m_targetComponent, m_overridePropertyList[index].floatOutput * m_profileMultiplier);
                            }
                            break;

                        case AzureOverrideType.ShaderProperty:
                            m_targetMaterial  = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetMaterial;
                            m_targetUniformID = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetUniformID;
                            if (m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetShaderUpdateMode == AzureShaderUpdateMode.Local)
                            {
                                if (m_targetMaterial)
                                {
                                    m_targetMaterial.SetFloat(m_targetUniformID, m_overridePropertyList[index].floatOutput * m_profileMultiplier);
                                }
                            }
                            else
                            {
                                Shader.SetGlobalFloat(m_targetUniformID, m_overridePropertyList[index].floatOutput * m_profileMultiplier);
                            }
                            break;
                        }
                    }
                    break;

                case AzureOutputType.Color:
                    m_overridePropertyList[index].colorOutput = ColorInterpolation(m_overridePropertyList[index].colorOutput, localZoneProfile.profilePropertyList[index].GetColorOutput(m_timeOfDay, m_sunElevation, m_moonElevation), t);
                    // Loop through the setup property list within the override property list
                    for (int innerIndex = 0; innerIndex < m_overridePropertyList[index].overridePropertySetupList.Count; innerIndex++)
                    {
                        m_profileMultiplier = m_overridePropertyList[index].overridePropertySetupList[innerIndex].multiplier;
                        switch (m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetType)
                        {
                        case AzureOverrideType.Field:
                            m_targetField     = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetField;
                            m_targetComponent = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetComponent;
                            if (m_targetField != null)
                            {
                                m_targetField.SetValue(m_targetComponent, m_overridePropertyList[index].colorOutput * m_profileMultiplier);
                            }
                            break;

                        case AzureOverrideType.Property:
                            m_targetProperty  = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetProperty;
                            m_targetComponent = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetComponent;
                            if (m_targetProperty != null)
                            {
                                m_targetProperty.SetValue(m_targetComponent, m_overridePropertyList[index].colorOutput * m_profileMultiplier);
                            }
                            break;

                        case AzureOverrideType.ShaderProperty:
                            m_targetMaterial  = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetMaterial;
                            m_targetUniformID = m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetUniformID;
                            if (m_overridePropertyList[index].overridePropertySetupList[innerIndex].targetShaderUpdateMode == AzureShaderUpdateMode.Local)
                            {
                                if (m_targetMaterial)
                                {
                                    m_targetMaterial.SetColor(m_targetUniformID, m_overridePropertyList[index].colorOutput * m_profileMultiplier);
                                }
                            }
                            else
                            {
                                Shader.SetGlobalColor(m_targetUniformID, m_overridePropertyList[index].colorOutput * m_profileMultiplier);
                            }
                            break;
                        }
                    }
                    break;
                }
            }
        }
예제 #7
0
        private void EvaluateWeatherProfiles()
        {
            if (!overrideObject)
            {
                return;
            }

            if (m_azureTimeController)
            {
                m_timeOfDay     = m_azureTimeController.GetEvaluateTime();
                m_sunElevation  = m_azureTimeController.GetSunElevation();
                m_moonElevation = m_azureTimeController.GetMoonElevation();
            }

            if (!m_isWeatherChanging)
            {
                // Evaluates the current weather profile when there is no global weather transition or local weather zone influence
                EvaluateCurrentWeatherProfile();
            }
            else
            {
                // Computes the global weather transition progress
                m_weatherTransitionProgress = Mathf.Clamp01((Time.time - m_weatherTransitionStart) / m_weatherTransitionLength);

                // Performs the global weather transition
                ApplyGlobalWeatherTransition(m_currentWeatherProfile, m_targetWeatherProfile, m_weatherTransitionProgress);

                // Ends the global weather transition
                if (Mathf.Abs(m_weatherTransitionProgress - 1.0f) <= 0.0f)
                {
                    m_isWeatherChanging         = false;
                    m_weatherTransitionProgress = 0.0f;
                    m_weatherTransitionStart    = 0.0f;
                    m_currentWeatherProfile     = m_targetWeatherProfile;
                }
            }

            // Computes weather zones influence
            // Based on Unity's Post Processing v2
            if (!m_localWeatherZoneTrigger)
            {
                return;
            }

            m_localWeatherZoneTriggerPosition = m_localWeatherZoneTrigger.position;

            // Traverse all weather zones in the weather zone list
            foreach (var weatherZone in m_localWeatherZonesList)
            {
                // Skip if the list index is null
                if (weatherZone == null)
                {
                    continue;
                }

                // If weather zone has no collider, skip it as it's useless
                m_localWeatherZoneCollider = weatherZone.GetComponent <Collider>();
                if (!m_localWeatherZoneCollider)
                {
                    continue;
                }

                if (!m_localWeatherZoneCollider.enabled || !m_localWeatherZoneCollider.gameObject.activeSelf)
                {
                    continue;
                }

                // Find closest distance to weather zone, 0 means it's inside it
                m_localWeatherZoneClosestDistanceSqr = float.PositiveInfinity;

                m_localWeatherZoneClosestPoint = m_localWeatherZoneCollider.ClosestPoint(m_localWeatherZoneTriggerPosition); // 5.6-only API
                m_localWeatherZoneDistance     = ((m_localWeatherZoneClosestPoint - m_localWeatherZoneTriggerPosition) / 2f).sqrMagnitude;

                if (m_localWeatherZoneDistance < m_localWeatherZoneClosestDistanceSqr)
                {
                    m_localWeatherZoneClosestDistanceSqr = m_localWeatherZoneDistance;
                }

                m_localWeatherZoneCollider         = null;
                m_localWeatherZoneBlendDistanceSqr = weatherZone.blendDistance * weatherZone.blendDistance;

                // Weather zone has no influence, ignore it
                // Note: Weather zone doesn't do anything when `closestDistanceSqr = blendDistSqr` but
                //       we can't use a >= comparison as blendDistSqr could be set to 0 in which
                //       case weather zone would have total influence
                if (m_localWeatherZoneClosestDistanceSqr > m_localWeatherZoneBlendDistanceSqr)
                {
                    continue;
                }

                // Weather zone has influence
                m_localWeatherZoneInterpolationFactor = 1f;

                if (m_localWeatherZoneBlendDistanceSqr > 0f)
                {
                    m_localWeatherZoneInterpolationFactor = 1f - (m_localWeatherZoneClosestDistanceSqr / m_localWeatherZoneBlendDistanceSqr);
                }

                // No need to clamp01 the interpolation factor as it'll always be in [0;1[ range
                ApplyWeatherZonesInfluence(weatherZone.profile, m_localWeatherZoneInterpolationFactor);
            }
        }
예제 #8
0
 /// <summary>
 /// Changes the current weather profile without transition.
 /// </summary>
 public void SetNewWeatherProfile(AzureWeatherProfile profile)
 {
     m_currentWeatherProfile = profile;
 }