SHA256
forked from ADOFAIEditorForum/ADOFAIRenderer
Add OnLastUpdate Callback to API
This commit is contained in:
3 files changed
+33
-2
No files matched your search
@@ -39,6 +39,7 @@ public class RenderSession
|
||||
|
||||
private Func<bool>? _endCondition;
|
||||
private Action<RenderResult>? _onComplete;
|
||||
private Action? _onLastUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether auto mode is enabled.
|
||||
@@ -114,6 +115,17 @@ public class RenderSession
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a callback action to be invoked on the last update of each frame in the render session.
|
||||
/// </summary>
|
||||
/// <param name="callback">The callback action to execute.</param>
|
||||
/// <returns>The current <see cref="RenderSession"/> instance for method chaining.</returns>
|
||||
public RenderSession OnLastUpdate(Action callback)
|
||||
{
|
||||
_onLastUpdate += callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the configured flags and initiates the render session.
|
||||
/// </summary>
|
||||
@@ -130,6 +142,7 @@ public class RenderSession
|
||||
|
||||
if (_endCondition is not null) RenderContext.EndCondition = _endCondition;
|
||||
if (_onComplete is not null) RenderContext.OnComplete = _onComplete;
|
||||
if (_onLastUpdate is not null) RenderContext.OnLastUpdate = _onLastUpdate;
|
||||
|
||||
RenderManager.Instance.levelPath = levelPath;
|
||||
RenderManager.Instance.Configuration = renderConfig;
|
||||
|
||||
@@ -33,7 +33,7 @@ internal class FirstUpdateHook : MonoBehaviour
|
||||
|
||||
if (RenderManager.Instance)
|
||||
{
|
||||
RenderManager.Instance.OnPreRenderUpdate();
|
||||
RenderManager.Instance.OnPreUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-1
@@ -48,6 +48,9 @@ internal static class RenderContext
|
||||
};
|
||||
public static Action<RenderResult> OnComplete = OnCompleteDefault;
|
||||
|
||||
private static readonly Action OnLastUpdateDefault = () => { };
|
||||
public static Action OnLastUpdate = OnLastUpdateDefault;
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
Auto = true;
|
||||
@@ -58,6 +61,7 @@ internal static class RenderContext
|
||||
|
||||
EndCondition = EndConditionDefault;
|
||||
OnComplete = OnCompleteDefault;
|
||||
OnLastUpdate = OnLastUpdateDefault;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +274,7 @@ internal class RenderManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPreRenderUpdate()
|
||||
public void OnPreUpdate()
|
||||
{
|
||||
if (!IsRendering) return;
|
||||
|
||||
@@ -331,6 +335,8 @@ internal class RenderManager : MonoBehaviour
|
||||
{
|
||||
floor.holdRenderer.m_meshRenderer.enabled = false;
|
||||
}
|
||||
|
||||
TriggerOnLastUpdate();
|
||||
}
|
||||
|
||||
// ReSharper disable once Unity.IncorrectMethodSignature
|
||||
@@ -867,6 +873,18 @@ internal class RenderManager : MonoBehaviour
|
||||
Melon<RenderMod>.Logger.Error($"OnComplete callback caused error: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void TriggerOnLastUpdate()
|
||||
{
|
||||
try
|
||||
{
|
||||
RenderContext.OnLastUpdate.Invoke();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Melon<RenderMod>.Logger.Error($"OnLastUpdate callback caused error: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Codec, AVCodecID> AudioCodecMatch = new()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user