SerializedProperty acquisition of property name

/// <summary>
/// https://forum.unity.com/threads/access-lighting-window-properties-in-script.328342/
/// </summary>
/// <returns></returns>
public static SerializedObject GetLighmapSettings()
{
   var getLightmapSettingsMethod = typeof(LightmapEditorSettings).GetMethod("GetLightmapSettings", 
   													BindingFlags.Static | BindingFlags.NonPublic);
   LightmapSettings lightmapSettings = getLightmapSettingsMethod.Invoke(null, null) as LightmapSettings;
   return new SerializedObject(lightmapSettings);
}

public static void TraversePropertyNames()
{
	SerializedObject so = GetLighmapSettings();
	var prop = so.GetIterator();
	while (prop.Next(true))
	{
	    Debug.LogError(prop.name);
	}
}

Then the output:
Here Insert Picture Description
Let us see:

SerializedObject so = GetLighmapSettings();
SerializedProperty sp = so.FindProperty("m_LightmapEditorSettings");
var prop = so.GetIterator();
while (prop.Next(true))
{
    Debug.LogError(prop.name + "  depth=" + prop.depth + "  hasChildren=" + prop.hasChildren);
}

At this time, output:
Here Insert Picture Description
For example, we want: m_AtlasSize this property:

SerializedProperty sp = so.FindProperty("m_LightmapEditorSettings");
var prop = so.GetIterator();
while (prop.Next(true))
{
    //Debug.LogError(prop.name + "  depth=" + prop.depth + "  hasChildren=" + prop.hasChildren);
}
sp = so.FindProperty("m_LightmapEditorSettings.m_AtlasSize");
Debug.LogError(sp.name);

This explains: https: //forum.unity.com/threads/access-lighting-window-properties-in-script.328342/
this blog content.

Lighting panels are set up on here

     	SerializedObject so = GetLighmapSettings();
        SerializedProperty sp = so.FindProperty("m_GIWorkflowMode");
        sp.intValue = 1; //https://docs.unity3d.com/ScriptReference/Lightmapping.GIWorkflowMode.html
        sp = so.FindProperty("m_GISettings.m_BounceScale");
        sp = so.FindProperty("m_GISettings.m_IndirectOutputScale");
        sp = so.FindProperty("m_GISettings.m_AlbedoBoost");
        sp = so.FindProperty("m_GISettings.m_EnvironmentLightingMode");
        sp = so.FindProperty("m_GISettings.m_EnableBakedLightmaps");
        sp.boolValue = true;
        sp = so.FindProperty("m_GISettings.m_EnableRealtimeLightmaps");
        sp.boolValue = false;
        mixedBakeMode = MixedLightingMode.Shadowmask; //需要重启Lighting窗口
        lightmapper = Lightmapper.ProgressiveCPU;     //需要重启Lighting窗口
        prioritizeView = true;
        sp = so.FindProperty("m_LightmapEditorSettings.m_PVREnvironmentMIS"); //mulitiple importance sampling
        sp.intValue = 0;
        sp = so.FindProperty("m_LightmapEditorSettings.m_PVRDirectSampleCount");
        sp.intValue = 32;
        sp = so.FindProperty("m_LightmapEditorSettings.m_PVRSampleCount");
        sp.intValue = 8;
        sp = so.FindProperty("m_LightmapEditorSettings.m_PVREnvironmentSampleCount");
        sp.intValue = 128;
        sp = so.FindProperty("m_LightmapEditorSettings.m_PVRBounces");
        sp.intValue = 2;
        sp = so.FindProperty("m_LightmapEditorSettings.m_PVRFilteringMode");
        sp.enumValueIndex = 1;

        bakeResolution = 30; //lightmap resolution
        padding = 4; //lightmap padding
        maxAtlasSize = 512; //lightmap size
        textureCompression = false; //compress lightmaps
        enableAmbientOcclusion = true; //ambient occlusion
        aoMaxDistance = 2; //max distance
        sp = so.FindProperty("m_LightmapEditorSettings.m_CompAOExponent");
        sp = so.FindProperty("m_LightmapEditorSettings.m_CompAOExponentDirect");
        aoExponentDirect = 4;  //indirect contribution
        aoExponentIndirect = 3; //direct contribution
        lightmapsMode = LightmapsMode.CombinedDirectional; //direcitonal mode
        sp = so.FindProperty("m_GISettings.m_IndirectOutputScale");
        sp.floatValue = 2.3f; //indirect intensity
        sp = so.FindProperty("m_GISettings.m_AlbedoBoost");
        sp.floatValue = 3.23f;
        sp = so.FindProperty("m_LightmapEditorSettings.m_LightmapParameters");
        sp.objectReferenceValue = bakeConfig.lightmapParameters; //lightmap parameters

        so.ApplyModifiedProperties();
        var prop = so.GetIterator();
        while (prop.Next(true))
        {
            Debug.LogError(prop.name + "  depth=" + prop.depth + "  hasChildren=" + prop.hasChildren);
        }
Published 646 original articles · won praise 107 · views 360 000 +

Guess you like

Origin blog.csdn.net/wodownload2/article/details/105090284