Skip to content

Instantly share code, notes, and snippets.

@strich
Created November 1, 2018 16:55
Show Gist options
  • Save strich/19e71f3bd42ef13412df7bcb3e27426e to your computer and use it in GitHub Desktop.
Save strich/19e71f3bd42ef13412df7bcb3e27426e to your computer and use it in GitHub Desktop.
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