using Amanotes.TripleSDK.Core; using Newtonsoft.Json; using Plugins.Countly.Enums; using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; namespace Amanotes.TripleSDK.Countly { [InitializeOnLoad] [System.Diagnostics.MonitoringDescription("com.amanotes.sdk.countly")] public class CountlyIntergrate : EditorWindow { private static CountlyConfiguration configuration; private static string ASSET_PATH = "Assets/Resources/countlyconfig.asset"; static CountlyIntergrate() { CreateCountlyDefaultConfig(); PlayerSettings.Android.forceSDCardPermission = true; } private static void CreateCountlyDefaultConfig() { var file = Path.Combine(Application.dataPath, "countlyconfig.json"); if (!File.Exists(file)) { var content = @" { ""ServerUrl"":""https://eventmgt.amanotes.io"", ""AppKey"":""4321da4aa10f0c3cf4e43d13476f5fece6f87ea6"", ""DeviceId"":"""", ""Salt"":"""", ""EnableFirstAppLaunchSegment"":"""", ""EnablePost"":"""", ""EnableConsoleErrorLogging"":"""", ""IgnoreSessionCooldown"":"""", ""NotificationMode"":""-1"", ""EnableManualSessionHandling"":"""", ""SessionDuration"":""5"", ""EventViewSendThreshold"":""1"", ""EventNonViewSendThreshold"":""1"", ""StoredRequestLimit"":""1000"", ""TotalBreadcrumbsAllowed"":""100"", ""EnableAutomaticCrashReporting"":""1"" } "; File.WriteAllText(file, content); } var text = File.ReadAllText(file); configuration = CreateInstance(); JsonUtility.FromJsonOverwrite(text, configuration); } private static void CreateDefaultConfigIfNeed(string filePathJson) { var filePath = "Resources/countlyconfig.asset"; var file = Path.Combine(Application.dataPath, filePath); if (!File.Exists(file)) { var text = File.ReadAllText(filePathJson); var configAsset = CreateInstance(); JsonUtility.FromJsonOverwrite(text, configAsset); AssetDatabase.CreateAsset(configAsset, ASSET_PATH); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } [Serializable] public struct CountlyConfig { public string ServerUrl; public string AppKey; public string DeviceId; public string Salt; public bool EnableFirstAppLaunchSegment; public bool EnablePost; public bool EnableConsoleErrorLogging; public bool IgnoreSessionCooldown; public TestMode NotificationMode; public bool EnableManualSessionHandling; public int SessionDuration; public int EventViewSendThreshold; public int EventNonViewSendThreshold; public int StoredRequestLimit; public int TotalBreadcrumbsAllowed; public bool EnableAutomaticCrashReporting; } public static void CustomRender() { GUIHelper.DrawTitle("Countly Settings"); var serverUrl = GUIHelper.DrawTextField("ServerURL:", configuration.ServerUrl); var appKey = GUIHelper.DrawTextField("AppKey:", configuration.AppKey); var sessionDuration = GUIHelper.DrawIntField("Session Duration:", configuration.SessionDuration); //var eventViewSendThreshold = GUIHelper.DrawIntField("Event View Send Threshold:", configuration.EventViewSendThreshold); var eventNonViewSendThreshold = GUIHelper.DrawIntField("Event Send Threshold:", configuration.EventNonViewSendThreshold); var storedRequestLimit = GUIHelper.DrawIntField("Stored Request Limit:", configuration.StoredRequestLimit); var totalBreadcrumbsAllowed = GUIHelper.DrawIntField("Total Breadcrumbs Allowed:", configuration.TotalBreadcrumbsAllowed); var enableAutomaticCrashReport = GUIHelper.DrawToggleField("Enable Auto Crash Report:", configuration.EnableAutomaticCrashReporting); if (string.IsNullOrEmpty(serverUrl) || string.IsNullOrEmpty(appKey)) { GUILayout.Space(5); GUIHelper.DrawErrorText("* Warning: Invalid iOS App ID"); } if (serverUrl != configuration.ServerUrl || appKey != configuration.AppKey || sessionDuration != configuration.SessionDuration //|| eventViewSendThreshold != configuration.EventViewSendThreshold || eventNonViewSendThreshold != configuration.EventNonViewSendThreshold || storedRequestLimit != configuration.StoredRequestLimit || totalBreadcrumbsAllowed != configuration.TotalBreadcrumbsAllowed || enableAutomaticCrashReport != configuration.EnableAutomaticCrashReporting) { configuration.ServerUrl = serverUrl; configuration.AppKey = appKey; configuration.SessionDuration = sessionDuration; //configuration.EventViewSendThreshold = eventViewSendThreshold; configuration.EventNonViewSendThreshold = eventNonViewSendThreshold; configuration.StoredRequestLimit = storedRequestLimit; configuration.TotalBreadcrumbsAllowed = totalBreadcrumbsAllowed; configuration.EnableAutomaticCrashReporting = enableAutomaticCrashReport; var file = Path.Combine(Application.dataPath, "countlyconfig.json"); var text = JsonUtility.ToJson(configuration); File.WriteAllText(file, text); } } } }