using System.Runtime.InteropServices;
using UnityEngine;

public class CallingNativeMethods
{
    private CallingNativeMethods() { }
    private static readonly CallingNativeMethods singleInstance = new CallingNativeMethods();
    public static CallingNativeMethods Instance
    {
        get
        {
            return singleInstance;
        }
    }

#if UNITY_ANDROID
    private AndroidJavaObject activity;
    public AndroidJavaObject GetActivity()
    {
        if (activity == null)
        {
            var unityPlayer = new AndroidJavaClass(
            "com.unity3d.player.UnityPlayer");
            activity = unityPlayer.GetStatic<AndroidJavaObject>(
           "currentActivity");
        }
        return activity;
    }
#endif

    /// <summary>
    /// 注册初始化微信登录
    /// </summary>
    public void InitWxLogin()
    {
#if UNITY_EDITOR
        Debug.unityLogger.Log("初始化微信登录" + Constant.Instance.WX_APP_ID);
#elif UNITY_ANDROID
        AndroidJavaObject WxLoginUtil = new AndroidJavaClass("com.ym.unityandroid.UnityWxLoginUtil").CallStatic<AndroidJavaObject>("getInstance");
        WxLoginUtil.Call("InitWxLogin", GetActivity(), Constant.Instance.WX_APP_ID);
#endif

    }

    /// <summary>
    /// 微信登录
    /// </summary>
    public void WeChatLogin()
    {
#if UNITY_EDITOR
        Debug.unityLogger.Log("吊起微信登录");
#elif UNITY_ANDROID
        AndroidJavaObject WxLoginUtil = new AndroidJavaClass("com.ym.unityandroid.UnityWxLoginUtil").CallStatic<AndroidJavaObject>("getInstance");
        WxLoginUtil.Call("wxLogin", GetActivity());
#endif
    }



}
