356 lines
7.7 KiB
C#
356 lines
7.7 KiB
C#
#if SDK_BILIBILI
|
||
using UnityEngine;
|
||
using System.Runtime.InteropServices;
|
||
|
||
/// <summary>
|
||
/// 接收 SDK 的回调消息,进行处理。
|
||
/// 该脚本应关联到每一个场景的 "Main Camera" 对象,以能接收SDK回调的消息。
|
||
/// 下面各方法中的逻辑处理,在游戏中应修改为真实的逻辑。
|
||
/// </summary>
|
||
public class GSCSdkInterface : MonoBehaviour
|
||
{
|
||
/// <summary>
|
||
/// 检查登录
|
||
/// </summary>
|
||
public static bool CheckLoging;
|
||
/// <summary>
|
||
/// 是否登录
|
||
/// </summary>
|
||
public static bool IsLogin;
|
||
|
||
//iOS unity调用iOS层方法
|
||
[DllImport("__Internal")]
|
||
public static extern void __initIosSDK(string gameId, string cpId, string serverId, string appkey, string sandboxKey);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosLogin();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosLogout();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosUserInfo(string accesskey);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosIsRealnameAuth();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosGetSdkType();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosGetSdkChannel();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosGetSdkVersion();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosCreateRole(string roleid, string rolename);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosNotifyZone(string serverid, string servername, string roleid, string rolename);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosSetGameOpenUrl(string url);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosHeartbeatStart();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosHeartbeatStop();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosAgreementWithLicence();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosAgreementWithPrivacy();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosGeetest();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosAccountProtect();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosGetFreeUrl(string sourceUrl, string gameId, string appKey);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void __iosPay(string productId, string outTradeNo, string money, string productName, string productCount, string description,string extension, string orderSign, string notifyUrl);
|
||
|
||
//android unity调用java层方法
|
||
public static void callSdkApi (string apiName, params object[] args)
|
||
{
|
||
using AndroidJavaClass cls = new("com.phxh.nld.GSCSdkCenter");
|
||
cls.CallStatic(apiName, args);
|
||
}
|
||
|
||
|
||
/**
|
||
* android 支付接口
|
||
* @param uid 用户的唯一标识(整型)
|
||
* @param username 用户名或者email(唯一)
|
||
* @param role 充值的角色信息
|
||
* @param serverId 区服号
|
||
* @param total_fee 充值金额
|
||
* @param game_money 游戏币,需要用充值金额*充值比率
|
||
* @param out_trade_no 充值订单号
|
||
* @param subject 充值主题
|
||
* @param body 充值描述
|
||
* @param extension_info 附加信息,会在服务器异步回调中原样传回
|
||
*/
|
||
public static void androidPay(long uid, string username, string role, string serverId,
|
||
int total_fee, int game_money, string out_trade_no, string subject, string body, string extension_info, string notify_url, string order_sign)
|
||
{
|
||
#if UNITY_ANDROID
|
||
callSdkApi ("pay", uid, username, role, serverId, total_fee, game_money, out_trade_no, subject, body, extension_info, notify_url, order_sign);
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* android获取设备指纹信息接口
|
||
*/
|
||
public static void androidFingerprint()
|
||
{
|
||
#if UNITY_ANDROID
|
||
callSdkApi ("getFingerprint");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* android获取是否登录接口
|
||
*/
|
||
public static void androidCheckLogin()
|
||
{
|
||
#if UNITY_ANDROID
|
||
CheckLoging = true;
|
||
callSdkApi("checkLogin");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* android退出接口
|
||
*/
|
||
public static void androidExit ()
|
||
{
|
||
#if UNITY_ANDROID
|
||
callSdkApi ("exit");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* iOS支付接口
|
||
*/
|
||
public static void iOSPay(string product_id, string out_trade_no, int money, string subject, int game_money, string body, string extension_info, string order_sign, string notify_url)
|
||
{
|
||
#if UNITY_IOS
|
||
__iosPay(product_id, out_trade_no, money, subject, game_money, body, extension_info, order_sign, notify_url);
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* iOS获取sdk的版本接口
|
||
*/
|
||
public static void iOSSdkVersion()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosGetSdkVersion();
|
||
#endif
|
||
}
|
||
/**
|
||
* 初始化
|
||
*/
|
||
public static void init(string merchant_id, string app_id, string server_id, string app_key, string sandboxKey)
|
||
{
|
||
Debug.Log("init");
|
||
#if UNITY_IOS
|
||
__initIosSDK(merchant_id, app_id, server_id, app_key, sandboxKey);
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("init", merchant_id, app_id, server_id, app_key);
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 登录接口
|
||
*/
|
||
public static void login ()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosLogin();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("login");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 通知区服接口
|
||
*/
|
||
public static void notifyZone(string server_id, string server_name, string role_id, string role_name)
|
||
{
|
||
#if UNITY_IOS
|
||
__iosNotifyZone(server_id, server_name, role_id, role_name);
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("notifyZone", server_id, server_name, role_id, role_name);
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 创角接口
|
||
*/
|
||
public static void createRole(string role_name, string role_id)
|
||
{
|
||
#if UNITY_IOS
|
||
__iosCreateRole(role_name, role_id);
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("createRole", role_id, role_name);
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 停止心跳接口
|
||
*/
|
||
public static void stopHeartbeat()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosHeartbeatStop();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("stop");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 开始心跳接口
|
||
*/
|
||
public static void startHeartbeat()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosHeartbeatStart();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("start");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 获取sdk类型接口
|
||
*/
|
||
public static void getSdkType()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosGetSdkType();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("getSdkType");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 获取渠道号接口
|
||
*/
|
||
public static void getChannelId()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosGetSdkChannel();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("getChannelId");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 获取是否实名认证接口
|
||
*/
|
||
public static void isRealNameAuth(){
|
||
#if UNITY_IOS
|
||
__iosIsRealnameAuth();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("isRealNameAuth");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 登出接口
|
||
*/
|
||
public static void logout()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosLogout();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("logout");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 获取用户信息接口
|
||
*/
|
||
public static void getUserInfo(string accesskey)
|
||
{
|
||
#if UNITY_IOS
|
||
__iosUserInfo(accesskey);
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("getUserInfo");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 账号保护接口
|
||
*/
|
||
public static void accountProtect ()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosAccountProtect();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("accountProtect");
|
||
#endif
|
||
}
|
||
|
||
|
||
/**
|
||
* 显示用户协议界面接口
|
||
*/
|
||
public static void showAgreementWithLicence ()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosAgreementWithLicence();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("showAgreementWithLicence");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 显示隐私政策界面接口
|
||
*/
|
||
public static void showAgreementWithPrivacy ()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosAgreementWithPrivacy();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("showAgreementWithPrivacy");
|
||
#endif
|
||
}
|
||
|
||
/**
|
||
* 显示人机验证接口
|
||
*/
|
||
public static void showGeetestView ()
|
||
{
|
||
#if UNITY_IOS
|
||
__iosGeetest();
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("showGeetestView");
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试
|
||
/// </summary>
|
||
/// <param name="content"></param>
|
||
public static void showToast(string content)
|
||
{
|
||
return;
|
||
|
||
#if UNITY_IOS
|
||
|
||
|
||
#elif UNITY_ANDROID
|
||
callSdkApi ("showToast", content);
|
||
#endif
|
||
}
|
||
|
||
}
|
||
#endif |