using System; using UnityEngine.Serialization; namespace UnityEngine.Rendering.HighDefinition { public partial class PhysicallyBasedSky : IVersionable { /// /// The version used during the migration /// protected enum Version { /// Version Step Initial, /// Version Step TypeEnum, /// Version Step SharedPlanet, /// Latest Version Count, } /// /// The migration steps for PhysicallyBasedSky /// protected static readonly MigrationDescription k_Migration = MigrationDescription.New( MigrationStep.New(Version.TypeEnum, (PhysicallyBasedSky p) => { #pragma warning disable 618 // Type or member is obsolete p.type.value = p.m_ObsoleteEarthPreset.value ? PhysicallyBasedSkyModel.EarthAdvanced : PhysicallyBasedSkyModel.Custom; p.type.overrideState = p.m_ObsoleteEarthPreset.overrideState; #pragma warning restore 618 }), MigrationStep.New(Version.SharedPlanet, (PhysicallyBasedSky p) => { // Previously, ozone was approximated by tinting air, undo that p.airTint.value = Color.white; #if UNITY_EDITOR var profiles = UnityEditor.AssetDatabase.FindAssets("t:" + typeof(VolumeProfile).Name); foreach (var guid in profiles) { var path = UnityEditor.AssetDatabase.GUIDToAssetPath(guid); if (!UnityEditor.AssetDatabase.IsMainAssetAtPathLoaded(path)) continue; var profile = UnityEditor.AssetDatabase.LoadAssetAtPath(path); if (!profile.components.Contains(p)) continue; if (!profile.TryGet(out var env)) env = profile.Add(); #pragma warning disable 618 // Type or member is obsolete var type = p.type.overrideState ? p.type.value : PhysicallyBasedSkyModel.EarthAdvanced; env.planetRadius.value = p.planetaryRadius.value / 1000.0f; env.planetRadius.overrideState = (type == PhysicallyBasedSkyModel.Custom) && p.planetaryRadius.overrideState; env.planetCenter.value = p.planetCenterPosition.value / 1000.0f; env.planetCenter.overrideState = (type != PhysicallyBasedSkyModel.EarthSimple) && p.planetCenterPosition.overrideState; #pragma warning restore 618 UnityEditor.EditorUtility.SetDirty(env); UnityEditor.EditorUtility.SetDirty(profile); return; } #endif }) ); void Awake() { k_Migration.Migrate(this); } [SerializeField] Version m_SkyVersion = MigrationDescription.LastVersion(); Version IVersionable.version { get => m_SkyVersion; set => m_SkyVersion = value; } /// Obsolete field. Simplifies the interface by using parameters suitable to simulate Earth. [SerializeField, FormerlySerializedAs("earthPreset"), Obsolete("For Data Migration")] BoolParameter m_ObsoleteEarthPreset = new BoolParameter(true); /// Radius of the planet (distance from the center of the planet to the sea level). Units: meters. [SerializeField, Obsolete("For Data Migration")] MinFloatParameter planetaryRadius = new MinFloatParameter(k_DefaultEarthRadius, 0); /// Position of the center of the planet in the world space. Units: meters. Does not affect the precomputation. [SerializeField, Obsolete("For Data Migration")] Vector3Parameter planetCenterPosition = new Vector3Parameter(new Vector3(0, -k_DefaultEarthRadius, 0)); } }