Discard member from IL using ILPostProcessor in Unity. lThis may be useful in IL2CPP to prevent reading const and enum from the metadata.
using ILDiscard;
[DiscardMembers(DiscardMembersOptions.DiscardByDefault)]
public enum MyEnum
{
A,
B,
[DontDiscard]
C
}
[Discard]
class Constants
{
public const int CONSTVALUE100 = 100;
}
[DiscardMembers]
public class NewScript : MonoBehaviour
{
[Discard]
const int CONSTVALUE = 100;
public MyEnum myEnum;
[Discard]
public int Value;
void Start()
{
Debug.Log("CONSTVALUE" + CONSTVALUE);
Debug.Log(Constants.CONSTVALUE100);
}
}- Open the Package Manager by going to Window > Package Manager.
- Click on the "+" button and select "Add package from git URL".
- Enter the following URL:
https://github.com/Akeit0/ILDiscard.git?path=/Assets/ILDiscard
Open Packages/manifest.json and add the following in the dependencies block:
"com.akeit0.ildiscard": "https://github.com/Akeit0/ILDiscard.git?path=/Assets/ILDiscard"