mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-17 06:28:42 +08:00
Fallback to LateUpdate if OnPostRender listener failed
This commit is contained in:
parent
3e42d7479f
commit
211576e0f8
@ -32,16 +32,32 @@ namespace UnityExplorer
|
|||||||
public ExplorerBehaviour(IntPtr ptr) : base(ptr) { }
|
public ExplorerBehaviour(IntPtr ptr) : base(ptr) { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
private static bool onPostRenderFailed;
|
||||||
|
|
||||||
internal void Awake()
|
internal void Awake()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
#if CPP
|
#if CPP
|
||||||
Camera.onPostRender = Camera.onPostRender == null
|
Camera.onPostRender = Camera.onPostRender == null
|
||||||
? new Action<Camera>(OnPostRender)
|
? new Action<Camera>(OnPostRender)
|
||||||
: Il2CppSystem.Delegate.Combine(Camera.onPostRender, (Camera.CameraCallback)new Action<Camera>(OnPostRender)).Cast<Camera.CameraCallback>();
|
: Il2CppSystem.Delegate.Combine(Camera.onPostRender,
|
||||||
|
(Camera.CameraCallback)new Action<Camera>(OnPostRender)).Cast<Camera.CameraCallback>();
|
||||||
|
|
||||||
|
if (Camera.onPostRender == null || Camera.onPostRender.delegates == null)
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning("Failed to add Camera.onPostRender listener, falling back to LateUpdate instead!");
|
||||||
|
onPostRenderFailed = true;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
Camera.onPostRender += OnPostRender;
|
Camera.onPostRender += OnPostRender;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning($"Exception adding onPostRender listener: {ex.ReflectionExToString()}\r\nFalling back to LateUpdate!");
|
||||||
|
onPostRenderFailed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Update()
|
internal void Update()
|
||||||
@ -54,7 +70,13 @@ namespace UnityExplorer
|
|||||||
ExplorerCore.FixedUpdate();
|
ExplorerCore.FixedUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void OnPostRender(Camera camera)
|
internal void LateUpdate()
|
||||||
|
{
|
||||||
|
if (onPostRenderFailed)
|
||||||
|
OnPostRender(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnPostRender(Camera _)
|
||||||
{
|
{
|
||||||
ExplorerCore.OnPostRender();
|
ExplorerCore.OnPostRender();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user