mirror of
https://github.com/originalnicodr/CinematicUnityExplorer.git
synced 2025-07-18 17:38:01 +08:00
Added new safeguards when adding and removing event handlers to the rendering pipeline. Also changed the "reset camera on new freecam sessions" option default value to true, as its more intuitive.
This commit is contained in:
@ -191,7 +191,7 @@ namespace UnityExplorer.Config
|
|||||||
|
|
||||||
Reset_Camera_Transform = new("Reset Camera transform on freecam disable",
|
Reset_Camera_Transform = new("Reset Camera transform on freecam disable",
|
||||||
"Reset the camera position and rotation between freecam sessions, so the freecam always starts from the gameplay position and rotation.",
|
"Reset the camera position and rotation between freecam sessions, so the freecam always starts from the gameplay position and rotation.",
|
||||||
false);
|
true);
|
||||||
|
|
||||||
Arrow_Size = new("Visualizers arrows size",
|
Arrow_Size = new("Visualizers arrows size",
|
||||||
"Cam Paths nodes and Lights Manager lights visualizers' arrow size (must be positive) (needs visualizer toggled to reflect changes).",
|
"Cam Paths nodes and Lights Manager lights visualizers' arrow size (must be positive) (needs visualizer toggled to reflect changes).",
|
||||||
|
@ -1068,40 +1068,48 @@ namespace UnityExplorer.UI.Panels
|
|||||||
ExplorerCore.LogWarning($"Failed to listen to BeforeRender: {exception}");
|
ExplorerCore.LogWarning($"Failed to listen to BeforeRender: {exception}");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// These doesn't exist for Unity <2017 nor when using HDRP
|
|
||||||
Type renderPipelineManagerType = ReflectionUtility.GetTypeByName("RenderPipelineManager");
|
try
|
||||||
if (renderPipelineManagerType != null){
|
{
|
||||||
EventInfo beginFrameRenderingEvent = renderPipelineManagerType.GetEvent("beginFrameRendering");
|
// These doesn't exist for Unity <2017 nor when using HDRP
|
||||||
if (beginFrameRenderingEvent != null) {
|
Type renderPipelineManagerType = ReflectionUtility.GetTypeByName("RenderPipelineManager");
|
||||||
beginFrameRenderingEvent.AddEventHandler(null, OnBeforeEvent);
|
if (renderPipelineManagerType != null){
|
||||||
}
|
EventInfo beginFrameRenderingEvent = renderPipelineManagerType.GetEvent("beginFrameRendering");
|
||||||
EventInfo endFrameRenderingEvent = renderPipelineManagerType.GetEvent("endFrameRendering");
|
if (beginFrameRenderingEvent != null) {
|
||||||
if (endFrameRenderingEvent != null) {
|
beginFrameRenderingEvent.AddEventHandler(null, OnBeforeEvent);
|
||||||
endFrameRenderingEvent.AddEventHandler(null, OnAfterEvent);
|
}
|
||||||
|
EventInfo endFrameRenderingEvent = renderPipelineManagerType.GetEvent("endFrameRendering");
|
||||||
|
if (endFrameRenderingEvent != null) {
|
||||||
|
endFrameRenderingEvent.AddEventHandler(null, OnAfterEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventInfo beginCameraRenderingEvent = renderPipelineManagerType.GetEvent("beginCameraRendering");
|
||||||
|
if (beginCameraRenderingEvent != null) {
|
||||||
|
beginCameraRenderingEvent.AddEventHandler(null, OnBeforeEvent);
|
||||||
|
}
|
||||||
|
EventInfo endCameraRenderingEvent = renderPipelineManagerType.GetEvent("endCameraRendering");
|
||||||
|
if (endCameraRenderingEvent != null) {
|
||||||
|
endCameraRenderingEvent.AddEventHandler(null, OnAfterEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventInfo beginContextRenderingEvent = renderPipelineManagerType.GetEvent("beginContextRendering");
|
||||||
|
if (beginContextRenderingEvent != null) {
|
||||||
|
beginContextRenderingEvent.AddEventHandler(null, OnBeforeEvent);
|
||||||
|
}
|
||||||
|
EventInfo endContextRenderingEvent = renderPipelineManagerType.GetEvent("endContextRendering");
|
||||||
|
if (endContextRenderingEvent != null) {
|
||||||
|
endContextRenderingEvent.AddEventHandler(null, OnAfterEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventInfo beginCameraRenderingEvent = renderPipelineManagerType.GetEvent("beginCameraRendering");
|
EventInfo onBeforeRenderEvent = typeof(Application).GetEvent("onBeforeRender");
|
||||||
if (beginCameraRenderingEvent != null) {
|
if (onBeforeRenderEvent != null) {
|
||||||
beginCameraRenderingEvent.AddEventHandler(null, OnBeforeEvent);
|
onBeforeRenderEvent.AddEventHandler(null, onBeforeRenderAction);
|
||||||
}
|
|
||||||
EventInfo endCameraRenderingEvent = renderPipelineManagerType.GetEvent("endCameraRendering");
|
|
||||||
if (endCameraRenderingEvent != null) {
|
|
||||||
endCameraRenderingEvent.AddEventHandler(null, OnAfterEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
EventInfo beginContextRenderingEvent = renderPipelineManagerType.GetEvent("beginContextRendering");
|
|
||||||
if (beginContextRenderingEvent != null) {
|
|
||||||
beginContextRenderingEvent.AddEventHandler(null, OnBeforeEvent);
|
|
||||||
}
|
|
||||||
EventInfo endContextRenderingEvent = renderPipelineManagerType.GetEvent("endContextRendering");
|
|
||||||
if (endContextRenderingEvent != null) {
|
|
||||||
endContextRenderingEvent.AddEventHandler(null, OnAfterEvent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception exception)
|
||||||
EventInfo onBeforeRenderEvent = typeof(Application).GetEvent("onBeforeRender");
|
{
|
||||||
if (onBeforeRenderEvent != null) {
|
ExplorerCore.LogWarning($"Failed to add event handler to rendering pipeline: {exception}");
|
||||||
onBeforeRenderEvent.AddEventHandler(null, onBeforeRenderAction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1117,41 +1125,48 @@ namespace UnityExplorer.UI.Panels
|
|||||||
ExplorerCore.LogWarning($"Failed to unlisten from BeforeRender: {exception}");
|
ExplorerCore.LogWarning($"Failed to unlisten from BeforeRender: {exception}");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// These doesn't exist for Unity <2017 nor when using HDRP
|
|
||||||
Type renderPipelineManagerType = ReflectionUtility.GetTypeByName("RenderPipelineManager");
|
|
||||||
|
|
||||||
if (renderPipelineManagerType != null){
|
try
|
||||||
EventInfo beginFrameRenderingEvent = renderPipelineManagerType.GetEvent("beginFrameRendering");
|
{
|
||||||
if (beginFrameRenderingEvent != null) {
|
// These doesn't exist for Unity <2017 nor when using HDRP
|
||||||
beginFrameRenderingEvent.RemoveEventHandler(null, OnBeforeEvent);
|
Type renderPipelineManagerType = ReflectionUtility.GetTypeByName("RenderPipelineManager");
|
||||||
}
|
if (renderPipelineManagerType != null){
|
||||||
EventInfo endFrameRenderingEvent = renderPipelineManagerType.GetEvent("endFrameRendering");
|
EventInfo beginFrameRenderingEvent = renderPipelineManagerType.GetEvent("beginFrameRendering");
|
||||||
if (endFrameRenderingEvent != null) {
|
if (beginFrameRenderingEvent != null) {
|
||||||
endFrameRenderingEvent.RemoveEventHandler(null, OnAfterEvent);
|
beginFrameRenderingEvent.RemoveEventHandler(null, OnBeforeEvent);
|
||||||
|
}
|
||||||
|
EventInfo endFrameRenderingEvent = renderPipelineManagerType.GetEvent("endFrameRendering");
|
||||||
|
if (endFrameRenderingEvent != null) {
|
||||||
|
endFrameRenderingEvent.RemoveEventHandler(null, OnAfterEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventInfo beginCameraRenderingEvent = renderPipelineManagerType.GetEvent("beginCameraRendering");
|
||||||
|
if (beginCameraRenderingEvent != null) {
|
||||||
|
beginCameraRenderingEvent.RemoveEventHandler(null, OnBeforeEvent);
|
||||||
|
}
|
||||||
|
EventInfo endCameraRenderingEvent = renderPipelineManagerType.GetEvent("endCameraRendering");
|
||||||
|
if (endCameraRenderingEvent != null) {
|
||||||
|
endCameraRenderingEvent.RemoveEventHandler(null, OnAfterEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventInfo beginContextRenderingEvent = renderPipelineManagerType.GetEvent("beginContextRendering");
|
||||||
|
if (beginContextRenderingEvent != null) {
|
||||||
|
beginContextRenderingEvent.RemoveEventHandler(null, OnBeforeEvent);
|
||||||
|
}
|
||||||
|
EventInfo endContextRenderingEvent = renderPipelineManagerType.GetEvent("endContextRendering");
|
||||||
|
if (endContextRenderingEvent != null) {
|
||||||
|
endContextRenderingEvent.RemoveEventHandler(null, OnAfterEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventInfo beginCameraRenderingEvent = renderPipelineManagerType.GetEvent("beginCameraRendering");
|
EventInfo onBeforeRenderEvent = typeof(Application).GetEvent("onBeforeRender");
|
||||||
if (beginCameraRenderingEvent != null) {
|
if (onBeforeRenderEvent != null) {
|
||||||
beginCameraRenderingEvent.RemoveEventHandler(null, OnBeforeEvent);
|
onBeforeRenderEvent.RemoveEventHandler(null, onBeforeRenderAction);
|
||||||
}
|
|
||||||
EventInfo endCameraRenderingEvent = renderPipelineManagerType.GetEvent("endCameraRendering");
|
|
||||||
if (endCameraRenderingEvent != null) {
|
|
||||||
endCameraRenderingEvent.RemoveEventHandler(null, OnAfterEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
EventInfo beginContextRenderingEvent = renderPipelineManagerType.GetEvent("beginContextRendering");
|
|
||||||
if (beginContextRenderingEvent != null) {
|
|
||||||
beginContextRenderingEvent.RemoveEventHandler(null, OnBeforeEvent);
|
|
||||||
}
|
|
||||||
EventInfo endContextRenderingEvent = renderPipelineManagerType.GetEvent("endContextRendering");
|
|
||||||
if (endContextRenderingEvent != null) {
|
|
||||||
endContextRenderingEvent.RemoveEventHandler(null, OnAfterEvent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception exception)
|
||||||
EventInfo onBeforeRenderEvent = typeof(Application).GetEvent("onBeforeRender");
|
{
|
||||||
if (onBeforeRenderEvent != null) {
|
ExplorerCore.LogWarning($"Failed to remove event handler from rendering pipeline: {exception}");
|
||||||
onBeforeRenderEvent.RemoveEventHandler(null, onBeforeRenderAction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user