using Amanotes.TripleSDK.Core; using Amanotes.TripleSDK.Core.Analytics; using Amanotes.TripleSDK.Core.Configuration; using Newtonsoft.Json; using Plugins.Countly; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Amanotes.TripleSDK.Countly { [InjectService(Order = -100000, Package = "AmaCountly")] [StartupService] [ServiceConfiguration(Name = "countlyconfig", Type = typeof(CountlyConfiguration))] public class CountlyService : CountlyServiceBase, IStartup { public CountlyConfiguration configuration { get; private set; } public void Startup() { configuration = Bootstrap.Instance.GetRequiredService(). GetConfiguration(); if (configuration == null) { serviceStatus = ServiceStatus.Unvailable; Debug.LogError("CountlyService initializing is failed. Configuration not found."); return; } #if !UNITY_EDITOR if (Plugins.Countly.Impl.Countly.Instance != null) { return; } #endif Init(); serviceStatus = ServiceStatus.Available; Bootstrap.Instance.OnServiceUpdate(this); } public override void Init() { var Auth = new Plugins.Countly.Models.CountlyAuthModel { AppKey = configuration.AppKey, DeviceId = configuration.DeviceId, ServerUrl = configuration.ServerUrl }; var Config = new Plugins.Countly.Models.CountlyConfigModel( configuration.Salt, configuration.EnablePost, configuration.EnableConsoleErrorLogging, configuration.IgnoreSessionCooldown, configuration.EnableManualSessionHandling, configuration.SessionDuration, configuration.EventViewSendThreshold, configuration.StoredRequestLimit, configuration.TotalBreadcrumbsAllowed, configuration.NotificationMode, configuration.EnableAutomaticCrashReporting ); #if !UNITY_EDITOR var Countly = this.gameObject.AddComponent(); Countly.Auth = Auth; Countly.Config = Config; #else CountlyWrapper = this.gameObject.AddComponent(); #endif } protected override IEnumerator LazyLogEvent(string eventName, Dictionary param = null) { #if !UNITY_EDITOR var checkNull = Plugins.Countly.Impl.Countly.Instance.Events == null; #else var checkNull = CountlyWrapper.Events == null; #endif while (GetStatus() != ServiceStatus.Available || checkNull) { yield return null; } if (param != null) { #if !UNITY_EDITOR Plugins.Countly.Impl.Countly.Instance.Events.ReportCustomEventAsync(eventName, param); #else CountlyWrapper.Events.ReportCustomEventAsync(eventName, param); #endif } else { #if !UNITY_EDITOR Plugins.Countly.Impl.Countly.Instance.Events.RecordEventAsync(eventName); #else CountlyWrapper.Events.RecordEventAsync(eventName); #endif } } } }