Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit 8b4013f

Browse files
committed
Add Scripting.InvokeOnUpdate
(cherry picked from commit 3baa66a)
1 parent 1f6246f commit 8b4013f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

FlaxEngine/API/Static/Scripting.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2012-2019 Wojciech Figat. All rights reserved.
22

33
using System;
4+
using System.Collections.Generic;
45
using System.Runtime.CompilerServices;
56

67
namespace FlaxEngine
@@ -10,6 +11,8 @@ namespace FlaxEngine
1011
/// </summary>
1112
public static class Scripting
1213
{
14+
private static readonly List<Action> UpdateActions = new List<Action>();
15+
1316
/// <summary>
1417
/// Occurs on scripting update.
1518
/// </summary>
@@ -30,10 +33,31 @@ public static class Scripting
3033
/// </summary>
3134
public static event Action Exit;
3235

36+
/// <summary>
37+
/// Calls the given action on the next scripting update.
38+
/// </summary>
39+
/// <param name="action">The action to invoke.</param>
40+
public static void InvokeOnUpdate(Action action)
41+
{
42+
UpdateActions.Add(action);
43+
}
44+
3345
internal static void Internal_Update()
3446
{
3547
Time.SyncData();
3648
Update?.Invoke();
49+
for (int i = 0; i < UpdateActions.Count; i++)
50+
{
51+
try
52+
{
53+
UpdateActions[i]();
54+
}
55+
catch (Exception ex)
56+
{
57+
Debug.LogException(ex);
58+
}
59+
}
60+
UpdateActions.Clear();
3761
}
3862

3963
internal static void Internal_LateUpdate()

0 commit comments

Comments
 (0)