Firstborn/Library/PackageCache/com.unity.ads@3.7.5/Editor/DevX/Settings/TestModeUi.cs

40 lines
1.2 KiB
C#
Raw Normal View History

2023-03-28 13:24:16 -04:00
#if SERVICES_SDK_CORE_ENABLED
using UnityEditor.Advertisements;
using UnityEngine.UIElements;
namespace UnityEngine.Advertisements.Editor
{
class TestModeUi : VisualElement
{
public TestModeUi()
{
var container = UiUtils.GetUiFromTemplate(UiConstants.UiTemplatePaths.TestMode);
if (container is null)
{
var message = string.Format(
UiConstants.Formats.TemplateNotFound, nameof(UiConstants.UiTemplatePaths.TestMode));
Debug.LogError(message);
return;
}
Add(container);
var toggle = container.Q<Toggle>(UiConstants.UiElementNames.TestModeToggle);
if (toggle is null)
{
return;
}
toggle.SetValueWithoutNotify(AdvertisementSettings.testMode);
toggle.RegisterValueChangedCallback(OnTestModeToggleChanged);
}
static void OnTestModeToggleChanged(ChangeEvent<bool> changeEvent)
{
EditorGameServiceAnalyticsSender.SendProjectSettingsEnableTestModeEvent(changeEvent.newValue);
AdvertisementSettings.testMode = changeEvent.newValue;
}
}
}
#endif