I’m attempting to develop a device for baking gentle in Unity however with some modifications and additions.
At present, what I need to obtain is for the instructions Generate Lighting
, Bake Reflection Probes
, and Clear Baked Information
to perform equally to how they do within the Lighting window
. Nevertheless, Unity doesn’t present a direct API for these capabilities.
To work round this, I created a debugging device to record all out there technique names within the Lighting window
, then I known as them (the talked about capabilities) by their names, which I discovered by way of the debugging outcomes.
So, I’ve two questions:
1- Is there a greater method to obtain this? (At present, this strategy works nicely since it’s executed solely as soon as inside the editor and doesn’t have an effect on the baking outcomes or the sport’s efficiency.)
2- Does this technique violate any of Unity’s copyrights or insurance policies?
Observe: I do know that I can entry it by way of Lightmapping, however generally the outcomes differ or develop into inaccessible.
The debugging device code:
utilizing System.Reflection;
utilizing UnityEditor;
utilizing UnityEngine;
public class DebugLightingWindowMethods : EditorWindow
{
[MenuItem("Special Tools/Debug Lighting Window Methods")]
public static void DebugMethods()
{
System.Kind lightingWindowType = typeof(EditorWindow).Meeting.GetType("UnityEditor.LightingWindow");
if (lightingWindowType == null)
{
Debug.LogError("LightingWindow sort not discovered!");
return;
}
MethodInfo[] strategies = lightingWindowType.GetMethods(BindingFlags.Occasion | BindingFlags.NonPublic | BindingFlags.Public);
Debug.Log($"Discovered {strategies.Size} strategies in LightingWindow:");
foreach (MethodInfo technique in strategies)
{
Debug.Log($"Technique: {technique.Identify}");
}
}
}
The perform by which I name the strategies:
void InvokeLightingWindowMethod(string methodName)
{
System.Kind lightingWindowType = typeof(EditorWindow).Meeting.GetType("UnityEditor.LightingWindow");
EditorWindow lightingWindow = EditorWindow.GetWindow(lightingWindowType);
MethodInfo technique = lightingWindowType.GetMethod(methodName, BindingFlags.Occasion | BindingFlags.NonPublic);
if (technique != null)
{
technique.Invoke(lightingWindow, null);
}
else
{
Debug.LogError($"Couldn't discover technique '{methodName}' in {lightingWindowType}.");
}
}