This repository was archived by the owner on Dec 24, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 11// Copyright (c) 2012-2019 Wojciech Figat. All rights reserved.
22
33using System ;
4+ using System . Collections . Generic ;
45using System . Runtime . CompilerServices ;
56
67namespace 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 ( )
You can’t perform that action at this time.
0 commit comments