Skip to content

Instantly share code, notes, and snippets.

@charlieamat
Created November 10, 2020 23:09
Show Gist options
  • Save charlieamat/372001589fd7927eff7aeecdb46ca92b to your computer and use it in GitHub Desktop.
Save charlieamat/372001589fd7927eff7aeecdb46ca92b to your computer and use it in GitHub Desktop.
An example of the compiler generating classes for anonymous functions.
using UnityEngine;
using UnityEngine.Events;
public class SimpleClass : MonoBehaviour
{
private UnityEvent _event;
private void Awake()
{
_event.AddListener(() =>
{
Debug.Log("Fire!");
});
}
}
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Events;
public class SimpleClass : MonoBehaviour
{
private UnityEvent _event;
private void Awake()
{
// ISSUE: method pointer
this._event.AddListener(SimpleClass.<>c.<>9__1_0 ?? (SimpleClass.<>c.<>9__1_0 = new UnityAction((object) SimpleClass.<>c.<>9, __methodptr(<Awake>b__1_0))));
}
public SimpleClass()
{
base.\u002Ector();
}
[CompilerGenerated]
[Serializable]
private sealed class <>c
{
public static readonly SimpleClass.<>c <>9;
public static UnityAction <>9__1_0;
static <>c()
{
SimpleClass.<>c.<>9 = new SimpleClass.<>c();
}
public <>c()
{
base.\u002Ector();
}
internal void <Awake>b__1_0()
{
Debug.Log((object) "Fire!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment