SerializedProperty的属性名获取

/// <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);
	}
}

此时输出:
在这里插入图片描述
我们再看到:

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);
}

此时输出:
在这里插入图片描述
比如我们想得到:m_AtlasSize这个属性:

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);

这样就解释了:https://forum.unity.com/threads/access-lighting-window-properties-in-script.328342/
这个博客里的内容了。

关于Lighting面板的设置都在这里了

     	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);
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值