The first method already answers your question, and the lower one uses an attribute that doesn’t exist?
I’ll just assume that what you really want is a method that is called when the game is closed?
In that case, spawn a GameObject, put a MonoBehaviour on it that has the OnApplicationQuit method and react to that.
public static class UnityClass
{
private class Worker : MonoBehaviour
{
private void OnApplicationQuit()
{
Clean();
}
}
[RuntimeInitializeOnLoadMethod( ... )]
private static void UnityInitMethod()
{
Init();
var gameObject = new GameObject("OnApplicationQuit Worker");
gameObject.AddComponent<Worker>();
Object.DontDestroyOnLoad(gameObject);
gameObject.hideFlags = HideFlags.HideAndDontSave;
}
}