69 lines
No EOL
2.5 KiB
C#
69 lines
No EOL
2.5 KiB
C#
using ShiroginSDK.Runtime.Modules.Events;
|
||
using ShiroginSDK.Runtime.Services.Base;
|
||
using ShiroginSDK.Runtime.Services.Interfaces;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace ShiroginSDK.Samples.EventSample.Scripts
|
||
{
|
||
/// <summary>
|
||
/// Simple demonstration UI for sending and receiving custom Shirogin events.
|
||
/// </summary>
|
||
public class EventSampleUI : MonoBehaviour
|
||
{
|
||
[SerializeField]
|
||
private Button noConnectionButton;
|
||
|
||
[SerializeField]
|
||
private Button rewardedAdUnavailableButton;
|
||
|
||
private IEventService _eventService;
|
||
|
||
private void Awake()
|
||
{
|
||
_eventService = ServiceLocator.Get<IEventService>();
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
noConnectionButton.onClick?.AddListener(OnNoConnectionButtonClicked);
|
||
rewardedAdUnavailableButton.onClick?.AddListener(RewardedAdUnavailableButtonClicked);
|
||
|
||
_eventService?.Subscribe<ShiroginEvents.Connection.NoConnectionEvent>(OnNoConnectionEventReceived);
|
||
_eventService?.Subscribe<ShiroginEvents.Ads.RewardedAdUnavailableEvent>(OnRewardedAdUnavailable);
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
if (noConnectionButton != null)
|
||
noConnectionButton.onClick.RemoveAllListeners();
|
||
|
||
_eventService?.Unsubscribe<ShiroginEvents.Connection.NoConnectionEvent>(OnNoConnectionEventReceived);
|
||
_eventService?.Unsubscribe<ShiroginEvents.Ads.RewardedAdUnavailableEvent>(OnRewardedAdUnavailable);
|
||
}
|
||
|
||
|
||
private void OnNoConnectionEventReceived(ShiroginEvents.Connection.NoConnectionEvent e)
|
||
{
|
||
Debug.Log("[EventSampleUI] ❗ No internet connection event received.");
|
||
}
|
||
|
||
private void OnRewardedAdUnavailable(ShiroginEvents.Ads.RewardedAdUnavailableEvent obj)
|
||
{
|
||
Debug.Log("[EventSampleUI] <20><> Rewarded ad unavailable event received.");
|
||
}
|
||
|
||
private void OnNoConnectionButtonClicked()
|
||
{
|
||
Debug.Log("[EventSampleUI] 🔘 Button clicked — sending NoConnectionEvent.");
|
||
_eventService?.Invoke(new ShiroginEvents.Connection.NoConnectionEvent());
|
||
}
|
||
|
||
private void RewardedAdUnavailableButtonClicked()
|
||
{
|
||
Debug.Log("[EventSampleUI] 🔘 Button clicked — sending NoConnectionEvent.");
|
||
_eventService?.Invoke(new ShiroginEvents.Ads.RewardedAdUnavailableEvent(
|
||
"Your custom message here! Ad not available at the moment. Please try again later."));
|
||
}
|
||
}
|
||
} |