using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using NCWWA6A0SDK;
using UnityEditor;
using UnityEngine;

public class NCWWA6A0SDKConfigEditor : EditorWindow
{
    private static NCWWA6A0SDKConfigEditor _view;

private int _emptyKwInterIdCount = 1;
private int _emptyKwVideoIdCount = 1;

private int _emptyBigoInterIdCount = 1;
private int _emptyBigoVideoIdCount = 1;

[MenuItem("Tools/设置 &G")]
public static void ShowWin()
{
    if (_view != null)
    {
        CloseView();
        return;
    }

    var win = GetWindow<NCWWA6A0SDKConfigEditor>();
    win.minSize = new Vector2(790, 872);
    _view = win;
    RemoveExtraEmptyStrings(SDKConfig.KwaiInterUnitId, _view._emptyKwInterIdCount);
    RemoveExtraEmptyStrings(SDKConfig.KwaiVideoUnitId, _view._emptyKwVideoIdCount);
    RemoveExtraEmptyStrings(SDKConfig.BigoInterUnitId, _view._emptyBigoInterIdCount);
    RemoveExtraEmptyStrings(SDKConfig.BigoVideoUnitId, _view._emptyBigoVideoIdCount);
    win.Show();

    #region topon

    // _view.loadPluginData();

    #endregion

    }

    static void CloseView()
{
    _view.Close();
    _view = null;
}

private void OnGUI()
{
    DrawWindow();
    EditorUtility.SetDirty(SDKConfig.Instance);
}

#region Topon
// private AnyThink.Scripts.IntegrationManager.Editor.ATEditorCoroutine loadDataCoroutine;
// private AnyThink.Scripts.IntegrationManager.Editor.PluginData pluginData;
// private bool pluginDataLoadFailed;
// private void loadPluginData()
// {
    // if (loadDataCoroutine != null)
    // {
        // loadDataCoroutine.Stop();
    // }
    // loadDataCoroutine = AnyThink.Scripts.IntegrationManager.Editor.ATEditorCoroutine.startCoroutine(AnyThink.Scripts.IntegrationManager.Editor.ATIntegrationManager.Instance.loadPluginData(data =>
    // {
        // if (data == null)
        // {
            // pluginDataLoadFailed = true;
        // }
        // else
        // {
            // ATLog.log("loadNetworksData() >>> pluginData: " + data);
            // pluginData = data;
            // pluginDataLoadFailed = false;
        // }
    // }));
// }

#endregion

    private void DrawWindow()
{
    TextLabel("基础配置");
    EditorGUILayout.BeginVertical("frameBox");
#if UNITY_IOS
        SDKConfig.Instance.appsFlyerDevKey = DrawTextField("appsFlyerDevKey", SDKConfig.Instance.appsFlyerDevKey);
        SDKConfig.Instance.appsFlyerIosAppleAppId = DrawTextField("appsFlyerIosAppleAppId", SDKConfig.Instance.appsFlyerIosAppleAppId);
#elif UNITY_ANDROID
    SDKConfig.Instance.appsFlyerDevKey = DrawTextField("appsFlyerDevKey", SDKConfig.Instance.appsFlyerDevKey);
#endif
    SDKConfig.Instance.logReportUrl = DrawTextField("配置域名", SDKConfig.Instance.logReportUrl);
    SDKConfig.Instance.appKey = DrawTextField("appKey", SDKConfig.Instance.appKey);
    SDKConfig.Instance.appSecret = DrawTextField("appSecret", SDKConfig.Instance.appSecret);

    EditorGUILayout.EndVertical();

    TextLabel("广告配置");


    #region MAX

    EditorGUILayout.BeginVertical("frameBox");
    TextLabel("MAX", Color.cyan);
    SDKConfig.Instance.maxAppKey = DrawTextField("MaxSdkKey", SDKConfig.Instance.maxAppKey);
    SDKConfig.Instance.videoUnitId = DrawTextField("激励视频 ID", SDKConfig.Instance.videoUnitId);
    SDKConfig.Instance.interUnitId = DrawTextField("插屏 ID", SDKConfig.Instance.interUnitId);
    SDKConfig.Instance.bannerUnitId = DrawTextField("Banner ID", SDKConfig.Instance.bannerUnitId);
    SDKConfig.Instance.splashUnitId = DrawTextField("开屏 ID", SDKConfig.Instance.splashUnitId);
    EditorGUILayout.EndVertical();

    AppLovinSettings.Instance.SdkKey = SDKConfig.Instance.maxAppKey;

    #endregion


        #region Topon

        // EditorGUILayout.BeginVertical("frameBox");
        // TextLabel("Topon", Color.cyan);
        // SDKConfig.Instance.toponAppId = DrawTextField("AppId", SDKConfig.Instance.toponAppId);
        // SDKConfig.Instance.toponAppkey = DrawTextField("Appkey", SDKConfig.Instance.toponAppkey);
        // SDKConfig.Instance.toponVideoUnitId = DrawTextField("激励视频 ID", SDKConfig.Instance.toponVideoUnitId);
        // SDKConfig.Instance.toponInterUnitId = DrawTextField("插屏 ID", SDKConfig.Instance.toponInterUnitId);
        // EditorGUILayout.EndVertical();

        // var integrationManager = AnyThink.Scripts.IntegrationManager.Editor.ATIntegrationManager.Instance;
        // bool isAdmobInstalledForAndroid = integrationManager.isAdmobInstalled(AnyThink.Scripts.IntegrationManager.Editor.ATConfig.OS_ANDROID);
        // bool isAdmobInstalledForIos = integrationManager.isAdmobInstalled(AnyThink.Scripts.IntegrationManager.Editor.ATConfig.OS_IOS);

        // if (isAdmobInstalledForAndroid || isAdmobInstalledForIos)
        // {
            // if (isAdmobInstalledForAndroid)
            // {
                // var androidAdmobAppId = "ca-app-pub-3940256099942544~3347511713";
                // integrationManager.setAdmobAppidByOs(pluginData, AnyThink.Scripts.IntegrationManager.Editor.ATConfig.OS_ANDROID, androidAdmobAppId);
            // }
            // if (isAdmobInstalledForIos)
            // {
                // var iosAdmobAppId = "ca-app-pub-3940256099942544~1458002511";
                // integrationManager.setAdmobAppidByOs(pluginData, AnyThink.Scripts.IntegrationManager.Editor.ATConfig.OS_IOS, iosAdmobAppId);
            // }
        // }

        #endregion

#if UNITY_ANDROID

        EditorGUILayout.BeginVertical("frameBox");
    EditorGUILayout.BeginHorizontal("frameBox");
    TextLabel("KWai", Color.cyan);
    DrawButton("插屏ID +", AddInterId);
    //DrawButton("插屏ID -", DelInterId);
    DrawButton("激励视频ID +", AddRewardId);
    //DrawButton("激励视频ID -", DelRewardId);
    EditorGUILayout.EndHorizontal();
    SDKConfig.Instance.kwaiAppId = DrawTextField("AppId", SDKConfig.Instance.kwaiAppId);

    for (int i = 0; i < SDKConfig.Instance.kwaiInterUnitId.Count; i++)
    {
        var index = i;
        GUILayout.BeginHorizontal();
        SDKConfig.Instance.kwaiInterUnitId[i] =
            DrawTextField("插屏ID - " + (i + 1), SDKConfig.Instance.kwaiInterUnitId[i]);
        DrawButtonX("X", () => DelInterId(index));
        GUILayout.EndHorizontal();

    }

    for (int i = 0; i < SDKConfig.Instance.kwaiVideoUnitId.Count; i++)
    {
        var index = i;
        GUILayout.BeginHorizontal();
        SDKConfig.Instance.kwaiVideoUnitId[i] =
            DrawTextField("激励视频ID - " + (i + 1), SDKConfig.Instance.kwaiVideoUnitId[i]);
        DrawButtonX("X", () => DelRewardId(index));
        GUILayout.EndHorizontal();

    }

    EditorGUILayout.EndVertical();

    EditorGUILayout.BeginVertical("frameBox");
    EditorGUILayout.BeginHorizontal("frameBox");
    TextLabel("Bigo", Color.cyan);
    DrawButton("插屏ID +", AddBigoInterId);
    DrawButton("激励视频ID +", AddBigoRewardId);
    EditorGUILayout.EndHorizontal();
    SDKConfig.Instance.bigoAppId = DrawTextField("AppId", SDKConfig.Instance.bigoAppId);
    SDKConfig.Instance.bigoSplashUnitId = DrawTextField("开屏 ID", SDKConfig.Instance.bigoSplashUnitId);

    for (int i = 0; i < SDKConfig.Instance.bigoInterUnitId.Count; i++)
    {
        //SDKConfig.Instance.bigoInterUnitId = DrawTextField("插屏 ID", SDKConfig.Instance.bigoInterUnitId);
        var index = i;
        GUILayout.BeginHorizontal();
        SDKConfig.Instance.bigoInterUnitId[i] =
            DrawTextField("插屏ID - " + (i + 1), SDKConfig.Instance.bigoInterUnitId[i]);
        DrawButtonX("X", () => DelBigoInterId(index));
        GUILayout.EndHorizontal();
    }

    for (int i = 0; i < SDKConfig.Instance.bigoVideoUnitId.Count; i++)
    {
        //SDKConfig.Instance.bigoVideoUnitId = DrawTextField("激励视频 ID", SDKConfig.Instance.bigoVideoUnitId);
        var index = i;
        GUILayout.BeginHorizontal();
        SDKConfig.Instance.bigoVideoUnitId[i] =
            DrawTextField("激励视频ID - " + (i + 1), SDKConfig.Instance.bigoVideoUnitId[i]);
        DrawButtonX("X", () => DelBigoRewardId(index));
        GUILayout.EndHorizontal();
    }

    EditorGUILayout.EndVertical();
#endif


        EditorGUILayout.BeginVertical("frameBox");
    SDKConfig.Instance.isUseAdmobSplash = DrawBoolField("启用开屏优化", SDKConfig.Instance.isUseAdmobSplash, "");
    if (SDKConfig.Instance.isUseAdmobSplash)
    {
        EditorGUILayout.BeginVertical("frameBox");
        TextLabel("Admob", Color.cyan);
        SDKConfig.Instance.admobAppId = DrawTextField("AppId", SDKConfig.Instance.admobAppId);
        SDKConfig.Instance.admobSplashUnitId = DrawTextField("开屏 ID", SDKConfig.Instance.admobSplashUnitId);
        //SDKConfig.Instance.admobInterUnitId = DrawTextField("插屏 ID", SDKConfig.Instance.admobInterUnitId);
        //SDKConfig.Instance.admobVideoUnitId = DrawTextField("激励视频 ID", SDKConfig.Instance.admobVideoUnitId);

        EditorGUILayout.EndVertical();
    }
    else
    {
        SDKConfig.Instance.admobSplashUnitId = string.Empty;
    }
    EditorGUILayout.EndVertical();

    TextLabel("Debug");
    EditorGUILayout.BeginVertical("frameBox");
    SDKConfig.Instance.isDebug = DrawBoolField("测试模式", SDKConfig.Instance.isDebug, "正式发布时请勿勾选");
    SDKConfig.Instance.isPrintLog = DrawBoolField("日志打印", SDKConfig.Instance.isPrintLog, "正式发布时请勿勾选");
    EditorGUILayout.EndVertical();

    // 水平布局实现按钮靠右
    GUILayout.BeginHorizontal();
    GUILayout.FlexibleSpace(); // 左侧填充弹性空间
    if (GUILayout.Button(new GUIContent("从剪贴板获取参数", _tooltipText),
            GUILayout.Width(120),
            GUILayout.Height(30)
        ))
    {
        ParseClipboard();
    }
    GUILayout.EndHorizontal();


    var sdkVersion = NCWWA6A0SDK_Manager.SdkVersion;
    GUI.Label(new Rect(10, position.height - 40, 400, 40), "@version: " + sdkVersion);

    EditorPrefs.SetString("sdk_version", sdkVersion);
}

private string DrawTextField(string title, string content)
{
    EditorGUILayout.BeginHorizontal();
    GUILayout.Label(title, GUILayout.MinWidth(90), GUILayout.ExpandWidth(false));
    content = GUILayout.TextField(content);
    EditorGUILayout.EndHorizontal();
    return content;
}

private bool DrawBoolField(string title, bool content, string warn = "")
{
    EditorGUILayout.BeginHorizontal();
    GUILayout.Label(title, GUILayout.MinWidth(80), GUILayout.ExpandWidth(false));
    content = EditorGUILayout.Toggle(content);
    if (content)
    {
        TextLabelWarn(warn);
    }
    EditorGUILayout.EndHorizontal();
    return content;
}

private void TextLabel(string content, Color color = new Color())
{
    if (color.Equals(Color.clear))
    {
        color = Color.gray;
    }
    GUIStyle style = new GUIStyle();
    style.contentOffset = new Vector2(8, 0);
    style.normal.textColor = color;
    style.fontSize = 14;
    style.padding = new RectOffset(0, 0, 3, 0);
    GUILayout.Label(content, style);
}

private void TextLabelWarn(string content)
{
    GUIStyle style = new GUIStyle();
    style.contentOffset = new Vector2(8, 0);
    style.normal.textColor = Color.red;
    style.fontSize = 14;
    style.padding = new RectOffset(0, 0, 3, 0);
    GUILayout.Label(content, style);
}

private void DrawButton(string btnName, Action clickAction)
{
    if (GUILayout.Button(btnName, GUILayout.Width(100), GUILayout.Height(30)))
    {
        clickAction?.Invoke();
    }
}

private void DrawButtonX(string btnName, Action clickAction)
{
    var originalBackgroundColor = GUI.backgroundColor;

    // 设置按钮的背景颜色
    GUI.backgroundColor = Color.red;
    if (GUILayout.Button(btnName, GUILayout.Width(40), GUILayout.Height(18)))
    {
        clickAction?.Invoke();
    }

    GUI.backgroundColor = originalBackgroundColor;
}

private void AddInterId()
{
    _emptyKwInterIdCount++;
    SDKConfig.KwaiInterUnitId.Add("");
}

private void DelInterId(int index)
{
    _emptyKwInterIdCount--;
    SDKConfig.KwaiInterUnitId.RemoveAt(index);
}

private void AddRewardId()
{
    _emptyKwVideoIdCount++;
    SDKConfig.KwaiVideoUnitId.Add("");
}

private void DelRewardId(int index)
{
    _emptyKwVideoIdCount--;
    SDKConfig.KwaiVideoUnitId.RemoveAt(index);
}

private void AddBigoInterId()
{
    _emptyBigoInterIdCount++;
    SDKConfig.BigoInterUnitId.Add("");
}

private void DelBigoInterId(int index)
{
    _emptyBigoInterIdCount--;
    SDKConfig.BigoInterUnitId.RemoveAt(index);
}

private void AddBigoRewardId()
{
    _emptyBigoVideoIdCount++;
    SDKConfig.BigoVideoUnitId.Add("");
}

private void DelBigoRewardId(int index)
{
    _emptyBigoVideoIdCount--;
    SDKConfig.BigoVideoUnitId.RemoveAt(index);
}

static void RemoveExtraEmptyStrings(List<string> list, int count)
{
    int emptyCount = count;
    if (list == null) return;
    // 先统计空字符串的数量
    for (int i = list.Count - 1; i >= 0; i--)
    {
        if (string.IsNullOrEmpty(list[i]))
        {
            emptyCount++;
            if (emptyCount > 1)
            {
                // 若空字符串数量超过 1，移除该元素
                list.RemoveAt(i);
            }
        }
    }
}

// ---------------------------- 参数解析 ------------------------------
private string clipboardText = "";
private Dictionary<string, string> parsedParameters = new Dictionary<string, string>();
private readonly string _tooltipText = "需提前在参数列表界面 Ctrl + A 全选，然后再 Ctrl + C 复制";


// 正则表达式模式字典，用于匹配不同类型的广告参数
private static readonly Dictionary<string, string> parameterPatterns = new Dictionary<string, string>
    {
        // App基本信息
        { "App名称", @"App name\s*([^\n]+)" },
        { "AF Dev key", @"AF Dev key(?:[\s-]*iOS)?\s*([^\n]+)"},
        { "APP KEY", @"a\s*p\s*p\s*k\s*e\s*y\s*([^\n]+)"},
        { "APP Secret", @"a\s*p\s*p\s*s\s*e\s*c\s*r\s*e\s*t\s*([^\n]+)" },
        { "包名", @"(?:正式包名|测试包名|包名)\*?\s+([^\n]+)"},
        { "广告源", @"广告源\s*([^\n]+)" },
        { "开发者邮箱", @"开发者邮箱\s*([^\n]+)" },
        { "谷歌商店链接", @"谷歌商店链接\s*([^\n]+)" },
        { "官网链接", @"官网链接\s*([^\n]+)" },
        { "隐私协议", @"隐私协议\s*([^\n]+)" },
        { "业务上报域名", @"(?:业务上报域名|业务域名)\s*([^\n]+)" },
        { "appkey", @"appkey\s*([^\n]+)" },
        { "appsecret", @"appsecret\s*([^\n]+)" },
        {"AF Apple Appid",  @"(?i)app\s*id(?:\s+id)*\s*[=:]*\s*([^\n]*)"},
        
        // MAX (兼容多种格式)
        { "MAX 激励视频", @"MAX参数(?:-[^\s]+)?[\s\S]*?(?:激励视频|激励1|激励2|客户端激励|bidding激励广告位ID|激励)\s*[""\r\n]*([^""\s\r\n]+)"},
        { "MAX 插屏", @"MAX参数(?:-[^\s]+)?[\s\S]*?(?:插屏|插屏1|插屏2|客户端插屏|bidding插屏广告位ID)\s*[""\r\n]*([^""\s\r\n]+)" },
        { "MAX SDK Key", @"MAX参数[\s\S]*?SDK key\*?\s*([^\n]+)" },
        { "MAX ad review key", @"MAX参数[\s\S]*?ad review key\*?\s*([^\n]+)" },
        
        // BIGO (兼容多种格式)
        { "BIGO 应用ID", @"BIGO参数[\s\S]*?(?:应用ID|appid)\s*([^\n]+)" },
        { "BIGO 激励", @"BIGO参数[\s\S]*?(?:激励|激励1|激励2|客户端激励|bidding激励广告位ID)\s*([^\n]+)" },
        { "BIGO 插屏", @"BIGO参数[\s\S]*?(?:插屏|插屏1|插屏2|客户端插屏|bidding插屏广告位ID)\s*([^\n]+)" },
        
        // Kwai (兼容多种格式)
        { "Kwai 应用ID", @"kwai参数[\s\S]*?(?:应用ID|appid)\s*([^\n]+)" },
        { "Kwai 激励", @"kwai参数[\s\S]*?(?:激励|激励1|激励2|客户端激励|bidding激励广告位ID)\s*([^\n]+)" },
        { "Kwai 插屏", @"kwai参数[\s\S]*?(?:插屏|插屏1|插屏2|客户端插屏|bidding插屏广告位ID)\s*([^\n]+)" },
        
        // Admob (兼容多种格式)
        { "Admob 应用ID", @"admob参数[\s\S]*?(?:应用ID|App ID)\s*([^\n]+)" },
        { "Admob 激励", @"admob参数[\s\S]*?(?:激励1|激励)\s*([^\n]+)" },
        { "Admob 插屏", @"admob参数[\s\S]*?(?:插屏1|插屏)\s*([^\n]+)" },
        { "Admob txt", @"admob参数[\s\S]*?txt\s*([^\n]+)" },
        
        // Facebook (兼容多种格式)
        { "FB appid", @"fb参数[\s\S]*?appid\s*([^\n]+)" },
        { "FB property_id", @"fb参数[\s\S]*?property_id\s*([^\n]+)" },
        { "FB 激励", @"fb参数[\s\S]*?激励\s*([^\n]+)" },
        { "FB 插屏", @"fb参数[\s\S]*?插屏\s*([^\n]+)" },
        { "FB txt", @"fb参数[\s\S]*?txt\s*([^\n]+)" },
        
        // Topon (兼容多种格式)
        // Topon (兼容多种格式)
        { "Topon ID", @"(?i)topon[\s\S]*?ID[\t\s]+([^\r\n]+)" },
        { "Topon KEY", @"(?i)topon[\s\S]*?(?:App Key|KEY)[\t\s]+([^\r\n]+)" },
        { "Topon 激励", @"(?i)topon[\s\S]*?激励[\t\s]+([^\r\n]+)" },
        { "Topon 插屏", @"(?i)topon[\s\S]*?插屏[\t\s]+([^\r\n]+)" }
    };

private void ParseClipboard()
{
    if (string.IsNullOrEmpty(clipboardText.Trim()))
    {
        clipboardText = EditorGUIUtility.systemCopyBuffer;
    }

    parsedParameters.Clear();

    foreach (var pattern in parameterPatterns)
    {
        Match match = Regex.Match(clipboardText, pattern.Value, RegexOptions.IgnoreCase);
        if (match.Success)
        {
            // 处理可能有多个捕获组的情况（如BIGO和Kwai的两种格式）
            for (int i = 1; i < match.Groups.Count; i++)
            {
                if (!string.IsNullOrEmpty(match.Groups[i].Value))
                {
                    parsedParameters[pattern.Key] = match.Groups[i].Value.Trim();
                    break;
                }
            }
        }
    }

    UpdateConfig();
    EditorUtility.DisplayDialog("解析完成",
        $"成功解析 {parsedParameters.Count} 个参数", "确定");
}

private void UpdateConfig()
{
    SDKConfig.Instance.bigoVideoUnitId ??= new List<string>();
    SDKConfig.Instance.bigoVideoUnitId.Clear();
    SDKConfig.Instance.bigoInterUnitId ??= new List<string>();
    SDKConfig.Instance.bigoInterUnitId.Clear();

    SDKConfig.Instance.kwaiVideoUnitId ??= new List<string>();
    SDKConfig.Instance.kwaiVideoUnitId.Clear();
    SDKConfig.Instance.kwaiInterUnitId ??= new List<string>();
    SDKConfig.Instance.kwaiInterUnitId.Clear();

    foreach (KeyValuePair<string, string> pair in parsedParameters)
    {
        //Debug.Log($"KEY : {pair.Key}, VALUE : {pair.Value}");
        if (pair.Key.Contains("包名"))
        {
#if UNITY_IOS
            PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, pair.Value);
#elif UNITY_ANDROID
            PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, pair.Value);
#endif

            Debug.Log($"包名设置 : {pair.Value}");
        }

        if (pair.Key.Contains("AF Dev key"))
        {
            Debug.Log($"AF Dev key: {pair.Value}");
            SDKConfig.Instance.appsFlyerDevKey = pair.Value;
        }

#if UNITY_IOS

        if (pair.Key.Contains("AF Apple Appid"))
        {
            Debug.Log($"AF Apple Appid: {pair.Value}");
            SDKConfig.Instance.appsFlyerIosAppleAppId = pair.Value;
        }
#endif

        if (pair.Key.Contains("APP KEY"))
        {
            Debug.Log($"BI APP KEY: {pair.Value}");
            SDKConfig.Instance.appKey = pair.Value;
        }

        if (pair.Key.Contains("APP Secret"))
        {
            Debug.Log($"BI APP Secret: {pair.Value}");
            SDKConfig.Instance.appSecret = pair.Value;
        }

        if (pair.Key.Contains("域名"))
        {
            Debug.Log($"业务域名: {pair.Value}");
            SDKConfig.Instance.logReportUrl = pair.Value;
        }

        if (pair.Key.Contains("Topon ID"))
        {
            Debug.Log($"Topon APP ID: {pair.Value}");
            SDKConfig.Instance.toponAppId = pair.Value;
        }

        if (pair.Key.Contains("Topon KEY"))
        {
            Debug.Log($"Topon APP KEY: {pair.Value}");
            SDKConfig.Instance.toponAppkey = pair.Value;
        }

        if (pair.Key.Contains("Topon 激励"))
        {
            Debug.Log($"Topon 激励: {pair.Value}");
            SDKConfig.Instance.toponVideoUnitId = pair.Value;
        }

        if (pair.Key.Contains("Topon 插屏"))
        {
            Debug.Log($"Topon 插屏: {pair.Value}");
            SDKConfig.Instance.toponInterUnitId = pair.Value;
        }

        if (pair.Key.Contains("MAX SDK Key"))
        {
            Debug.Log($"MAX SDK Key: {pair.Value}");
            SDKConfig.Instance.maxAppKey = pair.Value;
        }

        if (pair.Key.Contains("MAX 激励视频"))
        {
            Debug.Log($"MAX 激励视频: {pair.Value}");
            SDKConfig.Instance.videoUnitId = pair.Value;
        }

        if (pair.Key.Contains("MAX 插屏"))
        {
            Debug.Log($"MAX 插屏: {pair.Value}");
            SDKConfig.Instance.interUnitId = pair.Value;
        }

        if (pair.Key.Contains("BIGO 应用ID"))
        {
            Debug.Log($"BIGO 应用ID: {pair.Value}");
            SDKConfig.Instance.bigoAppId = pair.Value;
        }

        if (pair.Key.Contains("BIGO 激励"))
        {
            Debug.Log($"BIGO 激励: {pair.Value}");
            //SDKConfig.Instance.bigoVideoUnitId = pair.Value;
            SDKConfig.Instance.bigoVideoUnitId ??= new List<string>();
            SDKConfig.Instance.bigoVideoUnitId.Add(pair.Value);
        }

        if (pair.Key.Contains("BIGO 插屏"))
        {
            Debug.Log($"BIGO 插屏: {pair.Value}");
            //SDKConfig.Instance.bigoInterUnitId = pair.Value;
            SDKConfig.Instance.bigoInterUnitId ??= new List<string>();
            SDKConfig.Instance.bigoInterUnitId.Add(pair.Value);
        }

        if (pair.Key.Contains("Admob 应用ID"))
        {
            Debug.Log($"Admob 应用ID: {pair.Value}");
            //SDKConfig.Instance.admobAppId = pair.Value;
        }

        if (pair.Key.Contains("Admob 激励"))
        {
            Debug.Log($"Admob 激励: {pair.Value}");
        }

        if (pair.Key.Contains("Admob 插屏"))
        {
            Debug.Log($"Admob 插屏: {pair.Value}");
        }

        if (pair.Key.Contains("Kwai 应用ID"))
        {
            Debug.Log($"Kwai 应用ID: {pair.Value}");
            SDKConfig.Instance.kwaiAppId = pair.Value;
        }

        if (pair.Key.Contains("Kwai 激励"))
        {
            Debug.Log($"Kwai 激励: {pair.Value}");
            SDKConfig.Instance.kwaiVideoUnitId ??= new List<string>();
            SDKConfig.Instance.kwaiVideoUnitId.Add(pair.Value);
        }

        if (pair.Key.Contains("Kwai 插屏"))
        {
            Debug.Log($"Kwai 插屏: {pair.Value}");
            SDKConfig.Instance.kwaiInterUnitId ??= new List<string>();
            SDKConfig.Instance.kwaiInterUnitId.Add(pair.Value);
        }
    }
}

}
