SHA256
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 Func<bool>? _endCondition;
|
||||||
private Action<RenderResult>? _onComplete;
|
private Action<RenderResult>? _onComplete;
|
||||||
|
private Action? _onLastUpdate;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets whether auto mode is enabled.
|
/// Sets whether auto mode is enabled.
|
||||||
@@ -114,6 +115,17 @@ public class RenderSession
|
|||||||
return this;
|
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>
|
/// <summary>
|
||||||
/// Applies the configured flags and initiates the render session.
|
/// Applies the configured flags and initiates the render session.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -130,6 +142,7 @@ public class RenderSession
|
|||||||
|
|
||||||
if (_endCondition is not null) RenderContext.EndCondition = _endCondition;
|
if (_endCondition is not null) RenderContext.EndCondition = _endCondition;
|
||||||
if (_onComplete is not null) RenderContext.OnComplete = _onComplete;
|
if (_onComplete is not null) RenderContext.OnComplete = _onComplete;
|
||||||
|
if (_onLastUpdate is not null) RenderContext.OnLastUpdate = _onLastUpdate;
|
||||||
|
|
||||||
RenderManager.Instance.levelPath = levelPath;
|
RenderManager.Instance.levelPath = levelPath;
|
||||||
RenderManager.Instance.Configuration = renderConfig;
|
RenderManager.Instance.Configuration = renderConfig;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ internal class FirstUpdateHook : MonoBehaviour
|
|||||||
|
|
||||||
if (RenderManager.Instance)
|
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;
|
public static Action<RenderResult> OnComplete = OnCompleteDefault;
|
||||||
|
|
||||||
|
private static readonly Action OnLastUpdateDefault = () => { };
|
||||||
|
public static Action OnLastUpdate = OnLastUpdateDefault;
|
||||||
|
|
||||||
public static void Reset()
|
public static void Reset()
|
||||||
{
|
{
|
||||||
Auto = true;
|
Auto = true;
|
||||||
@@ -58,6 +61,7 @@ internal static class RenderContext
|
|||||||
|
|
||||||
EndCondition = EndConditionDefault;
|
EndCondition = EndConditionDefault;
|
||||||
OnComplete = OnCompleteDefault;
|
OnComplete = OnCompleteDefault;
|
||||||
|
OnLastUpdate = OnLastUpdateDefault;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +274,7 @@ internal class RenderManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPreRenderUpdate()
|
public void OnPreUpdate()
|
||||||
{
|
{
|
||||||
if (!IsRendering) return;
|
if (!IsRendering) return;
|
||||||
|
|
||||||
@@ -331,6 +335,8 @@ internal class RenderManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
floor.holdRenderer.m_meshRenderer.enabled = false;
|
floor.holdRenderer.m_meshRenderer.enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TriggerOnLastUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once Unity.IncorrectMethodSignature
|
// ReSharper disable once Unity.IncorrectMethodSignature
|
||||||
@@ -868,6 +874,18 @@ internal class RenderManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
private static readonly Dictionary<Codec, AVCodecID> AudioCodecMatch = new()
|
||||||
{
|
{
|
||||||
[Codec.H264] = AVCodecID.AV_CODEC_ID_AAC,
|
[Codec.H264] = AVCodecID.AV_CODEC_ID_AAC,
|
||||||
|
|||||||
Reference in new issue
Block a user