Search Unity

How to change the static light sky in Lighting Settings Window by script

Discussion in 'High Definition Render Pipeline' started by BerengerVolumiq, Apr 28, 2020.

  1. BerengerVolumiq

    BerengerVolumiq

    Joined:
    Feb 6, 2017
    Posts:
    14
    I'm trying to set those two values at editor time, but I can't find where it is, anyone has an idea ?

    a.png
     
  2. Hysparions

    Hysparions

    Joined:
    Jan 7, 2019
    Posts:
    29
    Hello ! Did you find a solution for this ?
     
  3. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    I already asked but no one write the answer... also i searched on the unity C# source without result
     
  4. Hysparions

    Hysparions

    Joined:
    Jan 7, 2019
    Posts:
    29
    Hi everyone, finally managed to do it reading hdrp source.
    What you have to do is getting static lighting sky instance of the scene holding that data
    Code (CSharp):
    1. StaticLightingSky staticSky;
    2. Scene scene = SceneManager.GetActiveScene();
    3. foreach(var go in scene.GetRootGameObjects)
    4. {
    5.       staticSky = go.GetComponent<StaticLightingSky>();
    6.       if(staticSky != null) break;
    7. }
    8.  
    Then you can change the static sky profile and the static sky id to use in that profile. I made an helper function
    Code (CSharp):
    1. public void UpdateStaticLightingSky(VolumeProfile profile)
    2.     {
    3.      
    4.         staticSky.profile = profile;
    5.      
    6.         HDRISky hdriSky;
    7.         profile.TryGet<HDRISky>(out hdriSky);
    8.         if (hdriSky != null)
    9.         { staticSky.staticLightingSkyUniqueID = SkySettings.GetUniqueID(hdriSky.GetType()); return; }
    10.  
    11.         GradientSky gradientSky;
    12.         profile.TryGet<GradientSky>(out gradientSky);
    13.         if (gradientSky != null)
    14.         { staticSky.staticLightingSkyUniqueID = SkySettings.GetUniqueID(gradientSky.GetType()); return; }
    15.  
    16.         PhysicallyBasedSky physicalSky;
    17.         profile.TryGet<PhysicallyBasedSky>(out physicalSky);
    18.         if (physicalSky != null)
    19.         { staticSky.staticLightingSkyUniqueID = SkySettings.GetUniqueID(physicalSky.GetType()); return; }
    20.  
    21.     }
     
    RhAnjiE likes this.