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);
        }
发布了655 篇原创文章 · 获赞 109 · 访问量 37万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 酷酷鲨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览