using UnityEngine;
using System;
class UnityEventsListener : MonoBehaviour
{
public bool IsEnabled { get; private set; }
public Action enabledHandlers;
public Action disabledHandlers;
private void OnEnable()
{
IsEnabled = true;
enabledHandlers?.Invoke();
}
private void OnDisable()
{
IsEnabled = false;
disabledHandlers?.Invoke();
}
}
// MVRScript:
private UnityEventsListener _pluginUIEventsListener;
public override void InitUI()
{
base.InitUI();
if(this.UITransform == null)
{
return;
}
if(_pluginUIEventsListener == null)
{
_pluginUIEventsListener = UITransform.gameObject.AddComponent<UnityEventsListener>();
_pluginUIEventsListener.enabledHandlers += OnUIEnabled;
_pluginUIEventsListener.disabledHandlers += OnUIDisabled;
}
}
private void OnUIEnabled()
{
// ...
}
private void OnUIDisabled()
{
// ...
}
private void OnDestroy()
{
if(_pluginUIEventsListener != null)
{
UnityEngine.Object.DestroyImmediate(_pluginUIEventsListener);
_pluginUIEventsListener = null;
}
}