r2mods/ilspy_dump/ror2_csproj/RoR2/OnDestroyCallback.cs

31 lines
661 B
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using System;
using UnityEngine;
namespace RoR2;
public class OnDestroyCallback : MonoBehaviour
{
private Action<OnDestroyCallback> callback;
public void OnDestroy()
{
if (callback != null)
{
callback(this);
}
}
public static OnDestroyCallback AddCallback(GameObject gameObject, Action<OnDestroyCallback> callback)
{
OnDestroyCallback onDestroyCallback = gameObject.AddComponent<OnDestroyCallback>();
onDestroyCallback.callback = callback;
return onDestroyCallback;
}
public static void RemoveCallback(OnDestroyCallback callbackComponent)
{
callbackComponent.callback = null;
UnityEngine.Object.Destroy(callbackComponent);
}
}