bilibilisdk代码移动到phxhsdk下的AOT路径
parent
90f6cfad26
commit
0aa14fa3b3
|
|
@ -2,6 +2,10 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if SDK_BILIBILI
|
||||
using PhxhSDK.AOT.Bilibili;
|
||||
#endif
|
||||
|
||||
namespace Gameplay.Net
|
||||
{
|
||||
public class LoginStatusBilibili : LoginStatus
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ using Image = UnityEngine.UI.Image;
|
|||
using Toggle = UnityEngine.UI.Toggle;
|
||||
#if SDK_TAPTAP
|
||||
using TapSDK.Login;
|
||||
#elif SDK_BILIBILI
|
||||
using PhxhSDK.AOT.Bilibili;
|
||||
#endif
|
||||
|
||||
public class UI_StartGameInterfaceController : UIWindow
|
||||
|
|
|
|||
|
|
@ -8,10 +8,15 @@ using PhxhSDK.AOT.PreConfig;
|
|||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Assets.PhxhSDK.AOT.BI;
|
||||
|
||||
#if PLATFORM_ANDROID
|
||||
using UnityEngine.Android;
|
||||
#endif
|
||||
|
||||
#if SDK_BILIBILI
|
||||
using PhxhSDK.AOT.Bilibili;
|
||||
#endif
|
||||
|
||||
public class GameLauncher : MonoBehaviour
|
||||
{
|
||||
const string START_SCENE_NAME = "Assets/Scenes/StartScene.unity";
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit ece0cecb01ff8f58e8e347d41aa40b96cf1f98bf
|
||||
Subproject commit 7293f0860f7ff1c30b6f319970fef6430253fbe3
|
||||
|
|
@ -1,425 +0,0 @@
|
|||
#if SDK_BILIBILI
|
||||
using UnityEngine;
|
||||
using LitJson;
|
||||
using System;
|
||||
|
||||
public class GSCCallbackListerner : MonoBehaviour
|
||||
{
|
||||
public const int StatusCode_Success = 10010;
|
||||
|
||||
public const string CALLBACKTYPE_INIT = "init"; //初始化
|
||||
public const string CALLBACKTYPE_PAY = "pay"; //支付
|
||||
public const string CALLBACKTYPE_SDKTYPE = "sdkType"; //获取sdktype
|
||||
public const string CALLBACKTYPE_CHANNELID = "channelId"; //获取渠道id
|
||||
public const string CALLBACKTYPE_FINGERPRINT = "fingerprint"; //获取设备指纹
|
||||
public const string CALLBACKTYPE_ISLOGIN = "isLogin"; //获取是否登录
|
||||
public const string CALLBACKTYPE_LOGIN = "login"; //登录
|
||||
public const string CALLBACKTYPE_LOGOUT = "logout"; //登出
|
||||
public const string CALLBACKTYPE_GETUSERINFO = "getUserInfo"; //获取用户信息
|
||||
public const string CALLBACKTYPE_ACCOUNTPROTECT = "accountProtect"; //账号保护
|
||||
public const string CALLBACKTYPE_AGREEMENTWITHLICENCE = "agreementWithLicence"; //用户协议
|
||||
public const string CALLBACKTYPE_AGREEMENTWITHPRIVACY = "agreementWithPrivacy"; //隐私政策
|
||||
public const string CALLBACKTYPE_GEETESTVIEW = "geetestView"; //人机验证
|
||||
public const string CALLBACKTYPE_ACCOUNTINVALID = "AccountInvalid"; //账号异常
|
||||
public const string CALLBACKTYPE_ISREALNAMEAUTH = "isRealNameAuth"; //获取是否还没
|
||||
public const string CALLBACKTYPE_EXIT = "exit"; //退出
|
||||
public const string CALLBACKTYPE_QUIT = "quit"; //退出游戏杀死进程的那种
|
||||
|
||||
/// <summary>
|
||||
/// 登录回调
|
||||
/// </summary>
|
||||
private Action<string, string> loginAction;
|
||||
|
||||
/// <summary>
|
||||
/// 注册登录回调
|
||||
/// </summary>
|
||||
public void RegistLoginCallback(Action<string, string> login)
|
||||
{
|
||||
loginAction = login;
|
||||
}
|
||||
|
||||
public void OnGSCSdkCallback(string jsonstr)
|
||||
{
|
||||
Debug.Log("OnGSCSdkCallback message: jsonstr=" + jsonstr);
|
||||
JsonData json = JsonMapper.ToObject(jsonstr);
|
||||
string callbackType = (string)json["callbackType"];
|
||||
int code = (int)json["code"];
|
||||
JsonData data = json["data"];
|
||||
switch (callbackType)
|
||||
{
|
||||
case CALLBACKTYPE_INIT:
|
||||
OnInitCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_PAY:
|
||||
OnPayCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_SDKTYPE:
|
||||
OnSdkTypeCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_CHANNELID:
|
||||
OnChannelIdCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_FINGERPRINT:
|
||||
OnFingerPrintCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_ISLOGIN:
|
||||
OnIsLoginCallback(code, data);
|
||||
break;
|
||||
case CALLBACKTYPE_ISREALNAMEAUTH:
|
||||
OnIsRealNameAuthCallback(code, data);
|
||||
break;
|
||||
case CALLBACKTYPE_LOGIN:
|
||||
OnLoginCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_LOGOUT:
|
||||
OnLogoutCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_GETUSERINFO:
|
||||
OnGetUserInfoCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_ACCOUNTPROTECT:
|
||||
OnAccountProtectCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_AGREEMENTWITHLICENCE:
|
||||
OnAgreementWithLicenceCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_AGREEMENTWITHPRIVACY:
|
||||
OnAgreementWithPrivacyCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_GEETESTVIEW:
|
||||
OnGeetestViewCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_ACCOUNTINVALID:
|
||||
OnAccountInvalidCallback(code, (string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_EXIT:
|
||||
OnExitCallback((string)data);
|
||||
break;
|
||||
case CALLBACKTYPE_QUIT:
|
||||
OnQuitCallback((string)data);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public virtual void OnInitCallback(int code, string data)
|
||||
{
|
||||
if (code == StatusCode_Success)
|
||||
Debug.Log($"初始化成功,code:{code},data:{data}");
|
||||
else
|
||||
{
|
||||
Debug.LogError($"初始化失败,code:{code},data:{data}");
|
||||
GSCSdkInterface.showToast($"OnInitCallbackError code: {code} message: {data}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 支付回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnPayCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnPayCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
JsonData json = JsonMapper.ToObject(data);
|
||||
string out_trade_no = (string)json["out_trade_no"];
|
||||
string bs_trade_no = (string)json["bs_trade_no"];
|
||||
GSCSdkInterface.showToast("OnPayCallbackSuccess " + " out_trade_no: " + out_trade_no + " bs_out_trade_no: " + bs_trade_no);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonData json = JsonMapper.ToObject(data);
|
||||
string message = (string)json["message"];
|
||||
string out_trade_no = (string)json["out_trade_no"];
|
||||
GSCSdkInterface.showToast("OnPayCallbackError " + " code: " + code + "out_trade_no" + out_trade_no + " message: +" + message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取sdk_type回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnSdkTypeCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnSdkTypeCallback" + data);
|
||||
GSCSdkInterface.showToast("OnSdkTypeCallback " + " sdkType: " + data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取渠道id回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnChannelIdCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnChannelIdCallback" + data);
|
||||
GSCSdkInterface.showToast("OnChannelIdCallback " + " channelId: " + data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备指纹信息回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnFingerPrintCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnFingerPrintCallback" + data);
|
||||
GSCSdkInterface.showToast("OnFingerPrintCallback " + " fingerPrint: " + data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取是否登录回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnIsLoginCallback(int code, JsonData data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnIsLoginCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
bool isLogin = (bool)data;
|
||||
GSCSdkInterface.showToast("OnIsLoginCallbackSuccess " + " isLogin: " + isLogin);
|
||||
GSCSdkInterface.IsLogin = true;
|
||||
GSCSdkInterface.CheckLoging = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
string message = (string)data;
|
||||
GSCSdkInterface.IsLogin = false;
|
||||
GSCSdkInterface.CheckLoging = false;
|
||||
GSCSdkInterface.showToast($"OnIsLoginCallbackError code: {code} message: {message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取是否实名认证回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnIsRealNameAuthCallback(int code, JsonData data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnIsRealNameAuthCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
bool isRealName = (bool)data;
|
||||
GSCSdkInterface.showToast("OnIsRealNameAuthCallback " + " isRealName: " + isRealName);
|
||||
}
|
||||
else
|
||||
{
|
||||
string message = (string)data;
|
||||
GSCSdkInterface.showToast("OnIsRealNameAuthCallback " + " code: " + code + " message: +" + message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取登录回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnLoginCallback(int code, string data)
|
||||
{
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
JsonData json = JsonMapper.ToObject(data);
|
||||
string username = (string)json["username"];
|
||||
string access_token = (string)json["access_token"];
|
||||
string uid = (string)json["uid"];
|
||||
loginAction?.Invoke(access_token, uid);
|
||||
|
||||
Debug.LogError($"登录成功,code:{code},data:{data}");
|
||||
}
|
||||
else
|
||||
Debug.LogError($"登录失败,code:{code},data:{data}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取登出回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnLogoutCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnLogoutCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
GSCSdkInterface.showToast("OnLogoutCallbackSuccess " + " logout: " + data);
|
||||
}
|
||||
else
|
||||
{
|
||||
GSCSdkInterface.showToast("OnLogoutCallbackError " + " code: " + code + " message: +" + data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户信息回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnGetUserInfoCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnGetUserInfoCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
JsonData json = JsonMapper.ToObject(data);
|
||||
string username = (string)json["username"];
|
||||
string lastLoginTime = (string)json["lastLoginTime"];
|
||||
string avatar = (string)json["avatar"];
|
||||
string s_avatar = (string)json["s_avatar"];
|
||||
GSCSdkInterface.showToast("OnGetUserInfoCallbackSuccess " + " username: " + username + " lastLoginTime: " + lastLoginTime
|
||||
+ " avatar: " + avatar + " s_avatar:" + s_avatar);
|
||||
}
|
||||
else
|
||||
{
|
||||
GSCSdkInterface.showToast("OnGetUserInfoCallbackError " + " code: " + code + " message: +" + data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 账号保护回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnAccountProtectCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnAccountProtectCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
JsonData json = JsonMapper.ToObject(data);
|
||||
string result = (string)json["result"];
|
||||
GSCSdkInterface.showToast("OnAccountProtectCallbackSuccess " + " result: " + result);
|
||||
}
|
||||
else
|
||||
{
|
||||
GSCSdkInterface.showToast("OnAccountProtectCallbackError " + " code: " + code + " message: +" + data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户协议回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnAgreementWithLicenceCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnAgreementWithLicenceCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
GSCSdkInterface.showToast("OnAgreementWithLicenceCallbackSuccess " + " data: " + data);
|
||||
}
|
||||
else
|
||||
{
|
||||
GSCSdkInterface.showToast("OnAgreementWithLicenceCallbackError " + " code: " + code + " message: +" + data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 隐私政策回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnAgreementWithPrivacyCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnAgreementWithPrivacyCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
GSCSdkInterface.showToast("OnAgreementWithPrivacyCallbackSuccess " + " data: " + data);
|
||||
}
|
||||
else
|
||||
{
|
||||
GSCSdkInterface.showToast("OnAgreementWithPrivacyCallbackError " + " code: " + code + " message: +" + data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 人机验证回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnGeetestViewCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnGeetestViewCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
JsonData json = JsonMapper.ToObject(data);
|
||||
string captcha_type = (string)json["captcha_type"];
|
||||
string image_token = (string)json["image_token"];
|
||||
string captcha_code = (string)json["captcha_code"];
|
||||
string challenge = (string)json["challenge"];
|
||||
string validate = (string)json["validate"];
|
||||
string seccode = (string)json["seccode"];
|
||||
string gt_user_id = (string)json["gt_user_id"];
|
||||
GSCSdkInterface.showToast("OnGeetestViewCallbackSuccess " + " captcha_type: " + captcha_type + " image_token: " + image_token + " captcha_code " + captcha_code + " challenge: " + challenge + " validate: " + validate + " seccode " + seccode + " gt_user_id " + gt_user_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
GSCSdkInterface.showToast("OnGeetestViewCallbackError " + " code: " + code + " message: +" + data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 账号异常回调
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnAccountInvalidCallback(int code, string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnAccountInvalidCallback" + data);
|
||||
if (code == StatusCode_Success)
|
||||
{
|
||||
//Demo.uid = 0;
|
||||
//TODO
|
||||
//游戏登出逻辑
|
||||
GSCSdkInterface.showToast("OnAccountInvalidCallbackSuccess " + data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出回调
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
public virtual void OnExitCallback(string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnExitCallback," + data);
|
||||
GSCSdkInterface.showToast(data);
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Application.Quit();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出游戏回调(防沉迷,付费之类)
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
public void OnQuitCallback(string data)
|
||||
{
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Debug.Log("OnQuitCallback" + data);
|
||||
GSCSdkInterface.showToast("OnQuitCallback - message: +" + data);
|
||||
//下面的用于demo,请改成自己的代码
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,356 +0,0 @@
|
|||
#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
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
#region Header
|
||||
/**
|
||||
* IJsonWrapper.cs
|
||||
* Interface that represents a type capable of handling all kinds of JSON
|
||||
* data. This is mainly used when mapping objects through JsonMapper, and
|
||||
* it's implemented by JsonData.
|
||||
*
|
||||
* The authors disclaim copyright to this source code. For more details, see
|
||||
* the COPYING file included with this distribution.
|
||||
**/
|
||||
#endregion
|
||||
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
|
||||
namespace LitJson
|
||||
{
|
||||
public enum JsonType
|
||||
{
|
||||
None,
|
||||
|
||||
Object,
|
||||
Array,
|
||||
String,
|
||||
Int,
|
||||
Long,
|
||||
Double,
|
||||
Boolean
|
||||
}
|
||||
|
||||
public interface IJsonWrapper : IList, IOrderedDictionary
|
||||
{
|
||||
bool IsArray { get; }
|
||||
bool IsBoolean { get; }
|
||||
bool IsDouble { get; }
|
||||
bool IsInt { get; }
|
||||
bool IsLong { get; }
|
||||
bool IsObject { get; }
|
||||
bool IsString { get; }
|
||||
|
||||
bool GetBoolean();
|
||||
double GetDouble();
|
||||
int GetInt();
|
||||
JsonType GetJsonType();
|
||||
long GetLong();
|
||||
string GetString();
|
||||
|
||||
void SetBoolean(bool val);
|
||||
void SetDouble(double val);
|
||||
void SetInt(int val);
|
||||
void SetJsonType(JsonType type);
|
||||
void SetLong(long val);
|
||||
void SetString(string val);
|
||||
|
||||
string ToJson();
|
||||
void ToJson(JsonWriter writer);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6d965c60870dec34cbf7991ae82ef1e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1588eb65784aee4ba987a6df9ab65b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
#region Header
|
||||
/**
|
||||
* JsonException.cs
|
||||
* Base class throwed by LitJSON when a parsing error occurs.
|
||||
*
|
||||
* The authors disclaim copyright to this source code. For more details, see
|
||||
* the COPYING file included with this distribution.
|
||||
**/
|
||||
#endregion
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
|
||||
namespace LitJson
|
||||
{
|
||||
public class JsonException : ApplicationException
|
||||
{
|
||||
public JsonException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
internal JsonException(ParserToken token) :
|
||||
base(String.Format(
|
||||
"Invalid token '{0}' in input string", token))
|
||||
{
|
||||
}
|
||||
|
||||
internal JsonException(ParserToken token,
|
||||
Exception inner_exception) :
|
||||
base(String.Format(
|
||||
"Invalid token '{0}' in input string", token),
|
||||
inner_exception)
|
||||
{
|
||||
}
|
||||
|
||||
internal JsonException(int c) :
|
||||
base(String.Format(
|
||||
"Invalid character '{0}' in input string", (char)c))
|
||||
{
|
||||
}
|
||||
|
||||
internal JsonException(int c, Exception inner_exception) :
|
||||
base(String.Format(
|
||||
"Invalid character '{0}' in input string", (char)c),
|
||||
inner_exception)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public JsonException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public JsonException(string message, Exception inner_exception) :
|
||||
base(message, inner_exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e33f8176aafda6d49b5b39ef61ec0240
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67a22c5e5cead5e4c806f4560c83c6ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,500 +0,0 @@
|
|||
#region Header
|
||||
/**
|
||||
* JsonReader.cs
|
||||
* Stream-like access to JSON text.
|
||||
*
|
||||
* The authors disclaim copyright to this source code. For more details, see
|
||||
* the COPYING file included with this distribution.
|
||||
**/
|
||||
#endregion
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace LitJson
|
||||
{
|
||||
public enum JsonToken
|
||||
{
|
||||
None,
|
||||
|
||||
ObjectStart,
|
||||
PropertyName,
|
||||
ObjectEnd,
|
||||
|
||||
ArrayStart,
|
||||
ArrayEnd,
|
||||
|
||||
Int,
|
||||
Long,
|
||||
Double,
|
||||
|
||||
String,
|
||||
|
||||
Boolean,
|
||||
Null
|
||||
}
|
||||
|
||||
|
||||
public class JsonReader
|
||||
{
|
||||
#region Fields
|
||||
private static IDictionary<int, IDictionary<int, int[]>> parse_table;
|
||||
|
||||
private Stack<int> automaton_stack;
|
||||
private int current_input;
|
||||
private int current_symbol;
|
||||
private bool end_of_json;
|
||||
private bool end_of_input;
|
||||
private Lexer lexer;
|
||||
private bool parser_in_string;
|
||||
private bool parser_return;
|
||||
private bool read_started;
|
||||
private TextReader reader;
|
||||
private bool reader_is_owned;
|
||||
private object token_value;
|
||||
private JsonToken token;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Public Properties
|
||||
public bool AllowComments
|
||||
{
|
||||
get { return lexer.AllowComments; }
|
||||
set { lexer.AllowComments = value; }
|
||||
}
|
||||
|
||||
public bool AllowSingleQuotedStrings
|
||||
{
|
||||
get { return lexer.AllowSingleQuotedStrings; }
|
||||
set { lexer.AllowSingleQuotedStrings = value; }
|
||||
}
|
||||
|
||||
public bool EndOfInput
|
||||
{
|
||||
get { return end_of_input; }
|
||||
}
|
||||
|
||||
public bool EndOfJson
|
||||
{
|
||||
get { return end_of_json; }
|
||||
}
|
||||
|
||||
public JsonToken Token
|
||||
{
|
||||
get { return token; }
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get { return token_value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
static JsonReader()
|
||||
{
|
||||
PopulateParseTable();
|
||||
}
|
||||
|
||||
public JsonReader(string json_text) :
|
||||
this(new StringReader(json_text), true)
|
||||
{
|
||||
}
|
||||
|
||||
public JsonReader(TextReader reader) :
|
||||
this(reader, false)
|
||||
{
|
||||
}
|
||||
|
||||
private JsonReader(TextReader reader, bool owned)
|
||||
{
|
||||
if (reader == null)
|
||||
throw new ArgumentNullException("reader");
|
||||
|
||||
parser_in_string = false;
|
||||
parser_return = false;
|
||||
|
||||
read_started = false;
|
||||
automaton_stack = new Stack<int>();
|
||||
automaton_stack.Push((int)ParserToken.End);
|
||||
automaton_stack.Push((int)ParserToken.Text);
|
||||
|
||||
lexer = new Lexer(reader);
|
||||
|
||||
end_of_input = false;
|
||||
end_of_json = false;
|
||||
|
||||
this.reader = reader;
|
||||
reader_is_owned = owned;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Static Methods
|
||||
private static void PopulateParseTable()
|
||||
{
|
||||
// See section A.2. of the manual for details
|
||||
parse_table = new Dictionary<int, IDictionary<int, int[]>>();
|
||||
|
||||
TableAddRow(ParserToken.Array);
|
||||
TableAddCol(ParserToken.Array, '[',
|
||||
'[',
|
||||
(int)ParserToken.ArrayPrime);
|
||||
|
||||
TableAddRow(ParserToken.ArrayPrime);
|
||||
TableAddCol(ParserToken.ArrayPrime, '"',
|
||||
(int)ParserToken.Value,
|
||||
|
||||
(int)ParserToken.ValueRest,
|
||||
']');
|
||||
TableAddCol(ParserToken.ArrayPrime, '[',
|
||||
(int)ParserToken.Value,
|
||||
(int)ParserToken.ValueRest,
|
||||
']');
|
||||
TableAddCol(ParserToken.ArrayPrime, ']',
|
||||
']');
|
||||
TableAddCol(ParserToken.ArrayPrime, '{',
|
||||
(int)ParserToken.Value,
|
||||
(int)ParserToken.ValueRest,
|
||||
']');
|
||||
TableAddCol(ParserToken.ArrayPrime, (int)ParserToken.Number,
|
||||
(int)ParserToken.Value,
|
||||
(int)ParserToken.ValueRest,
|
||||
']');
|
||||
TableAddCol(ParserToken.ArrayPrime, (int)ParserToken.True,
|
||||
(int)ParserToken.Value,
|
||||
(int)ParserToken.ValueRest,
|
||||
']');
|
||||
TableAddCol(ParserToken.ArrayPrime, (int)ParserToken.False,
|
||||
(int)ParserToken.Value,
|
||||
(int)ParserToken.ValueRest,
|
||||
']');
|
||||
TableAddCol(ParserToken.ArrayPrime, (int)ParserToken.Null,
|
||||
(int)ParserToken.Value,
|
||||
(int)ParserToken.ValueRest,
|
||||
']');
|
||||
|
||||
TableAddRow(ParserToken.Object);
|
||||
TableAddCol(ParserToken.Object, '{',
|
||||
'{',
|
||||
(int)ParserToken.ObjectPrime);
|
||||
|
||||
TableAddRow(ParserToken.ObjectPrime);
|
||||
TableAddCol(ParserToken.ObjectPrime, '"',
|
||||
(int)ParserToken.Pair,
|
||||
(int)ParserToken.PairRest,
|
||||
'}');
|
||||
TableAddCol(ParserToken.ObjectPrime, '}',
|
||||
'}');
|
||||
|
||||
TableAddRow(ParserToken.Pair);
|
||||
TableAddCol(ParserToken.Pair, '"',
|
||||
(int)ParserToken.String,
|
||||
':',
|
||||
(int)ParserToken.Value);
|
||||
|
||||
TableAddRow(ParserToken.PairRest);
|
||||
TableAddCol(ParserToken.PairRest, ',',
|
||||
',',
|
||||
(int)ParserToken.Pair,
|
||||
(int)ParserToken.PairRest);
|
||||
TableAddCol(ParserToken.PairRest, '}',
|
||||
(int)ParserToken.Epsilon);
|
||||
|
||||
TableAddRow(ParserToken.String);
|
||||
TableAddCol(ParserToken.String, '"',
|
||||
'"',
|
||||
(int)ParserToken.CharSeq,
|
||||
'"');
|
||||
|
||||
TableAddRow(ParserToken.Text);
|
||||
TableAddCol(ParserToken.Text, '[',
|
||||
(int)ParserToken.Array);
|
||||
TableAddCol(ParserToken.Text, '{',
|
||||
(int)ParserToken.Object);
|
||||
|
||||
TableAddRow(ParserToken.Value);
|
||||
TableAddCol(ParserToken.Value, '"',
|
||||
(int)ParserToken.String);
|
||||
TableAddCol(ParserToken.Value, '[',
|
||||
(int)ParserToken.Array);
|
||||
TableAddCol(ParserToken.Value, '{',
|
||||
(int)ParserToken.Object);
|
||||
TableAddCol(ParserToken.Value, (int)ParserToken.Number,
|
||||
(int)ParserToken.Number);
|
||||
TableAddCol(ParserToken.Value, (int)ParserToken.True,
|
||||
(int)ParserToken.True);
|
||||
TableAddCol(ParserToken.Value, (int)ParserToken.False,
|
||||
(int)ParserToken.False);
|
||||
TableAddCol(ParserToken.Value, (int)ParserToken.Null,
|
||||
(int)ParserToken.Null);
|
||||
|
||||
TableAddRow(ParserToken.ValueRest);
|
||||
TableAddCol(ParserToken.ValueRest, ',',
|
||||
',',
|
||||
(int)ParserToken.Value,
|
||||
(int)ParserToken.ValueRest);
|
||||
TableAddCol(ParserToken.ValueRest, ']',
|
||||
(int)ParserToken.Epsilon);
|
||||
}
|
||||
|
||||
private static void TableAddCol(ParserToken row, int col,
|
||||
params int[] symbols)
|
||||
{
|
||||
parse_table[(int)row].Add(col, symbols);
|
||||
}
|
||||
|
||||
private static void TableAddRow(ParserToken rule)
|
||||
{
|
||||
parse_table.Add((int)rule, new Dictionary<int, int[]>());
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Private Methods
|
||||
private void ProcessNumber(string number)
|
||||
{
|
||||
if (number.IndexOf('.') != -1 ||
|
||||
number.IndexOf('e') != -1 ||
|
||||
number.IndexOf('E') != -1)
|
||||
{
|
||||
|
||||
double n_double;
|
||||
if (Double.TryParse(number, out n_double))
|
||||
{
|
||||
token = JsonToken.Double;
|
||||
token_value = n_double;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int n_int32;
|
||||
if (Int32.TryParse(number, out n_int32))
|
||||
{
|
||||
token = JsonToken.Int;
|
||||
token_value = n_int32;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
long n_int64;
|
||||
if (Int64.TryParse(number, out n_int64))
|
||||
{
|
||||
token = JsonToken.Long;
|
||||
token_value = n_int64;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Shouldn't happen, but just in case, return something
|
||||
token = JsonToken.Int;
|
||||
token_value = 0;
|
||||
}
|
||||
|
||||
private void ProcessSymbol()
|
||||
{
|
||||
if (current_symbol == '[')
|
||||
{
|
||||
token = JsonToken.ArrayStart;
|
||||
parser_return = true;
|
||||
|
||||
}
|
||||
else if (current_symbol == ']')
|
||||
{
|
||||
token = JsonToken.ArrayEnd;
|
||||
parser_return = true;
|
||||
|
||||
}
|
||||
else if (current_symbol == '{')
|
||||
{
|
||||
token = JsonToken.ObjectStart;
|
||||
parser_return = true;
|
||||
|
||||
}
|
||||
else if (current_symbol == '}')
|
||||
{
|
||||
token = JsonToken.ObjectEnd;
|
||||
parser_return = true;
|
||||
|
||||
}
|
||||
else if (current_symbol == '"')
|
||||
{
|
||||
if (parser_in_string)
|
||||
{
|
||||
parser_in_string = false;
|
||||
|
||||
parser_return = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (token == JsonToken.None)
|
||||
token = JsonToken.String;
|
||||
|
||||
parser_in_string = true;
|
||||
}
|
||||
|
||||
}
|
||||
else if (current_symbol == (int)ParserToken.CharSeq)
|
||||
{
|
||||
token_value = lexer.StringValue;
|
||||
|
||||
}
|
||||
else if (current_symbol == (int)ParserToken.False)
|
||||
{
|
||||
token = JsonToken.Boolean;
|
||||
token_value = false;
|
||||
parser_return = true;
|
||||
|
||||
}
|
||||
else if (current_symbol == (int)ParserToken.Null)
|
||||
{
|
||||
token = JsonToken.Null;
|
||||
parser_return = true;
|
||||
|
||||
}
|
||||
else if (current_symbol == (int)ParserToken.Number)
|
||||
{
|
||||
ProcessNumber(lexer.StringValue);
|
||||
|
||||
parser_return = true;
|
||||
|
||||
}
|
||||
else if (current_symbol == (int)ParserToken.Pair)
|
||||
{
|
||||
token = JsonToken.PropertyName;
|
||||
|
||||
}
|
||||
else if (current_symbol == (int)ParserToken.True)
|
||||
{
|
||||
token = JsonToken.Boolean;
|
||||
token_value = true;
|
||||
parser_return = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private bool ReadToken()
|
||||
{
|
||||
if (end_of_input)
|
||||
return false;
|
||||
|
||||
lexer.NextToken();
|
||||
|
||||
if (lexer.EndOfInput)
|
||||
{
|
||||
Close();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
current_input = lexer.Token;
|
||||
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (end_of_input)
|
||||
return;
|
||||
|
||||
end_of_input = true;
|
||||
end_of_json = true;
|
||||
|
||||
if (reader_is_owned)
|
||||
reader.Close();
|
||||
|
||||
reader = null;
|
||||
}
|
||||
|
||||
public bool Read()
|
||||
{
|
||||
if (end_of_input)
|
||||
return false;
|
||||
|
||||
if (end_of_json)
|
||||
{
|
||||
end_of_json = false;
|
||||
automaton_stack.Clear();
|
||||
automaton_stack.Push((int)ParserToken.End);
|
||||
automaton_stack.Push((int)ParserToken.Text);
|
||||
}
|
||||
|
||||
parser_in_string = false;
|
||||
parser_return = false;
|
||||
|
||||
token = JsonToken.None;
|
||||
token_value = null;
|
||||
|
||||
if (!read_started)
|
||||
{
|
||||
read_started = true;
|
||||
|
||||
if (!ReadToken())
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int[] entry_symbols;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (parser_return)
|
||||
{
|
||||
if (automaton_stack.Peek() == (int)ParserToken.End)
|
||||
end_of_json = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
current_symbol = automaton_stack.Pop();
|
||||
|
||||
ProcessSymbol();
|
||||
|
||||
if (current_symbol == current_input)
|
||||
{
|
||||
if (!ReadToken())
|
||||
{
|
||||
if (automaton_stack.Peek() != (int)ParserToken.End)
|
||||
throw new JsonException(
|
||||
"Input doesn't evaluate to proper JSON text");
|
||||
|
||||
if (parser_return)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
entry_symbols =
|
||||
parse_table[current_symbol][current_input];
|
||||
|
||||
}
|
||||
catch (KeyNotFoundException e)
|
||||
{
|
||||
throw new JsonException((ParserToken)current_input, e);
|
||||
}
|
||||
|
||||
if (entry_symbols[0] == (int)ParserToken.Epsilon)
|
||||
continue;
|
||||
|
||||
for (int i = entry_symbols.Length - 1; i >= 0; i--)
|
||||
automaton_stack.Push(entry_symbols[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c2cc8939c8ce49c4392feeec732729dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,477 +0,0 @@
|
|||
#region Header
|
||||
/**
|
||||
* JsonWriter.cs
|
||||
* Stream-like facility to output JSON text.
|
||||
*
|
||||
* The authors disclaim copyright to this source code. For more details, see
|
||||
* the COPYING file included with this distribution.
|
||||
**/
|
||||
#endregion
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace LitJson
|
||||
{
|
||||
internal enum Condition
|
||||
{
|
||||
InArray,
|
||||
InObject,
|
||||
NotAProperty,
|
||||
Property,
|
||||
Value
|
||||
}
|
||||
|
||||
internal class WriterContext
|
||||
{
|
||||
public int Count;
|
||||
public bool InArray;
|
||||
public bool InObject;
|
||||
public bool ExpectingValue;
|
||||
public int Padding;
|
||||
}
|
||||
|
||||
public class JsonWriter
|
||||
{
|
||||
#region Fields
|
||||
private static NumberFormatInfo number_format;
|
||||
|
||||
private WriterContext context;
|
||||
private Stack<WriterContext> ctx_stack;
|
||||
private bool has_reached_end;
|
||||
private char[] hex_seq;
|
||||
private int indentation;
|
||||
private int indent_value;
|
||||
private StringBuilder inst_string_builder;
|
||||
private bool pretty_print;
|
||||
private bool validate;
|
||||
private TextWriter writer;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
public int IndentValue
|
||||
{
|
||||
get { return indent_value; }
|
||||
set
|
||||
{
|
||||
indentation = (indentation / indent_value) * value;
|
||||
indent_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool PrettyPrint
|
||||
{
|
||||
get { return pretty_print; }
|
||||
set { pretty_print = value; }
|
||||
}
|
||||
|
||||
public TextWriter TextWriter
|
||||
{
|
||||
get { return writer; }
|
||||
}
|
||||
|
||||
public bool Validate
|
||||
{
|
||||
get { return validate; }
|
||||
set { validate = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
static JsonWriter()
|
||||
{
|
||||
number_format = NumberFormatInfo.InvariantInfo;
|
||||
}
|
||||
|
||||
public JsonWriter()
|
||||
{
|
||||
inst_string_builder = new StringBuilder();
|
||||
writer = new StringWriter(inst_string_builder);
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
public JsonWriter(StringBuilder sb) :
|
||||
this(new StringWriter(sb))
|
||||
{
|
||||
}
|
||||
|
||||
public JsonWriter(TextWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
throw new ArgumentNullException("writer");
|
||||
|
||||
this.writer = writer;
|
||||
|
||||
Init();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Private Methods
|
||||
private void DoValidation(Condition cond)
|
||||
{
|
||||
if (!context.ExpectingValue)
|
||||
context.Count++;
|
||||
|
||||
if (!validate)
|
||||
return;
|
||||
|
||||
if (has_reached_end)
|
||||
throw new JsonException(
|
||||
"A complete JSON symbol has already been written");
|
||||
|
||||
switch (cond)
|
||||
{
|
||||
case Condition.InArray:
|
||||
if (!context.InArray)
|
||||
throw new JsonException(
|
||||
"Can't close an array here");
|
||||
break;
|
||||
|
||||
case Condition.InObject:
|
||||
if (!context.InObject || context.ExpectingValue)
|
||||
throw new JsonException(
|
||||
"Can't close an object here");
|
||||
break;
|
||||
|
||||
case Condition.NotAProperty:
|
||||
if (context.InObject && !context.ExpectingValue)
|
||||
throw new JsonException(
|
||||
"Expected a property");
|
||||
break;
|
||||
|
||||
case Condition.Property:
|
||||
if (!context.InObject || context.ExpectingValue)
|
||||
throw new JsonException(
|
||||
"Can't add a property here");
|
||||
break;
|
||||
|
||||
case Condition.Value:
|
||||
if (!context.InArray &&
|
||||
(!context.InObject || !context.ExpectingValue))
|
||||
throw new JsonException(
|
||||
"Can't add a value here");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
has_reached_end = false;
|
||||
hex_seq = new char[4];
|
||||
indentation = 0;
|
||||
indent_value = 4;
|
||||
pretty_print = false;
|
||||
validate = true;
|
||||
|
||||
ctx_stack = new Stack<WriterContext>();
|
||||
context = new WriterContext();
|
||||
ctx_stack.Push(context);
|
||||
}
|
||||
|
||||
private static void IntToHex(int n, char[] hex)
|
||||
{
|
||||
int num;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
num = n % 16;
|
||||
|
||||
if (num < 10)
|
||||
hex[3 - i] = (char)('0' + num);
|
||||
else
|
||||
hex[3 - i] = (char)('A' + (num - 10));
|
||||
|
||||
n >>= 4;
|
||||
}
|
||||
}
|
||||
|
||||
private void Indent()
|
||||
{
|
||||
if (pretty_print)
|
||||
indentation += indent_value;
|
||||
}
|
||||
|
||||
|
||||
private void Put(string str)
|
||||
{
|
||||
if (pretty_print && !context.ExpectingValue)
|
||||
for (int i = 0; i < indentation; i++)
|
||||
writer.Write(' ');
|
||||
|
||||
writer.Write(str);
|
||||
}
|
||||
|
||||
private void PutNewline()
|
||||
{
|
||||
PutNewline(true);
|
||||
}
|
||||
|
||||
private void PutNewline(bool add_comma)
|
||||
{
|
||||
if (add_comma && !context.ExpectingValue &&
|
||||
context.Count > 1)
|
||||
writer.Write(',');
|
||||
|
||||
if (pretty_print && !context.ExpectingValue)
|
||||
writer.Write('\n');
|
||||
}
|
||||
|
||||
private void PutString(string str)
|
||||
{
|
||||
Put(String.Empty);
|
||||
|
||||
writer.Write('"');
|
||||
|
||||
int n = str.Length;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
switch (str[i])
|
||||
{
|
||||
case '\n':
|
||||
writer.Write("\\n");
|
||||
continue;
|
||||
|
||||
case '\r':
|
||||
writer.Write("\\r");
|
||||
continue;
|
||||
|
||||
case '\t':
|
||||
writer.Write("\\t");
|
||||
continue;
|
||||
|
||||
case '"':
|
||||
case '\\':
|
||||
writer.Write('\\');
|
||||
writer.Write(str[i]);
|
||||
continue;
|
||||
|
||||
case '\f':
|
||||
writer.Write("\\f");
|
||||
continue;
|
||||
|
||||
case '\b':
|
||||
writer.Write("\\b");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((int)str[i] >= 32 && (int)str[i] <= 126)
|
||||
{
|
||||
writer.Write(str[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Default, turn into a \uXXXX sequence
|
||||
IntToHex((int)str[i], hex_seq);
|
||||
writer.Write("\\u");
|
||||
writer.Write(hex_seq);
|
||||
}
|
||||
|
||||
writer.Write('"');
|
||||
}
|
||||
|
||||
private void Unindent()
|
||||
{
|
||||
if (pretty_print)
|
||||
indentation -= indent_value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (inst_string_builder == null)
|
||||
return String.Empty;
|
||||
|
||||
return inst_string_builder.ToString();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
has_reached_end = false;
|
||||
|
||||
ctx_stack.Clear();
|
||||
context = new WriterContext();
|
||||
ctx_stack.Push(context);
|
||||
|
||||
if (inst_string_builder != null)
|
||||
inst_string_builder.Remove(0, inst_string_builder.Length);
|
||||
}
|
||||
|
||||
public void Write(bool boolean)
|
||||
{
|
||||
DoValidation(Condition.Value);
|
||||
PutNewline();
|
||||
|
||||
Put(boolean ? "true" : "false");
|
||||
|
||||
context.ExpectingValue = false;
|
||||
}
|
||||
|
||||
public void Write(decimal number)
|
||||
{
|
||||
DoValidation(Condition.Value);
|
||||
PutNewline();
|
||||
|
||||
Put(Convert.ToString(number, number_format));
|
||||
|
||||
context.ExpectingValue = false;
|
||||
}
|
||||
|
||||
public void Write(double number)
|
||||
{
|
||||
DoValidation(Condition.Value);
|
||||
PutNewline();
|
||||
|
||||
string str = Convert.ToString(number, number_format);
|
||||
Put(str);
|
||||
|
||||
if (str.IndexOf('.') == -1 &&
|
||||
str.IndexOf('E') == -1)
|
||||
writer.Write(".0");
|
||||
|
||||
context.ExpectingValue = false;
|
||||
}
|
||||
|
||||
public void Write(int number)
|
||||
{
|
||||
DoValidation(Condition.Value);
|
||||
PutNewline();
|
||||
|
||||
Put(Convert.ToString(number, number_format));
|
||||
|
||||
context.ExpectingValue = false;
|
||||
}
|
||||
|
||||
public void Write(long number)
|
||||
{
|
||||
DoValidation(Condition.Value);
|
||||
PutNewline();
|
||||
|
||||
Put(Convert.ToString(number, number_format));
|
||||
|
||||
context.ExpectingValue = false;
|
||||
}
|
||||
|
||||
public void Write(string str)
|
||||
{
|
||||
DoValidation(Condition.Value);
|
||||
PutNewline();
|
||||
|
||||
if (str == null)
|
||||
Put("null");
|
||||
else
|
||||
PutString(str);
|
||||
|
||||
context.ExpectingValue = false;
|
||||
}
|
||||
|
||||
//[CLSCompliant(false)]
|
||||
public void Write(ulong number)
|
||||
{
|
||||
DoValidation(Condition.Value);
|
||||
PutNewline();
|
||||
|
||||
Put(Convert.ToString(number, number_format));
|
||||
|
||||
context.ExpectingValue = false;
|
||||
}
|
||||
|
||||
public void WriteArrayEnd()
|
||||
{
|
||||
DoValidation(Condition.InArray);
|
||||
PutNewline(false);
|
||||
|
||||
ctx_stack.Pop();
|
||||
if (ctx_stack.Count == 1)
|
||||
has_reached_end = true;
|
||||
else
|
||||
{
|
||||
context = ctx_stack.Peek();
|
||||
context.ExpectingValue = false;
|
||||
}
|
||||
|
||||
Unindent();
|
||||
Put("]");
|
||||
}
|
||||
|
||||
public void WriteArrayStart()
|
||||
{
|
||||
DoValidation(Condition.NotAProperty);
|
||||
PutNewline();
|
||||
|
||||
Put("[");
|
||||
|
||||
context = new WriterContext();
|
||||
context.InArray = true;
|
||||
ctx_stack.Push(context);
|
||||
|
||||
Indent();
|
||||
}
|
||||
|
||||
public void WriteObjectEnd()
|
||||
{
|
||||
DoValidation(Condition.InObject);
|
||||
PutNewline(false);
|
||||
|
||||
ctx_stack.Pop();
|
||||
if (ctx_stack.Count == 1)
|
||||
has_reached_end = true;
|
||||
else
|
||||
{
|
||||
context = ctx_stack.Peek();
|
||||
context.ExpectingValue = false;
|
||||
}
|
||||
|
||||
Unindent();
|
||||
Put("}");
|
||||
}
|
||||
|
||||
public void WriteObjectStart()
|
||||
{
|
||||
DoValidation(Condition.NotAProperty);
|
||||
PutNewline();
|
||||
|
||||
Put("{");
|
||||
|
||||
context = new WriterContext();
|
||||
context.InObject = true;
|
||||
ctx_stack.Push(context);
|
||||
|
||||
Indent();
|
||||
}
|
||||
|
||||
public void WritePropertyName(string property_name)
|
||||
{
|
||||
DoValidation(Condition.Property);
|
||||
PutNewline();
|
||||
|
||||
PutString(property_name);
|
||||
|
||||
if (pretty_print)
|
||||
{
|
||||
if (property_name.Length > context.Padding)
|
||||
context.Padding = property_name.Length;
|
||||
|
||||
for (int i = context.Padding - property_name.Length;
|
||||
i >= 0; i--)
|
||||
writer.Write(' ');
|
||||
|
||||
writer.Write(": ");
|
||||
}
|
||||
else
|
||||
writer.Write(':');
|
||||
|
||||
context.ExpectingValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6c54250dcc566d4428b070ae1ebaa7a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,971 +0,0 @@
|
|||
#region Header
|
||||
/**
|
||||
* Lexer.cs
|
||||
* JSON lexer implementation based on a finite state machine.
|
||||
*
|
||||
* The authors disclaim copyright to this source code. For more details, see
|
||||
* the COPYING file included with this distribution.
|
||||
**/
|
||||
#endregion
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace LitJson
|
||||
{
|
||||
internal class FsmContext
|
||||
{
|
||||
public bool Return;
|
||||
public int NextState;
|
||||
public Lexer L;
|
||||
public int StateStack;
|
||||
}
|
||||
|
||||
|
||||
internal class Lexer
|
||||
{
|
||||
#region Fields
|
||||
private delegate bool StateHandler(FsmContext ctx);
|
||||
|
||||
private static int[] fsm_return_table;
|
||||
private static StateHandler[] fsm_handler_table;
|
||||
|
||||
private bool allow_comments;
|
||||
private bool allow_single_quoted_strings;
|
||||
private bool end_of_input;
|
||||
private FsmContext fsm_context;
|
||||
private int input_buffer;
|
||||
private int input_char;
|
||||
private TextReader reader;
|
||||
private int state;
|
||||
private StringBuilder string_buffer;
|
||||
private string string_value;
|
||||
private int token;
|
||||
private int unichar;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
public bool AllowComments
|
||||
{
|
||||
get { return allow_comments; }
|
||||
set { allow_comments = value; }
|
||||
}
|
||||
|
||||
public bool AllowSingleQuotedStrings
|
||||
{
|
||||
get { return allow_single_quoted_strings; }
|
||||
set { allow_single_quoted_strings = value; }
|
||||
}
|
||||
|
||||
public bool EndOfInput
|
||||
{
|
||||
get { return end_of_input; }
|
||||
}
|
||||
|
||||
public int Token
|
||||
{
|
||||
get { return token; }
|
||||
}
|
||||
|
||||
public string StringValue
|
||||
{
|
||||
get { return string_value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
static Lexer()
|
||||
{
|
||||
PopulateFsmTables();
|
||||
}
|
||||
|
||||
public Lexer(TextReader reader)
|
||||
{
|
||||
allow_comments = true;
|
||||
allow_single_quoted_strings = true;
|
||||
|
||||
input_buffer = 0;
|
||||
string_buffer = new StringBuilder(128);
|
||||
state = 1;
|
||||
end_of_input = false;
|
||||
this.reader = reader;
|
||||
|
||||
fsm_context = new FsmContext();
|
||||
fsm_context.L = this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Static Methods
|
||||
private static int HexValue(int digit)
|
||||
{
|
||||
switch (digit)
|
||||
{
|
||||
case 'a':
|
||||
case 'A':
|
||||
return 10;
|
||||
|
||||
case 'b':
|
||||
case 'B':
|
||||
return 11;
|
||||
|
||||
case 'c':
|
||||
case 'C':
|
||||
return 12;
|
||||
|
||||
case 'd':
|
||||
case 'D':
|
||||
return 13;
|
||||
|
||||
case 'e':
|
||||
case 'E':
|
||||
return 14;
|
||||
|
||||
case 'f':
|
||||
case 'F':
|
||||
return 15;
|
||||
|
||||
default:
|
||||
return digit - '0';
|
||||
}
|
||||
}
|
||||
|
||||
private static void PopulateFsmTables()
|
||||
{
|
||||
// See section A.1. of the manual for details of the finite
|
||||
// state machine.
|
||||
fsm_handler_table = new StateHandler[28] {
|
||||
State1,
|
||||
State2,
|
||||
State3,
|
||||
State4,
|
||||
State5,
|
||||
State6,
|
||||
State7,
|
||||
State8,
|
||||
State9,
|
||||
State10,
|
||||
State11,
|
||||
State12,
|
||||
State13,
|
||||
State14,
|
||||
State15,
|
||||
State16,
|
||||
State17,
|
||||
State18,
|
||||
State19,
|
||||
State20,
|
||||
State21,
|
||||
State22,
|
||||
State23,
|
||||
State24,
|
||||
State25,
|
||||
State26,
|
||||
State27,
|
||||
State28
|
||||
};
|
||||
|
||||
fsm_return_table = new int[28] {
|
||||
(int) ParserToken.Char,
|
||||
0,
|
||||
(int) ParserToken.Number,
|
||||
(int) ParserToken.Number,
|
||||
0,
|
||||
(int) ParserToken.Number,
|
||||
0,
|
||||
(int) ParserToken.Number,
|
||||
0,
|
||||
0,
|
||||
(int) ParserToken.True,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
(int) ParserToken.False,
|
||||
0,
|
||||
0,
|
||||
(int) ParserToken.Null,
|
||||
(int) ParserToken.CharSeq,
|
||||
(int) ParserToken.Char,
|
||||
0,
|
||||
0,
|
||||
(int) ParserToken.CharSeq,
|
||||
(int) ParserToken.Char,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
}
|
||||
|
||||
private static char ProcessEscChar(int esc_char)
|
||||
{
|
||||
switch (esc_char)
|
||||
{
|
||||
case '"':
|
||||
case '\'':
|
||||
case '\\':
|
||||
case '/':
|
||||
return Convert.ToChar(esc_char);
|
||||
|
||||
case 'n':
|
||||
return '\n';
|
||||
|
||||
case 't':
|
||||
return '\t';
|
||||
|
||||
case 'r':
|
||||
return '\r';
|
||||
|
||||
case 'b':
|
||||
return '\b';
|
||||
|
||||
case 'f':
|
||||
return '\f';
|
||||
|
||||
default:
|
||||
// Unreachable
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State1(FsmContext ctx)
|
||||
{
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
if (ctx.L.input_char == ' ' ||
|
||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r')
|
||||
continue;
|
||||
|
||||
if (ctx.L.input_char >= '1' && ctx.L.input_char <= '9')
|
||||
{
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 3;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case '"':
|
||||
ctx.NextState = 19;
|
||||
ctx.Return = true;
|
||||
return true;
|
||||
|
||||
case ',':
|
||||
case ':':
|
||||
case '[':
|
||||
case ']':
|
||||
case '{':
|
||||
case '}':
|
||||
ctx.NextState = 1;
|
||||
ctx.Return = true;
|
||||
return true;
|
||||
|
||||
case '-':
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 2;
|
||||
return true;
|
||||
|
||||
case '0':
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 4;
|
||||
return true;
|
||||
|
||||
case 'f':
|
||||
ctx.NextState = 12;
|
||||
return true;
|
||||
|
||||
case 'n':
|
||||
ctx.NextState = 16;
|
||||
return true;
|
||||
|
||||
case 't':
|
||||
ctx.NextState = 9;
|
||||
return true;
|
||||
|
||||
case '\'':
|
||||
if (!ctx.L.allow_single_quoted_strings)
|
||||
return false;
|
||||
|
||||
ctx.L.input_char = '"';
|
||||
ctx.NextState = 23;
|
||||
ctx.Return = true;
|
||||
return true;
|
||||
|
||||
case '/':
|
||||
if (!ctx.L.allow_comments)
|
||||
return false;
|
||||
|
||||
ctx.NextState = 25;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool State2(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
if (ctx.L.input_char >= '1' && ctx.L.input_char <= '9')
|
||||
{
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 3;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case '0':
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 4;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State3(FsmContext ctx)
|
||||
{
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9')
|
||||
{
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ctx.L.input_char == ' ' ||
|
||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r')
|
||||
{
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case ',':
|
||||
case ']':
|
||||
case '}':
|
||||
ctx.L.UngetChar();
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
|
||||
case '.':
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 5;
|
||||
return true;
|
||||
|
||||
case 'e':
|
||||
case 'E':
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 7;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool State4(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
if (ctx.L.input_char == ' ' ||
|
||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r')
|
||||
{
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case ',':
|
||||
case ']':
|
||||
case '}':
|
||||
ctx.L.UngetChar();
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
|
||||
case '.':
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 5;
|
||||
return true;
|
||||
|
||||
case 'e':
|
||||
case 'E':
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 7;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State5(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9')
|
||||
{
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 6;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool State6(FsmContext ctx)
|
||||
{
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9')
|
||||
{
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ctx.L.input_char == ' ' ||
|
||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r')
|
||||
{
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case ',':
|
||||
case ']':
|
||||
case '}':
|
||||
ctx.L.UngetChar();
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
|
||||
case 'e':
|
||||
case 'E':
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 7;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool State7(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9')
|
||||
{
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 8;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case '+':
|
||||
case '-':
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
ctx.NextState = 8;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State8(FsmContext ctx)
|
||||
{
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9')
|
||||
{
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ctx.L.input_char == ' ' ||
|
||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r')
|
||||
{
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case ',':
|
||||
case ']':
|
||||
case '}':
|
||||
ctx.L.UngetChar();
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool State9(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'r':
|
||||
ctx.NextState = 10;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State10(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'u':
|
||||
ctx.NextState = 11;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State11(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'e':
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State12(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'a':
|
||||
ctx.NextState = 13;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State13(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'l':
|
||||
ctx.NextState = 14;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State14(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 's':
|
||||
ctx.NextState = 15;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State15(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'e':
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State16(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'u':
|
||||
ctx.NextState = 17;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State17(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'l':
|
||||
ctx.NextState = 18;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State18(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'l':
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State19(FsmContext ctx)
|
||||
{
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case '"':
|
||||
ctx.L.UngetChar();
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 20;
|
||||
return true;
|
||||
|
||||
case '\\':
|
||||
ctx.StateStack = 19;
|
||||
ctx.NextState = 21;
|
||||
return true;
|
||||
|
||||
default:
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool State20(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case '"':
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State21(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case 'u':
|
||||
ctx.NextState = 22;
|
||||
return true;
|
||||
|
||||
case '"':
|
||||
case '\'':
|
||||
case '/':
|
||||
case '\\':
|
||||
case 'b':
|
||||
case 'f':
|
||||
case 'n':
|
||||
case 'r':
|
||||
case 't':
|
||||
ctx.L.string_buffer.Append(
|
||||
ProcessEscChar(ctx.L.input_char));
|
||||
ctx.NextState = ctx.StateStack;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State22(FsmContext ctx)
|
||||
{
|
||||
int counter = 0;
|
||||
int mult = 4096;
|
||||
|
||||
ctx.L.unichar = 0;
|
||||
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
|
||||
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9' ||
|
||||
ctx.L.input_char >= 'A' && ctx.L.input_char <= 'F' ||
|
||||
ctx.L.input_char >= 'a' && ctx.L.input_char <= 'f')
|
||||
{
|
||||
|
||||
ctx.L.unichar += HexValue(ctx.L.input_char) * mult;
|
||||
|
||||
counter++;
|
||||
mult /= 16;
|
||||
|
||||
if (counter == 4)
|
||||
{
|
||||
ctx.L.string_buffer.Append(
|
||||
Convert.ToChar(ctx.L.unichar));
|
||||
ctx.NextState = ctx.StateStack;
|
||||
return true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool State23(FsmContext ctx)
|
||||
{
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case '\'':
|
||||
ctx.L.UngetChar();
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 24;
|
||||
return true;
|
||||
|
||||
case '\\':
|
||||
ctx.StateStack = 23;
|
||||
ctx.NextState = 21;
|
||||
return true;
|
||||
|
||||
default:
|
||||
ctx.L.string_buffer.Append((char)ctx.L.input_char);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool State24(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case '\'':
|
||||
ctx.L.input_char = '"';
|
||||
ctx.Return = true;
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State25(FsmContext ctx)
|
||||
{
|
||||
ctx.L.GetChar();
|
||||
|
||||
switch (ctx.L.input_char)
|
||||
{
|
||||
case '*':
|
||||
ctx.NextState = 27;
|
||||
return true;
|
||||
|
||||
case '/':
|
||||
ctx.NextState = 26;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool State26(FsmContext ctx)
|
||||
{
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
if (ctx.L.input_char == '\n')
|
||||
{
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool State27(FsmContext ctx)
|
||||
{
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
if (ctx.L.input_char == '*')
|
||||
{
|
||||
ctx.NextState = 28;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool State28(FsmContext ctx)
|
||||
{
|
||||
while (ctx.L.GetChar())
|
||||
{
|
||||
if (ctx.L.input_char == '*')
|
||||
continue;
|
||||
|
||||
if (ctx.L.input_char == '/')
|
||||
{
|
||||
ctx.NextState = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
ctx.NextState = 27;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
private bool GetChar()
|
||||
{
|
||||
if ((input_char = NextChar()) != -1)
|
||||
return true;
|
||||
|
||||
end_of_input = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private int NextChar()
|
||||
{
|
||||
if (input_buffer != 0)
|
||||
{
|
||||
int tmp = input_buffer;
|
||||
input_buffer = 0;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return reader.Read();
|
||||
}
|
||||
|
||||
public bool NextToken()
|
||||
{
|
||||
StateHandler handler;
|
||||
fsm_context.Return = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
handler = fsm_handler_table[state - 1];
|
||||
|
||||
if (!handler(fsm_context))
|
||||
throw new JsonException(input_char);
|
||||
|
||||
if (end_of_input)
|
||||
return false;
|
||||
|
||||
if (fsm_context.Return)
|
||||
{
|
||||
string_value = string_buffer.ToString();
|
||||
string_buffer.Remove(0, string_buffer.Length);
|
||||
token = fsm_return_table[state - 1];
|
||||
|
||||
if (token == (int)ParserToken.Char)
|
||||
token = input_char;
|
||||
|
||||
state = fsm_context.NextState;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
state = fsm_context.NextState;
|
||||
}
|
||||
}
|
||||
|
||||
private void UngetChar()
|
||||
{
|
||||
input_buffer = input_char;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 85ccf574e69b96b4cbd4308be60da0fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
#region Header
|
||||
/**
|
||||
* ParserToken.cs
|
||||
* Internal representation of the tokens used by the lexer and the parser.
|
||||
*
|
||||
* The authors disclaim copyright to this source code. For more details, see
|
||||
* the COPYING file included with this distribution.
|
||||
**/
|
||||
#endregion
|
||||
|
||||
|
||||
namespace LitJson
|
||||
{
|
||||
internal enum ParserToken
|
||||
{
|
||||
// Lexer tokens (see section A.1.1. of the manual)
|
||||
None = System.Char.MaxValue + 1,
|
||||
Number,
|
||||
True,
|
||||
False,
|
||||
Null,
|
||||
CharSeq,
|
||||
// Single char
|
||||
Char,
|
||||
|
||||
// Parser Rules (see section A.2.1 of the manual)
|
||||
Text,
|
||||
Object,
|
||||
ObjectPrime,
|
||||
Pair,
|
||||
PairRest,
|
||||
Array,
|
||||
ArrayPrime,
|
||||
Value,
|
||||
ValueRest,
|
||||
String,
|
||||
|
||||
// End of input
|
||||
End,
|
||||
|
||||
// The empty rule
|
||||
Epsilon
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f5758b3fb61a7a647acaacae7ae41bf8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in New Issue