-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91887e3
commit 0432a12
Showing
6 changed files
with
213 additions
and
171 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
VisualPinball.Unity/VisualPinball.Unity/Common/LazyInit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
|
||
namespace VisualPinball.Unity | ||
{ | ||
public class LazyInit<T> | ||
{ | ||
private bool isInitialized = false; | ||
private T value; | ||
public ref T Ref | ||
{ | ||
get | ||
{ | ||
if (!isInitialized) { | ||
isInitialized = true; | ||
value = constructor(); | ||
} | ||
return ref value; | ||
} | ||
} | ||
|
||
private readonly Func<T> constructor; | ||
|
||
public LazyInit(Func<T> constructor) | ||
{ | ||
this.constructor = constructor; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
VisualPinball.Unity/VisualPinball.Unity/Common/LazyInit.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.