Created
November 1, 2018 16:55
-
-
Save strich/19e71f3bd42ef13412df7bcb3e27426e to your computer and use it in GitHub Desktop.
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
using System.Runtime.CompilerServices; | |
using UnityEngine; | |
public class MyScripty : MonoBehaviour | |
{ | |
void Start() | |
{ | |
var writer = new SingletonWriter<MyStruct>(new MyStruct() { Int = 1 }); | |
var val = writer.InspectMe; // Set a breakpoint here and inspect "InspectMe" with your mouse hover | |
Debug.Log($"Ahoy {val}"); | |
} | |
} | |
public sealed class SingletonWriter<T> | |
{ | |
private T _value; | |
public SingletonWriter(T val) | |
{ | |
_value = val; | |
} | |
public ref readonly T InspectMe { | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
get => ref _value; | |
} | |
} | |
public struct MyStruct | |
{ | |
public int Int; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment