打点结构
This commit is contained in:
parent
5ad15b173e
commit
4dc5d1eca6
|
|
@ -69,6 +69,40 @@ public partial class JoypacAdManager : MonoBehaviour
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static bool bannerShow = false;
|
||||||
|
public static bool BannerShow
|
||||||
|
{
|
||||||
|
get { return bannerShow; }
|
||||||
|
set { bannerShow = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool videoShow = false;
|
||||||
|
|
||||||
|
public static bool VideoShow
|
||||||
|
{
|
||||||
|
get { return videoShow; }
|
||||||
|
set { videoShow = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool intersShow = false;
|
||||||
|
|
||||||
|
public static bool IntersShow
|
||||||
|
{
|
||||||
|
get { return intersShow; }
|
||||||
|
set { intersShow = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool nativeShow = false;
|
||||||
|
|
||||||
|
public static bool NativeShow
|
||||||
|
{
|
||||||
|
get { return nativeShow; }
|
||||||
|
set { nativeShow = value; }
|
||||||
|
}
|
||||||
|
|
||||||
private const int RETRY_TIMES_COUNT = 2;
|
private const int RETRY_TIMES_COUNT = 2;
|
||||||
private int m_bannerRetryTimes = RETRY_TIMES_COUNT;
|
private int m_bannerRetryTimes = RETRY_TIMES_COUNT;
|
||||||
private int m_intersRetryTimes = RETRY_TIMES_COUNT;
|
private int m_intersRetryTimes = RETRY_TIMES_COUNT;
|
||||||
|
|
@ -418,6 +452,7 @@ public IEnumerator SwitchPageTime()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int[] interCallbackFlg = new int[Enum.GetValues(typeof(JoypacIntersitialStatus)).Cast<int>().Max() + 1];
|
||||||
void ShowInterOnly(Action<JoypacIntersitialStatus> callback, string interId, string position)
|
void ShowInterOnly(Action<JoypacIntersitialStatus> callback, string interId, string position)
|
||||||
{
|
{
|
||||||
boolInterReady = 0;
|
boolInterReady = 0;
|
||||||
|
|
@ -432,26 +467,36 @@ public IEnumerator SwitchPageTime()
|
||||||
testType = TestType.Inter;
|
testType = TestType.Inter;
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
for (int i = 0; i < interCallbackFlg.Length; ++i)
|
||||||
|
{
|
||||||
|
interCallbackFlg[i] = 1;
|
||||||
|
LogTool.DebugLog("JoypacInter: 重置Flg");
|
||||||
|
}
|
||||||
|
|
||||||
|
IntersShow = false;
|
||||||
joypacAds.ShowIntersitial((status) =>
|
joypacAds.ShowIntersitial((status) =>
|
||||||
{
|
{
|
||||||
if (status == JoypacIntersitialStatus.CLOSE || status == JoypacIntersitialStatus.FAIL)
|
if (interCallbackFlg[(int)status] == 1)
|
||||||
{
|
{
|
||||||
|
if (status == JoypacIntersitialStatus.CLOSE || status == JoypacIntersitialStatus.FAIL)
|
||||||
ContinueGame();
|
|
||||||
if (callback != null) callback(status); // 回调改到这里了
|
|
||||||
//AudioAdaper.ContinueGame(); // 恢复原游戏声音状态
|
|
||||||
LoadInterstitial(interId);
|
|
||||||
if (status == JoypacIntersitialStatus.FAIL) // 失败回调
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ContinueGame();
|
||||||
|
if (callback != null) callback(status); // 回调改到这里了
|
||||||
|
//AudioAdaper.ContinueGame(); // 恢复原游戏声音状态
|
||||||
|
LoadInterstitial(interId);
|
||||||
|
if (status == JoypacIntersitialStatus.FAIL) // 失败回调
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (status == JoypacIntersitialStatus.SHOW)
|
||||||
|
{
|
||||||
|
if (callback != null) callback(status);
|
||||||
|
JoypacAnalyticsManager.DesignEvent(StaticStringsEvent.Ad, StaticStringsEvent.InterShow, position);
|
||||||
|
StopGame();
|
||||||
|
JPADEvent.Instance.ShowInterstitialEvent();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (status == JoypacIntersitialStatus.SHOW)
|
|
||||||
{
|
|
||||||
if (callback != null) callback(status);
|
|
||||||
JoypacAnalyticsManager.DesignEvent(StaticStringsEvent.Ad, StaticStringsEvent.InterShow, position);
|
|
||||||
StopGame();
|
|
||||||
JPADEvent.Instance.ShowInterstitialEvent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, interId);
|
}, interId);
|
||||||
|
|
@ -487,6 +532,8 @@ public IEnumerator SwitchPageTime()
|
||||||
if (IsReadyVideo)
|
if (IsReadyVideo)
|
||||||
{
|
{
|
||||||
LogTool.DebugLog("IsReadyVideo");
|
LogTool.DebugLog("IsReadyVideo");
|
||||||
|
|
||||||
|
VideoShow = false;
|
||||||
joypacAds.ShowVideo(_videoPlace.ShowPlace, (status) =>
|
joypacAds.ShowVideo(_videoPlace.ShowPlace, (status) =>
|
||||||
{
|
{
|
||||||
if (callbackFlg[(int)status] == 1)
|
if (callbackFlg[(int)status] == 1)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
|
||||||
//#if UNITY_IPHONE || UNITY_ANDROID
|
//#if UNITY_IPHONE || UNITY_ANDROID
|
||||||
|
|
@ -219,12 +220,25 @@ public class JoyPacAdverManager : MonoBehaviour
|
||||||
if (onSetInterstitialListener_onAdFailedToLoad != null)
|
if (onSetInterstitialListener_onAdFailedToLoad != null)
|
||||||
onSetInterstitialListener_onAdFailedToLoad (json);
|
onSetInterstitialListener_onAdFailedToLoad (json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInterstitialListener_onAdOpened (string json)
|
void setInterstitialListener_onAdOpened(string json)
|
||||||
{
|
{
|
||||||
Debug.Log("unity JoyPacAdverManager setInterstitialListener_onAdOpened msg:" + json);
|
Debug.Log("unity JoyPacAdverManager setInterstitialListener_onAdOpened msg:" + json);
|
||||||
if (onSetInterstitialListener_onAdOpened != null)
|
if (onSetInterstitialListener_onAdOpened != null)
|
||||||
onSetInterstitialListener_onAdOpened (json);
|
onSetInterstitialListener_onAdOpened(json);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(json) && !JoypacAdManager.IntersShow)
|
||||||
|
{
|
||||||
|
JoypacAdManager.IntersShow = true;
|
||||||
|
//Dictionary<string, object> values = new Dictionary<string, object>();
|
||||||
|
Dictionary<string, object> jsonTemp = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
jsonTemp = JsonMapper.ToObject<Dictionary<string, object>>(json);//
|
||||||
|
|
||||||
|
JoypacAnalyticsManager.Instance.APPAdsShow(jsonTemp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInterstitialListener_onAdLeftApplication (string json)
|
void setInterstitialListener_onAdLeftApplication (string json)
|
||||||
|
|
@ -241,11 +255,23 @@ public class JoyPacAdverManager : MonoBehaviour
|
||||||
onSetInterstitialListener_onAdClosed (json);
|
onSetInterstitialListener_onAdClosed (json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInterstitialListener_onClick (string json)
|
void setInterstitialListener_onClick(string json)
|
||||||
{
|
{
|
||||||
Debug.Log("unity JoyPacAdverManager setInterstitialListener_onClick msg:" + json);
|
Debug.Log("unity JoyPacAdverManager setInterstitialListener_onClick msg:" + json);
|
||||||
if (onSetInterstitialListener_onClick != null)
|
if (onSetInterstitialListener_onClick != null)
|
||||||
onSetInterstitialListener_onClick (json);
|
onSetInterstitialListener_onClick(json);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(json))
|
||||||
|
{
|
||||||
|
Dictionary<string, object> jsonTemp = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
jsonTemp = JsonMapper.ToObject<Dictionary<string, object>>(json);//
|
||||||
|
|
||||||
|
JoypacAnalyticsManager.Instance.APPAdsClick(jsonTemp);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInterstitialListener_onRequestAd (string json)
|
void setInterstitialListener_onRequestAd (string json)
|
||||||
|
|
@ -349,19 +375,30 @@ public class JoyPacAdverManager : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="json">Json.</param>
|
/// <param name="json">Json.</param>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setRewardListener_onRewarded (string json)
|
void setRewardListener_onRewarded(string json)
|
||||||
{
|
{
|
||||||
Debug.Log("unity JoyPacAdverManager setRewardListener_onRewarded msg:" + json);
|
Debug.Log("unity JoyPacAdverManager setRewardListener_onRewarded msg:" + json);
|
||||||
if (onSetRewardListener_onRewarded != null)
|
if (onSetRewardListener_onRewarded != null)
|
||||||
onSetRewardListener_onRewarded (json);
|
onSetRewardListener_onRewarded(json);
|
||||||
|
if (!string.IsNullOrEmpty(json))
|
||||||
|
{
|
||||||
|
Dictionary<string, object> jsonTemp = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
jsonTemp = JsonMapper.ToObject<Dictionary<string, object>>(json);//
|
||||||
|
|
||||||
|
JoypacAnalyticsManager.Instance.AppAdsReward(jsonTemp);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRewardListener_onRewardedVideoAdLeftApplication (string json)
|
void setRewardListener_onRewardedVideoAdLeftApplication (string json)
|
||||||
|
|
@ -399,11 +436,24 @@ public class JoyPacAdverManager : MonoBehaviour
|
||||||
onSetRewardListener_onRewardedVideoAdOpened (json);
|
onSetRewardListener_onRewardedVideoAdOpened (json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRewardListener_onRewardedVideoStarted (string json)
|
void setRewardListener_onRewardedVideoStarted(string json)
|
||||||
{
|
{
|
||||||
Debug.Log("unity JoyPacAdverManager setRewardListener_onRewardedVideoStarted msg:" + json);
|
Debug.Log("unity JoyPacAdverManager setRewardListener_onRewardedVideoStarted msg:" + json);
|
||||||
if (onSetRewardListener_onRewardedVideoStarted != null)
|
if (onSetRewardListener_onRewardedVideoStarted != null)
|
||||||
onSetRewardListener_onRewardedVideoStarted (json);
|
onSetRewardListener_onRewardedVideoStarted(json);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(json) && !JoypacAdManager.VideoShow)
|
||||||
|
{
|
||||||
|
JoypacAdManager.VideoShow = true;
|
||||||
|
Dictionary<string, object> jsonTemp = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
jsonTemp = JsonMapper.ToObject<Dictionary<string, object>>(json);//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JoypacAnalyticsManager.Instance.APPAdsShow(jsonTemp);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRewardListener_onRewardedVideoCompleted (string json)
|
void setRewardListener_onRewardedVideoCompleted (string json)
|
||||||
|
|
@ -413,11 +463,23 @@ public class JoyPacAdverManager : MonoBehaviour
|
||||||
onSetRewardListener_onRewardedVideoCompleted (json);
|
onSetRewardListener_onRewardedVideoCompleted (json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRewardListener_onRewardedVideoClickAd (string json)
|
void setRewardListener_onRewardedVideoClickAd(string json)
|
||||||
{
|
{
|
||||||
Debug.Log("unity JoyPacAdverManager setRewardListener_onRewardedVideoClickAd msg:" + json);
|
Debug.Log("unity JoyPacAdverManager setRewardListener_onRewardedVideoClickAd msg:" + json);
|
||||||
if (onSetRewardListener_onRewardedVideoClickAd != null)
|
if (onSetRewardListener_onRewardedVideoClickAd != null)
|
||||||
onSetRewardListener_onRewardedVideoClickAd (json);
|
onSetRewardListener_onRewardedVideoClickAd(json);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(json))
|
||||||
|
{
|
||||||
|
|
||||||
|
Dictionary<string, object> jsonTemp = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
jsonTemp = JsonMapper.ToObject<Dictionary<string, object>>(json);//
|
||||||
|
|
||||||
|
JoypacAnalyticsManager.Instance.APPAdsClick(jsonTemp);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRewardListener_onRewardedReadyAd (string json)
|
void setRewardListener_onRewardedReadyAd (string json)
|
||||||
|
|
|
||||||
|
|
@ -8,143 +8,143 @@ public class JoyPacCurrentcyAdSingle
|
||||||
{
|
{
|
||||||
private readonly AndroidJavaObject _currentcyAdSinglePlugin;
|
private readonly AndroidJavaObject _currentcyAdSinglePlugin;
|
||||||
|
|
||||||
public JoyPacCurrentcyAdSingle ()
|
public JoyPacCurrentcyAdSingle()
|
||||||
{
|
{
|
||||||
if (Application.platform != RuntimePlatform.Android)
|
if (Application.platform != RuntimePlatform.Android)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
_currentcyAdSinglePlugin = new AndroidJavaObject ("com.joypac.unitybridge.UnityAdManager");
|
|
||||||
|
_currentcyAdSinglePlugin = new AndroidJavaObject("com.joypac.unitybridge.UnityAdManager");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init (string joypacAppID, string userType, string joypacUnitName)
|
|
||||||
{
|
|
||||||
|
|
||||||
_currentcyAdSinglePlugin.Call ("init", joypacAppID,userType,joypacUnitName);
|
public void init(string joypacAppID, string userType, string joypacUnitName)
|
||||||
|
{
|
||||||
|
|
||||||
|
_currentcyAdSinglePlugin.Call("init", joypacAppID, userType, joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initBanner (string joypacUnitName, int position)
|
public void initBanner(string joypacUnitName, int position)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("initBanner", joypacUnitName, position);
|
_currentcyAdSinglePlugin.Call("initBanner", joypacUnitName, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initInterstitial (string joypacUnitName)
|
public void initInterstitial(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("initInterstitial", joypacUnitName);
|
_currentcyAdSinglePlugin.Call("initInterstitial", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initReward (string joypacUnitName)
|
public void initReward(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("initReward", joypacUnitName);
|
_currentcyAdSinglePlugin.Call("initReward", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initNative(string joypacUnitName)
|
public void initNative(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call("initNative",joypacUnitName);
|
_currentcyAdSinglePlugin.Call("initNative", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadBanner (int direction, string joypacUnitName, string postion)
|
public void loadBanner(int direction, string joypacUnitName, string postion)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("loadBanner",direction, joypacUnitName, postion);
|
_currentcyAdSinglePlugin.Call("loadBanner", direction, joypacUnitName, postion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void loadInterstitial (string joypacUnitName)
|
public void loadInterstitial(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("loadInterstitial", joypacUnitName);
|
_currentcyAdSinglePlugin.Call("loadInterstitial", joypacUnitName);
|
||||||
}
|
|
||||||
|
|
||||||
public void loadReward (string joypacUnitName)
|
|
||||||
{
|
|
||||||
_currentcyAdSinglePlugin.Call ("loadReward", joypacUnitName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadNative(string joypacUnitName)
|
public void loadReward(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call("loadNative",joypacUnitName);
|
_currentcyAdSinglePlugin.Call("loadReward", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showBanner(string joypacUnitName)
|
public void loadNative(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call("showBanner", joypacUnitName);
|
_currentcyAdSinglePlugin.Call("loadNative", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showBanner(string joypacUnitName)
|
||||||
|
{
|
||||||
public bool isReadyNative(string joypacUnitName)
|
_currentcyAdSinglePlugin.Call("showBanner", joypacUnitName);
|
||||||
{
|
|
||||||
if (Application.platform != RuntimePlatform.Android)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return _currentcyAdSinglePlugin.Call<bool>("isReadyNative",joypacUnitName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showNative(string joypacUnitName, float left, float top, float width, float height)
|
|
||||||
{
|
|
||||||
_currentcyAdSinglePlugin.Call("showNative", joypacUnitName,left, top,width,height);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void hideNative()
|
|
||||||
{
|
|
||||||
_currentcyAdSinglePlugin.Call("hideNative");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void destroyNative()
|
|
||||||
{
|
|
||||||
_currentcyAdSinglePlugin.Call("destroyNative");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hideBanner ()
|
|
||||||
{
|
|
||||||
_currentcyAdSinglePlugin.Call ("hideBanner");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void destroyBanner ()
|
|
||||||
{
|
|
||||||
_currentcyAdSinglePlugin.Call ("destroyBanner");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool isReadyInterstitial(string joypacUnitName)
|
|
||||||
{
|
|
||||||
if (Application.platform != RuntimePlatform.Android)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return _currentcyAdSinglePlugin.Call<bool>("isReadyInterstitial", joypacUnitName);
|
public bool isReadyNative(string joypacUnitName)
|
||||||
}
|
{
|
||||||
|
if (Application.platform != RuntimePlatform.Android)
|
||||||
|
return false;
|
||||||
|
|
||||||
public bool isReadyBanner(string joypacUnitName)
|
return _currentcyAdSinglePlugin.Call<bool>("isReadyNative", joypacUnitName);
|
||||||
{
|
|
||||||
if (Application.platform != RuntimePlatform.Android)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return _currentcyAdSinglePlugin.Call<bool>("isReadyBanner", joypacUnitName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void showInterstitial (string joypacUnitName)
|
|
||||||
{
|
|
||||||
_currentcyAdSinglePlugin.Call ("showInterstitial", joypacUnitName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeInterstitial ()
|
public void showNative(string joypacUnitName, float left, float top, float width, float height)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("closeInterstitial");
|
_currentcyAdSinglePlugin.Call("showNative", joypacUnitName, left, top, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroyInterstitial ()
|
|
||||||
{
|
public void hideNative()
|
||||||
_currentcyAdSinglePlugin.Call ("destroyInterstitial");
|
{
|
||||||
}
|
_currentcyAdSinglePlugin.Call("hideNative");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroyNative()
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("destroyNative");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideBanner()
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("hideBanner");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroyBanner()
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("destroyBanner");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool isReadyInterstitial(string joypacUnitName)
|
||||||
|
{
|
||||||
|
if (Application.platform != RuntimePlatform.Android)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return _currentcyAdSinglePlugin.Call<bool>("isReadyInterstitial", joypacUnitName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool isReadyBanner(string joypacUnitName)
|
||||||
|
{
|
||||||
|
if (Application.platform != RuntimePlatform.Android)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return _currentcyAdSinglePlugin.Call<bool>("isReadyBanner", joypacUnitName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void showInterstitial(string joypacUnitName)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("showInterstitial", joypacUnitName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeInterstitial()
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("closeInterstitial");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroyInterstitial()
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("destroyInterstitial");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void showReward (string joypacUnitName, string eventPosition)
|
public void showReward(string joypacUnitName, string eventPosition)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("showReward", joypacUnitName,eventPosition);
|
_currentcyAdSinglePlugin.Call("showReward", joypacUnitName, eventPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool isReady(string joypacUnitName)
|
public bool isReady(string joypacUnitName)
|
||||||
|
|
@ -152,93 +152,168 @@ public class JoyPacCurrentcyAdSingle
|
||||||
if (Application.platform != RuntimePlatform.Android)
|
if (Application.platform != RuntimePlatform.Android)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return _currentcyAdSinglePlugin.Call<bool> ("isReady", joypacUnitName);
|
return _currentcyAdSinglePlugin.Call<bool>("isReady", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void destroyReward()
|
public void destroyReward()
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("destroyReward");
|
_currentcyAdSinglePlugin.Call("destroyReward");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setBannerListener (string joypacUnitName)
|
public void setBannerListener(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("setBannerListener", joypacUnitName);
|
_currentcyAdSinglePlugin.Call("setBannerListener", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInterstitialListener (string joypacUnitName)
|
public void setInterstitialListener(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("setInterstitialListener", joypacUnitName);
|
_currentcyAdSinglePlugin.Call("setInterstitialListener", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRewardListener (string joypacUnitName)
|
public void setRewardListener(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call ("setRewardListener", joypacUnitName);
|
_currentcyAdSinglePlugin.Call("setRewardListener", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNativeListener(string joypacUnitName)
|
public void setNativeListener(string joypacUnitName)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call("setNativeListener", joypacUnitName);
|
_currentcyAdSinglePlugin.Call("setNativeListener", joypacUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void joypacEventLog(string eventSort, string eventType, string eventPosition, string eventExtra)
|
public void joypacEventLog(string eventSort, string eventType, string eventPosition, string eventExtra)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call("joypacEventLog", eventSort, eventType, eventPosition, eventExtra);
|
_currentcyAdSinglePlugin.Call("joypacEventLog", eventSort, eventType, eventPosition, eventExtra);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ReceiveGameGroupId(string cGroupId)
|
public void ReceiveGameGroupId(string cGroupId)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call("ReceiveGameGroupId", cGroupId);
|
_currentcyAdSinglePlugin.Call("ReceiveGameGroupId", cGroupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetDeviceID()
|
public string GetDeviceID()
|
||||||
{
|
{
|
||||||
string deviceid=_currentcyAdSinglePlugin.Call<string>("GetDeviceID");
|
string deviceid = _currentcyAdSinglePlugin.Call<string>("GetDeviceID");
|
||||||
return deviceid;
|
return deviceid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ReceiveAdJustData(string adJustJson)
|
public void ReceiveAdJustData(string adJustJson)
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call("ReceiveAdJustData", adJustJson);
|
_currentcyAdSinglePlugin.Call("ReceiveAdJustData", adJustJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//火山引擎上报
|
||||||
|
public void reportRangersAppLogEventMap(string jsonArrayStr)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("reportRangersAppLogEventMap", jsonArrayStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取渠道号
|
||||||
|
public string getChannel()
|
||||||
|
{
|
||||||
|
|
||||||
|
//return "tuiguang_toutiao";
|
||||||
|
return _currentcyAdSinglePlugin.Call<string>("getChannel");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新finder的热云deviceid
|
||||||
|
public void updateFinderHeadInfo(string reyun_deviceid, string adjustAttribution)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("updateFinderHeadInfo", reyun_deviceid, adjustAttribution);
|
||||||
|
}
|
||||||
|
//获取finder 设备等id信息
|
||||||
|
public string getFinderDeviceInfo()
|
||||||
|
{
|
||||||
|
|
||||||
|
return _currentcyAdSinglePlugin.Call<string>("getFinderDeviceInfo");
|
||||||
|
|
||||||
|
}
|
||||||
|
//火山引擎id上报
|
||||||
|
public void finderAppLog(string uid)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("finderAppLog", uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void getRedeemWithCCode(string ccode,string appID)
|
//打开oppo游戏中心
|
||||||
{
|
public void openOppoGameCenter()
|
||||||
_currentcyAdSinglePlugin.Call("getRedeemWithCCode", ccode,appID);
|
{
|
||||||
}
|
_currentcyAdSinglePlugin.Call("openOppoGameCenter");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void heavyVibrate()
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("heavyVibrate");
|
||||||
|
}
|
||||||
|
|
||||||
//打开oppo游戏中心
|
public void lightVibrate()
|
||||||
public void openOppoGameCenter()
|
{
|
||||||
{
|
_currentcyAdSinglePlugin.Call("lightVibrate");
|
||||||
_currentcyAdSinglePlugin.Call("openOppoGameCenter");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void heavyVibrate()
|
public void mediumVibrate()
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call("heavyVibrate");
|
_currentcyAdSinglePlugin.Call("mediumVibrate");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lightVibrate()
|
public void showAgreementPermissionPop()
|
||||||
{
|
{
|
||||||
_currentcyAdSinglePlugin.Call("lightVibrate");
|
_currentcyAdSinglePlugin.Call("showAgreementPermissionPop");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mediumVibrate()
|
//更新finder的热云deviceid
|
||||||
{
|
public void updateFinderHeadInfo(string uid)
|
||||||
_currentcyAdSinglePlugin.Call("mediumVibrate");
|
{
|
||||||
}
|
_currentcyAdSinglePlugin.Call("updateFinderHeadInfo", uid);
|
||||||
|
}
|
||||||
|
|
||||||
public void showAgreementPermissionPop()
|
//热云普通事件上报
|
||||||
{
|
public void reyunKeyEvent(string eventKey, string jsonStr)
|
||||||
_currentcyAdSinglePlugin.Call("showAgreementPermissionPop");
|
{
|
||||||
}
|
_currentcyAdSinglePlugin.Call("reyunKeyEvent", eventKey, jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//热云 广告展示事件上报
|
||||||
|
public void reyun_report_ad_show(string come, string adType, string adSourceId, string from, string priceInt, string priceStr, string currency)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("report_ad_show", come, adType, adSourceId, from, priceInt, priceStr, currency);
|
||||||
|
}
|
||||||
|
|
||||||
|
//热云 广告点击事件上报
|
||||||
|
public void reyun_report_ad_click(string come, string adType, string adSourceId, string from)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("report_ad_click", come, adType, adSourceId, from);
|
||||||
|
}
|
||||||
|
|
||||||
|
//热云注册
|
||||||
|
public void reyunSetRegisterWithAccountID(string uid, string jsonStr)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("reyunSetRegisterWithAccountID", uid, jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//热云登录
|
||||||
|
public void reyunSetLoginSuccessBusiness(string uid, string jsonStr)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("reyunSetLoginSuccessBusiness", uid, jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//finder海外版 事件上报
|
||||||
|
public void finderGlobalonEventV3(string eventKey, string eventJsonStr)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("finderGlobalonEventV3", eventKey, eventJsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//finder 海外版属性上报,主要上报adjust回调
|
||||||
|
public void finderGlobalProfileSet(string adjustCallBack)
|
||||||
|
{
|
||||||
|
_currentcyAdSinglePlugin.Call("finderGlobalProfileSet", adjustCallBack);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,4 +73,10 @@
|
||||||
|
|
||||||
//public const string Noadspage = "Noadspage";
|
//public const string Noadspage = "Noadspage";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//finder
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -13,6 +13,8 @@ using com.adjust.sdk.oaid;
|
||||||
using GameAnalyticsSDK;
|
using GameAnalyticsSDK;
|
||||||
using GameAnalyticsSDK.Events;
|
using GameAnalyticsSDK.Events;
|
||||||
using GameAnalyticsSDK.Wrapper;
|
using GameAnalyticsSDK.Wrapper;
|
||||||
|
using LitJson;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Umeng;
|
using Umeng;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
@ -50,6 +52,267 @@ public class JoypacAnalyticsManager : MonoBehaviour
|
||||||
return s_instance;
|
return s_instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string aPPAdsShowCome = "";
|
||||||
|
|
||||||
|
public string aPPAdsShowAdType = "";
|
||||||
|
|
||||||
|
public void AdEvent(string name, string extras, string from, string AdsShowCome, string AdsShowAdType)
|
||||||
|
{
|
||||||
|
// Debug.Log(string.Format("<color=#ff0000>{0}</color>", name));
|
||||||
|
aPPAdsShowCome = AdsShowCome;
|
||||||
|
aPPAdsShowAdType = AdsShowAdType;
|
||||||
|
|
||||||
|
// AppFunShow(name,extras);
|
||||||
|
AppFunClick(name, from);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ToJson(object jsonObject)
|
||||||
|
{
|
||||||
|
if (null == jsonObject)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "[" + JsonConvert.SerializeObject(jsonObject) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReYun(VolcanoReYunJson json)
|
||||||
|
{
|
||||||
|
#if JOYPAC_ReYun&&!UNITY_EDITOR
|
||||||
|
|
||||||
|
setEvent(json.eventname,json.values);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEvent(string eventName, Dictionary<string, object> values)
|
||||||
|
{
|
||||||
|
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||||
|
Debug.Log("setEvent========coming");
|
||||||
|
//ryattrs
|
||||||
|
values.Add("ryattrs", JsonConvert.SerializeObject(values));
|
||||||
|
JoyPacCurrentcyAdSingle currAdSingleTemp = new JoyPacCurrentcyAdSingle();
|
||||||
|
|
||||||
|
string finderJson = currAdSingleTemp.getFinderDeviceInfo();//"{\"ver\":10005,\"dtu\":\"yyb\",\"ssid\":\"2c50bc0f-9d14-4cd5-9332-b8c95169c4f0\",\"bd_did\":\"BQQKVB6DZQD5TPA5BQ63AGODTXC6EWUY7V6KISXZWV6QSJM56EYA01\",\"a_uuid\":\"b76ad092-b93a-457d-8bef-fbb27da56a11\"}";
|
||||||
|
|
||||||
|
Debug.Log("setEvent========coming finderJson=="+ finderJson);
|
||||||
|
if (!string.IsNullOrEmpty(finderJson))
|
||||||
|
{
|
||||||
|
|
||||||
|
Dictionary<string, object> jsonTemp = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
jsonTemp = JsonMapper.ToObject<Dictionary<string, object>>(finderJson);//
|
||||||
|
//公共参数
|
||||||
|
Debug.Log("setEvent========coming jsonTemp==" + jsonTemp.Count);
|
||||||
|
values.Add("ver", jsonTemp["ver"]);
|
||||||
|
values.Add("dtu", jsonTemp["dtu"]);
|
||||||
|
values.Add("ssid", jsonTemp["ssid"]);
|
||||||
|
values.Add("bd_did", jsonTemp["bd_did"]);
|
||||||
|
values.Add("a_uuid", jsonTemp["a_uuid"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// JoyPacCurrentcyAdSingle currAdSingleTemp = new JoyPacCurrentcyAdSingle();
|
||||||
|
|
||||||
|
|
||||||
|
currAdSingleTemp.reyunKeyEvent(eventName, JsonConvert.SerializeObject(values));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
public void Volcano(VolcanoReYunJson json)
|
||||||
|
{
|
||||||
|
// ReYUNTracking.Instance.setEvent(json.eventname, json.values.toJson());
|
||||||
|
Debug.Log("VolcanoVolcano" + json.eventname + " " + JsonConvert.SerializeObject(json.values));
|
||||||
|
#if UNITY_IOS && JOYPAC_Volcano_OS&&!UNITY_EDITOR
|
||||||
|
JoypacAdClient.Instance.UploadEvent(json.eventname, JsonConvert.SerializeObject(json.values));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||||
|
#if JOYPAC_Volcano
|
||||||
|
JoyPacCurrentcyAdSingle currAdSingleTemp = new JoyPacCurrentcyAdSingle();
|
||||||
|
|
||||||
|
currAdSingleTemp.reportRangersAppLogEventMap(ToJson(json));
|
||||||
|
|
||||||
|
#elif JOYPAC_Volcano_OS
|
||||||
|
JoyPacCurrentcyAdSingle currAdSingleTemp = new JoyPacCurrentcyAdSingle();
|
||||||
|
|
||||||
|
currAdSingleTemp.finderGlobalonEventV3(json.eventname,ToJson(json.values));
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void AppFunShow(string name, string extras)
|
||||||
|
{
|
||||||
|
Debug.Log(string.Format("<color=#ff0000>{0}</color>", name + " " + extras + " App_Fun_Show "));
|
||||||
|
VolcanoReYunJson temp = new VolcanoReYunJson();
|
||||||
|
temp.eventname = "App_Fun_Show";
|
||||||
|
temp.values.Add("name", name);
|
||||||
|
temp.values.Add("extras", extras);
|
||||||
|
Volcano(temp);
|
||||||
|
temp.eventname = "event_13";
|
||||||
|
ReYun(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AppFunClick(string name, string from)
|
||||||
|
{
|
||||||
|
Debug.Log(string.Format("<color=#ff0000>{0}</color>", name + " " + from + " AppFunClick "));
|
||||||
|
VolcanoReYunJson temp = new VolcanoReYunJson();
|
||||||
|
temp.eventname = "App_Fun_Click";
|
||||||
|
temp.values.Add("name", name);
|
||||||
|
temp.values.Add("from", from);
|
||||||
|
Volcano(temp);
|
||||||
|
temp.eventname = "event_14";
|
||||||
|
ReYun(temp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AppOperation(string name, string from, string action, string data, string extras)
|
||||||
|
{
|
||||||
|
|
||||||
|
Debug.Log(string.Format("<color=#ff0000>{0}</color>", action + " " + from + " " + data));
|
||||||
|
VolcanoReYunJson temp = new VolcanoReYunJson();
|
||||||
|
temp.eventname = "App_Operation";
|
||||||
|
temp.values.Add("name", name);
|
||||||
|
temp.values.Add("from", from);
|
||||||
|
temp.values.Add("action", action);
|
||||||
|
temp.values.Add("data", data);
|
||||||
|
temp.values.Add("extras", extras);
|
||||||
|
Volcano(temp);
|
||||||
|
temp.eventname = "event_15";
|
||||||
|
ReYun(temp);
|
||||||
|
|
||||||
|
}
|
||||||
|
public void APPAdsShow(Dictionary<string, object> adSource)
|
||||||
|
{
|
||||||
|
Debug.Log("APPAdsShow========coming");
|
||||||
|
|
||||||
|
|
||||||
|
Debug.Log("APPAdsShow========coming adSource" + adSource.Count);
|
||||||
|
|
||||||
|
VolcanoReYunJson temp = new VolcanoReYunJson();
|
||||||
|
temp.eventname = "APP_Ads_Show";
|
||||||
|
temp.values.Add("Come", aPPAdsShowCome);
|
||||||
|
temp.values.Add("AdType", aPPAdsShowAdType);
|
||||||
|
temp.values.Add("AdSourceId", adSource["AdSourceId"]);
|
||||||
|
temp.values.Add("From", adSource["From"]);
|
||||||
|
temp.values.Add("price_int", adSource["price_int"]);
|
||||||
|
temp.values.Add("price_string", adSource["price_string"]);
|
||||||
|
temp.values.Add("currency", adSource["currency"]);
|
||||||
|
#if JOYPAC_Volcano_OS
|
||||||
|
Volcano(temp);
|
||||||
|
#endif
|
||||||
|
temp.eventname = "event_4";
|
||||||
|
#if UNITY_ANDROID && JOYPAC_ReYun
|
||||||
|
JoyPacCurrentcyAdSingle currAdSingleTemp = new JoyPacCurrentcyAdSingle();
|
||||||
|
|
||||||
|
currAdSingleTemp.reyun_report_ad_show(aPPAdsShowCome, aPPAdsShowAdType, adSource["AdSourceId"].ToString(), adSource["From"].ToString(), adSource["price_int"].ToString(), adSource["price_string"].ToString(), adSource["currency"].ToString());
|
||||||
|
// ReYun(temp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
public void APPAdsClick(Dictionary<string, object> adSource)
|
||||||
|
{
|
||||||
|
|
||||||
|
Debug.Log("APPAdsClick========coming");
|
||||||
|
|
||||||
|
|
||||||
|
Debug.Log("APPAdsClick========coming adSource" + adSource.Count);
|
||||||
|
|
||||||
|
VolcanoReYunJson temp = new VolcanoReYunJson();
|
||||||
|
temp.eventname = "APP_Ads_Click";
|
||||||
|
temp.values.Add("Come", aPPAdsShowCome);
|
||||||
|
temp.values.Add("AdType", aPPAdsShowAdType);
|
||||||
|
temp.values.Add("AdSourceId", adSource["AdSourceId"]);
|
||||||
|
temp.values.Add("From", adSource["From"]);
|
||||||
|
|
||||||
|
#if JOYPAC_Volcano_OS
|
||||||
|
Volcano(temp);
|
||||||
|
#endif
|
||||||
|
temp.eventname = "event_2";
|
||||||
|
#if UNITY_ANDROID && JOYPAC_ReYun
|
||||||
|
JoyPacCurrentcyAdSingle currAdSingleTemp = new JoyPacCurrentcyAdSingle();
|
||||||
|
|
||||||
|
currAdSingleTemp.reyun_report_ad_click(aPPAdsShowCome, aPPAdsShowAdType, adSource["AdSourceId"].ToString(), adSource["From"].ToString());
|
||||||
|
// ReYun(temp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
public void AppAdsReward(Dictionary<string, object> adSource)
|
||||||
|
{
|
||||||
|
Debug.Log("AppAdsReward========coming");
|
||||||
|
|
||||||
|
|
||||||
|
Debug.Log("AppAdsReward========coming adSource" + adSource.Count);
|
||||||
|
|
||||||
|
|
||||||
|
VolcanoReYunJson temp = new VolcanoReYunJson();
|
||||||
|
temp.eventname = "App_Ads_Reward";
|
||||||
|
temp.values.Add("Come", aPPAdsShowCome);
|
||||||
|
temp.values.Add("AdType", aPPAdsShowAdType);
|
||||||
|
temp.values.Add("AdSourceId", adSource["AdSourceId"]);
|
||||||
|
temp.values.Add("From", adSource["From"]);
|
||||||
|
Volcano(temp);
|
||||||
|
temp.eventname = "event_30";
|
||||||
|
ReYun(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void App_Banner_Show(Dictionary<string, object> adSource)
|
||||||
|
{
|
||||||
|
VolcanoReYunJson temp = new VolcanoReYunJson();
|
||||||
|
temp.eventname = "App_Banner_Show";
|
||||||
|
temp.values.Add("Come", "Banner");
|
||||||
|
temp.values.Add("AdType", "Banner");
|
||||||
|
temp.values.Add("AdSourceId", adSource["AdSourceId"]);
|
||||||
|
temp.values.Add("From", adSource["From"]);
|
||||||
|
temp.values.Add("price_int", adSource["price_int"]);
|
||||||
|
temp.values.Add("price_string", adSource["price_string"]);
|
||||||
|
temp.values.Add("currency", adSource["currency"]);
|
||||||
|
|
||||||
|
#if UNITY_IOS && JOYPAC_Volcano
|
||||||
|
Volcano(temp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ANDROID_CN
|
||||||
|
JoyPacCurrentcyAdSingle currAdSingleTemp = new JoyPacCurrentcyAdSingle();
|
||||||
|
currAdSingleTemp.reyun_report_ad_show("Banner", "Banner", adSource["AdSourceId"].ToString(), adSource["From"].ToString(), adSource["price_int"].ToString(), adSource["price_string"].ToString(), adSource["currency"].ToString());
|
||||||
|
#elif ANDROID_GP
|
||||||
|
Volcano(temp);
|
||||||
|
temp.eventname = "event_4";
|
||||||
|
ReYun(temp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
public void App_Banner_Click(Dictionary<string, object> adSource)
|
||||||
|
{
|
||||||
|
VolcanoReYunJson temp = new VolcanoReYunJson();
|
||||||
|
temp.eventname = "App_Banner_Click";
|
||||||
|
temp.values.Add("Come", "Banner");
|
||||||
|
temp.values.Add("AdType", "Banner");
|
||||||
|
temp.values.Add("AdSourceId", adSource["AdSourceId"]);
|
||||||
|
temp.values.Add("From", adSource["From"]);
|
||||||
|
temp.values.Add("price_int", adSource["price_int"]);
|
||||||
|
temp.values.Add("price_string", adSource["price_string"]);
|
||||||
|
temp.values.Add("currency", adSource["currency"]);
|
||||||
|
|
||||||
|
#if UNITY_IOS && JOYPAC_Volcano
|
||||||
|
Volcano(temp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ANDROID_CN
|
||||||
|
JoyPacCurrentcyAdSingle currAdSingleTemp = new JoyPacCurrentcyAdSingle();
|
||||||
|
currAdSingleTemp.reyun_report_ad_click("Banner", "Banner", adSource["AdSourceId"].ToString(), adSource["From"].ToString());
|
||||||
|
#elif ANDROID_GP
|
||||||
|
Volcano(temp);
|
||||||
|
temp.eventname = "event_2";
|
||||||
|
ReYun(temp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static bool updateEventToGA = false;
|
private static bool updateEventToGA = false;
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
|
|
@ -70,7 +333,7 @@ public class JoypacAnalyticsManager : MonoBehaviour
|
||||||
InitFirebase();
|
InitFirebase();
|
||||||
LogFirstDeviceInfo();
|
LogFirstDeviceInfo();
|
||||||
}
|
}
|
||||||
#region Inits
|
#region Inits
|
||||||
|
|
||||||
private void InitUmeng()
|
private void InitUmeng()
|
||||||
{
|
{
|
||||||
|
|
@ -127,7 +390,7 @@ public class JoypacAnalyticsManager : MonoBehaviour
|
||||||
Debug.LogError("必填项没有手动修改!!【测试期间可忽略】");
|
Debug.LogError("必填项没有手动修改!!【测试期间可忽略】");
|
||||||
}
|
}
|
||||||
config.setAppSecret(ConstStringKey.ADJUST_APP_SECRET, ConstStringKey.ADJUST_APP_INFO1, ConstStringKey.ADJUST_APP_INFO2, ConstStringKey.ADJUST_APP_INFO3, ConstStringKey.ADJUST_APP_INFO4);
|
config.setAppSecret(ConstStringKey.ADJUST_APP_SECRET, ConstStringKey.ADJUST_APP_INFO1, ConstStringKey.ADJUST_APP_INFO2, ConstStringKey.ADJUST_APP_INFO3, ConstStringKey.ADJUST_APP_INFO4);
|
||||||
#if DEVELOPMENT_BUILD||ADJUST_TEST
|
#if DEVELOPMENT_BUILD || ADJUST_TEST
|
||||||
config.setEventSuccessDelegate(EventSuccessCallback);
|
config.setEventSuccessDelegate(EventSuccessCallback);
|
||||||
config.setEventFailureDelegate(EventFailureCallback);
|
config.setEventFailureDelegate(EventFailureCallback);
|
||||||
config.setSessionSuccessDelegate(SessionSuccessCallback);
|
config.setSessionSuccessDelegate(SessionSuccessCallback);
|
||||||
|
|
@ -180,7 +443,7 @@ public class JoypacAnalyticsManager : MonoBehaviour
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#if USER_FIREBASE
|
#if USER_FIREBASE
|
||||||
IEnumerator FirebaseLogInit()
|
IEnumerator FirebaseLogInit()
|
||||||
{
|
{
|
||||||
|
|
@ -192,7 +455,7 @@ public class JoypacAnalyticsManager : MonoBehaviour
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#region Events
|
#region Events
|
||||||
|
|
||||||
|
|
||||||
private void LogFirstDeviceInfo()
|
private void LogFirstDeviceInfo()
|
||||||
|
|
@ -383,9 +646,9 @@ public class JoypacAnalyticsManager : MonoBehaviour
|
||||||
LogTool.DebugLog("Joypac LogEventWithLabel Adjust: " + _eventToken);
|
LogTool.DebugLog("Joypac LogEventWithLabel Adjust: " + _eventToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region adjust
|
#region adjust
|
||||||
public void AttributionChangedCallback(AdjustAttribution attribution)
|
public void AttributionChangedCallback(AdjustAttribution attribution)
|
||||||
{
|
{
|
||||||
LogTool.DebugLog("adjust:Attribution changed");
|
LogTool.DebugLog("adjust:Attribution changed");
|
||||||
|
|
@ -396,7 +659,7 @@ public class JoypacAnalyticsManager : MonoBehaviour
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
#if DEVELOPMENT_BUILD||ADJUST_TEST
|
#if DEVELOPMENT_BUILD || ADJUST_TEST
|
||||||
public void EventSuccessCallback(AdjustEventSuccess eventSuccessData)
|
public void EventSuccessCallback(AdjustEventSuccess eventSuccessData)
|
||||||
{
|
{
|
||||||
LogTool.DebugLog("adjust:Event tracked successfully!");
|
LogTool.DebugLog("adjust:Event tracked successfully!");
|
||||||
|
|
@ -543,7 +806,7 @@ public class JoypacAnalyticsManager : MonoBehaviour
|
||||||
JoypacSDKAdapter.Instance.ReceiveAdJustData(json);
|
JoypacSDKAdapter.Instance.ReceiveAdJustData(json);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -585,4 +848,39 @@ public class JoypacAdjustAttribution
|
||||||
trackerName = attribution.trackerName;
|
trackerName = attribution.trackerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class VolcanoReYunJson
|
||||||
|
{
|
||||||
|
public string eventname;
|
||||||
|
public Dictionary<string, object> values = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class VolcanoReYunJson1
|
||||||
|
{
|
||||||
|
public string eventname;
|
||||||
|
public Dictionary<string, object> values = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class ADListenerJson
|
||||||
|
{
|
||||||
|
|
||||||
|
public string AdSourceId;
|
||||||
|
public string From;
|
||||||
|
public string price_int;
|
||||||
|
public string currency;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 572e2434b19c14792b08172f0731675e
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
|
||||||
|
[assembly: CLSCompliant (true)]
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle ("LitJson")]
|
||||||
|
[assembly: AssemblyDescription ("LitJSON library")]
|
||||||
|
[assembly: AssemblyConfiguration ("")]
|
||||||
|
[assembly: AssemblyCompany ("")]
|
||||||
|
[assembly: AssemblyProduct ("LitJSON")]
|
||||||
|
[assembly: AssemblyCopyright (
|
||||||
|
"The authors disclaim copyright to this source code")]
|
||||||
|
[assembly: AssemblyTrademark ("")]
|
||||||
|
[assembly: AssemblyCulture ("")]
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion ("@ASSEMBLY_VERSION@")]
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f562fa7d86ca04f5ebd395e9e9f7b967
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3a7d2ef68eaf44a3b8b30f73289617d1
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7ccfa6321ae1f4f239d9c1f3af32894b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
#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 :
|
||||||
|
#if NETSTANDARD1_5
|
||||||
|
Exception
|
||||||
|
#else
|
||||||
|
ApplicationException
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cd3371d8dd16b42c38fbc477faeeeae9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,964 @@
|
||||||
|
#region Header
|
||||||
|
/**
|
||||||
|
* JsonMapper.cs
|
||||||
|
* JSON to .Net object and object to JSON conversions.
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
|
||||||
|
namespace LitJson
|
||||||
|
{
|
||||||
|
internal struct PropertyMetadata
|
||||||
|
{
|
||||||
|
public MemberInfo Info;
|
||||||
|
public bool IsField;
|
||||||
|
public Type Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal struct ArrayMetadata
|
||||||
|
{
|
||||||
|
private Type element_type;
|
||||||
|
private bool is_array;
|
||||||
|
private bool is_list;
|
||||||
|
|
||||||
|
|
||||||
|
public Type ElementType {
|
||||||
|
get {
|
||||||
|
if (element_type == null)
|
||||||
|
return typeof (JsonData);
|
||||||
|
|
||||||
|
return element_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
set { element_type = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsArray {
|
||||||
|
get { return is_array; }
|
||||||
|
set { is_array = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsList {
|
||||||
|
get { return is_list; }
|
||||||
|
set { is_list = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal struct ObjectMetadata
|
||||||
|
{
|
||||||
|
private Type element_type;
|
||||||
|
private bool is_dictionary;
|
||||||
|
|
||||||
|
private IDictionary<string, PropertyMetadata> properties;
|
||||||
|
|
||||||
|
|
||||||
|
public Type ElementType {
|
||||||
|
get {
|
||||||
|
if (element_type == null)
|
||||||
|
return typeof (JsonData);
|
||||||
|
|
||||||
|
return element_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
set { element_type = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsDictionary {
|
||||||
|
get { return is_dictionary; }
|
||||||
|
set { is_dictionary = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDictionary<string, PropertyMetadata> Properties {
|
||||||
|
get { return properties; }
|
||||||
|
set { properties = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal delegate void ExporterFunc (object obj, JsonWriter writer);
|
||||||
|
public delegate void ExporterFunc<T> (T obj, JsonWriter writer);
|
||||||
|
|
||||||
|
internal delegate object ImporterFunc (object input);
|
||||||
|
public delegate TValue ImporterFunc<TJson, TValue> (TJson input);
|
||||||
|
|
||||||
|
public delegate IJsonWrapper WrapperFactory ();
|
||||||
|
|
||||||
|
|
||||||
|
public class JsonMapper
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
private static readonly int max_nesting_depth;
|
||||||
|
|
||||||
|
private static readonly IFormatProvider datetime_format;
|
||||||
|
|
||||||
|
private static readonly IDictionary<Type, ExporterFunc> base_exporters_table;
|
||||||
|
private static readonly IDictionary<Type, ExporterFunc> custom_exporters_table;
|
||||||
|
|
||||||
|
private static readonly IDictionary<Type,
|
||||||
|
IDictionary<Type, ImporterFunc>> base_importers_table;
|
||||||
|
private static readonly IDictionary<Type,
|
||||||
|
IDictionary<Type, ImporterFunc>> custom_importers_table;
|
||||||
|
|
||||||
|
private static readonly IDictionary<Type, ArrayMetadata> array_metadata;
|
||||||
|
private static readonly object array_metadata_lock = new Object ();
|
||||||
|
|
||||||
|
private static readonly IDictionary<Type,
|
||||||
|
IDictionary<Type, MethodInfo>> conv_ops;
|
||||||
|
private static readonly object conv_ops_lock = new Object ();
|
||||||
|
|
||||||
|
private static readonly IDictionary<Type, ObjectMetadata> object_metadata;
|
||||||
|
private static readonly object object_metadata_lock = new Object ();
|
||||||
|
|
||||||
|
private static readonly IDictionary<Type,
|
||||||
|
IList<PropertyMetadata>> type_properties;
|
||||||
|
private static readonly object type_properties_lock = new Object ();
|
||||||
|
|
||||||
|
private static readonly JsonWriter static_writer;
|
||||||
|
private static readonly object static_writer_lock = new Object ();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
static JsonMapper ()
|
||||||
|
{
|
||||||
|
max_nesting_depth = 100;
|
||||||
|
|
||||||
|
array_metadata = new Dictionary<Type, ArrayMetadata> ();
|
||||||
|
conv_ops = new Dictionary<Type, IDictionary<Type, MethodInfo>> ();
|
||||||
|
object_metadata = new Dictionary<Type, ObjectMetadata> ();
|
||||||
|
type_properties = new Dictionary<Type,
|
||||||
|
IList<PropertyMetadata>> ();
|
||||||
|
|
||||||
|
static_writer = new JsonWriter ();
|
||||||
|
|
||||||
|
datetime_format = DateTimeFormatInfo.InvariantInfo;
|
||||||
|
|
||||||
|
base_exporters_table = new Dictionary<Type, ExporterFunc> ();
|
||||||
|
custom_exporters_table = new Dictionary<Type, ExporterFunc> ();
|
||||||
|
|
||||||
|
base_importers_table = new Dictionary<Type,
|
||||||
|
IDictionary<Type, ImporterFunc>> ();
|
||||||
|
custom_importers_table = new Dictionary<Type,
|
||||||
|
IDictionary<Type, ImporterFunc>> ();
|
||||||
|
|
||||||
|
RegisterBaseExporters ();
|
||||||
|
RegisterBaseImporters ();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
private static void AddArrayMetadata (Type type)
|
||||||
|
{
|
||||||
|
if (array_metadata.ContainsKey (type))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ArrayMetadata data = new ArrayMetadata ();
|
||||||
|
|
||||||
|
data.IsArray = type.IsArray;
|
||||||
|
|
||||||
|
if (type.GetInterface ("System.Collections.IList") != null)
|
||||||
|
data.IsList = true;
|
||||||
|
|
||||||
|
foreach (PropertyInfo p_info in type.GetProperties ()) {
|
||||||
|
if (p_info.Name != "Item")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ParameterInfo[] parameters = p_info.GetIndexParameters ();
|
||||||
|
|
||||||
|
if (parameters.Length != 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (parameters[0].ParameterType == typeof (int))
|
||||||
|
data.ElementType = p_info.PropertyType;
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (array_metadata_lock) {
|
||||||
|
try {
|
||||||
|
array_metadata.Add (type, data);
|
||||||
|
} catch (ArgumentException) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddObjectMetadata (Type type)
|
||||||
|
{
|
||||||
|
if (object_metadata.ContainsKey (type))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ObjectMetadata data = new ObjectMetadata ();
|
||||||
|
|
||||||
|
if (type.GetInterface ("System.Collections.IDictionary") != null)
|
||||||
|
data.IsDictionary = true;
|
||||||
|
|
||||||
|
data.Properties = new Dictionary<string, PropertyMetadata> ();
|
||||||
|
|
||||||
|
foreach (PropertyInfo p_info in type.GetProperties ()) {
|
||||||
|
if (p_info.Name == "Item") {
|
||||||
|
ParameterInfo[] parameters = p_info.GetIndexParameters ();
|
||||||
|
|
||||||
|
if (parameters.Length != 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (parameters[0].ParameterType == typeof (string))
|
||||||
|
data.ElementType = p_info.PropertyType;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertyMetadata p_data = new PropertyMetadata ();
|
||||||
|
p_data.Info = p_info;
|
||||||
|
p_data.Type = p_info.PropertyType;
|
||||||
|
|
||||||
|
data.Properties.Add (p_info.Name, p_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (FieldInfo f_info in type.GetFields ()) {
|
||||||
|
PropertyMetadata p_data = new PropertyMetadata ();
|
||||||
|
p_data.Info = f_info;
|
||||||
|
p_data.IsField = true;
|
||||||
|
p_data.Type = f_info.FieldType;
|
||||||
|
|
||||||
|
data.Properties.Add (f_info.Name, p_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (object_metadata_lock) {
|
||||||
|
try {
|
||||||
|
object_metadata.Add (type, data);
|
||||||
|
} catch (ArgumentException) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddTypeProperties (Type type)
|
||||||
|
{
|
||||||
|
if (type_properties.ContainsKey (type))
|
||||||
|
return;
|
||||||
|
|
||||||
|
IList<PropertyMetadata> props = new List<PropertyMetadata> ();
|
||||||
|
|
||||||
|
foreach (PropertyInfo p_info in type.GetProperties ()) {
|
||||||
|
if (p_info.Name == "Item")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PropertyMetadata p_data = new PropertyMetadata ();
|
||||||
|
p_data.Info = p_info;
|
||||||
|
p_data.IsField = false;
|
||||||
|
props.Add (p_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (FieldInfo f_info in type.GetFields ()) {
|
||||||
|
PropertyMetadata p_data = new PropertyMetadata ();
|
||||||
|
p_data.Info = f_info;
|
||||||
|
p_data.IsField = true;
|
||||||
|
|
||||||
|
props.Add (p_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (type_properties_lock) {
|
||||||
|
try {
|
||||||
|
type_properties.Add (type, props);
|
||||||
|
} catch (ArgumentException) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MethodInfo GetConvOp (Type t1, Type t2)
|
||||||
|
{
|
||||||
|
lock (conv_ops_lock) {
|
||||||
|
if (! conv_ops.ContainsKey (t1))
|
||||||
|
conv_ops.Add (t1, new Dictionary<Type, MethodInfo> ());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conv_ops[t1].ContainsKey (t2))
|
||||||
|
return conv_ops[t1][t2];
|
||||||
|
|
||||||
|
MethodInfo op = t1.GetMethod (
|
||||||
|
"op_Implicit", new Type[] { t2 });
|
||||||
|
|
||||||
|
lock (conv_ops_lock) {
|
||||||
|
try {
|
||||||
|
conv_ops[t1].Add (t2, op);
|
||||||
|
} catch (ArgumentException) {
|
||||||
|
return conv_ops[t1][t2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return op;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static object ReadValue (Type inst_type, JsonReader reader)
|
||||||
|
{
|
||||||
|
reader.Read ();
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.ArrayEnd)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Type underlying_type = Nullable.GetUnderlyingType(inst_type);
|
||||||
|
Type value_type = underlying_type ?? inst_type;
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.Null) {
|
||||||
|
#if NETSTANDARD1_5
|
||||||
|
if (inst_type.IsClass() || underlying_type != null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (inst_type.IsClass || underlying_type != null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
throw new JsonException (String.Format (
|
||||||
|
"Can't assign null to an instance of type {0}",
|
||||||
|
inst_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.Double ||
|
||||||
|
reader.Token == JsonToken.Int ||
|
||||||
|
reader.Token == JsonToken.Long ||
|
||||||
|
reader.Token == JsonToken.String ||
|
||||||
|
reader.Token == JsonToken.Boolean) {
|
||||||
|
|
||||||
|
Type json_type = reader.Value.GetType ();
|
||||||
|
|
||||||
|
if (value_type.IsAssignableFrom (json_type))
|
||||||
|
return reader.Value;
|
||||||
|
|
||||||
|
// If there's a custom importer that fits, use it
|
||||||
|
if (custom_importers_table.ContainsKey (json_type) &&
|
||||||
|
custom_importers_table[json_type].ContainsKey (
|
||||||
|
value_type)) {
|
||||||
|
|
||||||
|
ImporterFunc importer =
|
||||||
|
custom_importers_table[json_type][value_type];
|
||||||
|
|
||||||
|
return importer (reader.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maybe there's a base importer that works
|
||||||
|
if (base_importers_table.ContainsKey (json_type) &&
|
||||||
|
base_importers_table[json_type].ContainsKey (
|
||||||
|
value_type)) {
|
||||||
|
|
||||||
|
ImporterFunc importer =
|
||||||
|
base_importers_table[json_type][value_type];
|
||||||
|
|
||||||
|
return importer (reader.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maybe it's an enum
|
||||||
|
#if NETSTANDARD1_5
|
||||||
|
if (value_type.IsEnum())
|
||||||
|
return Enum.ToObject (value_type, reader.Value);
|
||||||
|
#else
|
||||||
|
if (value_type.IsEnum)
|
||||||
|
return Enum.ToObject (value_type, reader.Value);
|
||||||
|
#endif
|
||||||
|
// Try using an implicit conversion operator
|
||||||
|
MethodInfo conv_op = GetConvOp (value_type, json_type);
|
||||||
|
|
||||||
|
if (conv_op != null)
|
||||||
|
return conv_op.Invoke (null,
|
||||||
|
new object[] { reader.Value });
|
||||||
|
|
||||||
|
// No luck
|
||||||
|
throw new JsonException (String.Format (
|
||||||
|
"Can't assign value '{0}' (type {1}) to type {2}",
|
||||||
|
reader.Value, json_type, inst_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
object instance = null;
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.ArrayStart) {
|
||||||
|
|
||||||
|
AddArrayMetadata (inst_type);
|
||||||
|
ArrayMetadata t_data = array_metadata[inst_type];
|
||||||
|
|
||||||
|
if (! t_data.IsArray && ! t_data.IsList)
|
||||||
|
throw new JsonException (String.Format (
|
||||||
|
"Type {0} can't act as an array",
|
||||||
|
inst_type));
|
||||||
|
|
||||||
|
IList list;
|
||||||
|
Type elem_type;
|
||||||
|
|
||||||
|
if (! t_data.IsArray) {
|
||||||
|
list = (IList) Activator.CreateInstance (inst_type);
|
||||||
|
elem_type = t_data.ElementType;
|
||||||
|
} else {
|
||||||
|
list = new ArrayList ();
|
||||||
|
elem_type = inst_type.GetElementType ();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
object item = ReadValue (elem_type, reader);
|
||||||
|
if (item == null && reader.Token == JsonToken.ArrayEnd)
|
||||||
|
break;
|
||||||
|
|
||||||
|
list.Add (item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t_data.IsArray) {
|
||||||
|
int n = list.Count;
|
||||||
|
instance = Array.CreateInstance (elem_type, n);
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
((Array) instance).SetValue (list[i], i);
|
||||||
|
} else
|
||||||
|
instance = list;
|
||||||
|
|
||||||
|
} else if (reader.Token == JsonToken.ObjectStart) {
|
||||||
|
AddObjectMetadata (value_type);
|
||||||
|
ObjectMetadata t_data = object_metadata[value_type];
|
||||||
|
|
||||||
|
instance = Activator.CreateInstance (value_type);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
reader.Read ();
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.ObjectEnd)
|
||||||
|
break;
|
||||||
|
|
||||||
|
string property = (string) reader.Value;
|
||||||
|
|
||||||
|
if (t_data.Properties.ContainsKey (property)) {
|
||||||
|
PropertyMetadata prop_data =
|
||||||
|
t_data.Properties[property];
|
||||||
|
|
||||||
|
if (prop_data.IsField) {
|
||||||
|
((FieldInfo) prop_data.Info).SetValue (
|
||||||
|
instance, ReadValue (prop_data.Type, reader));
|
||||||
|
} else {
|
||||||
|
PropertyInfo p_info =
|
||||||
|
(PropertyInfo) prop_data.Info;
|
||||||
|
|
||||||
|
if (p_info.CanWrite)
|
||||||
|
p_info.SetValue (
|
||||||
|
instance,
|
||||||
|
ReadValue (prop_data.Type, reader),
|
||||||
|
null);
|
||||||
|
else
|
||||||
|
ReadValue (prop_data.Type, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (! t_data.IsDictionary) {
|
||||||
|
|
||||||
|
if (! reader.SkipNonMembers) {
|
||||||
|
throw new JsonException (String.Format (
|
||||||
|
"The type {0} doesn't have the " +
|
||||||
|
"property '{1}'",
|
||||||
|
inst_type, property));
|
||||||
|
} else {
|
||||||
|
ReadSkip (reader);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
((IDictionary) instance).Add (
|
||||||
|
property, ReadValue (
|
||||||
|
t_data.ElementType, reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IJsonWrapper ReadValue (WrapperFactory factory,
|
||||||
|
JsonReader reader)
|
||||||
|
{
|
||||||
|
reader.Read ();
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.ArrayEnd ||
|
||||||
|
reader.Token == JsonToken.Null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
IJsonWrapper instance = factory ();
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.String) {
|
||||||
|
instance.SetString ((string) reader.Value);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.Double) {
|
||||||
|
instance.SetDouble ((double) reader.Value);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.Int) {
|
||||||
|
instance.SetInt ((int) reader.Value);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.Long) {
|
||||||
|
instance.SetLong ((long) reader.Value);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.Boolean) {
|
||||||
|
instance.SetBoolean ((bool) reader.Value);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.ArrayStart) {
|
||||||
|
instance.SetJsonType (JsonType.Array);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
IJsonWrapper item = ReadValue (factory, reader);
|
||||||
|
if (item == null && reader.Token == JsonToken.ArrayEnd)
|
||||||
|
break;
|
||||||
|
|
||||||
|
((IList) instance).Add (item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (reader.Token == JsonToken.ObjectStart) {
|
||||||
|
instance.SetJsonType (JsonType.Object);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
reader.Read ();
|
||||||
|
|
||||||
|
if (reader.Token == JsonToken.ObjectEnd)
|
||||||
|
break;
|
||||||
|
|
||||||
|
string property = (string) reader.Value;
|
||||||
|
|
||||||
|
((IDictionary) instance)[property] = ReadValue (
|
||||||
|
factory, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ReadSkip (JsonReader reader)
|
||||||
|
{
|
||||||
|
ToWrapper (
|
||||||
|
delegate { return new JsonMockWrapper (); }, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RegisterBaseExporters ()
|
||||||
|
{
|
||||||
|
base_exporters_table[typeof (byte)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write (Convert.ToInt32 ((byte) obj));
|
||||||
|
};
|
||||||
|
|
||||||
|
base_exporters_table[typeof (char)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write (Convert.ToString ((char) obj));
|
||||||
|
};
|
||||||
|
|
||||||
|
base_exporters_table[typeof (DateTime)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write (Convert.ToString ((DateTime) obj,
|
||||||
|
datetime_format));
|
||||||
|
};
|
||||||
|
|
||||||
|
base_exporters_table[typeof (decimal)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write ((decimal) obj);
|
||||||
|
};
|
||||||
|
|
||||||
|
base_exporters_table[typeof (sbyte)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write (Convert.ToInt32 ((sbyte) obj));
|
||||||
|
};
|
||||||
|
|
||||||
|
base_exporters_table[typeof (short)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write (Convert.ToInt32 ((short) obj));
|
||||||
|
};
|
||||||
|
|
||||||
|
base_exporters_table[typeof (ushort)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write (Convert.ToInt32 ((ushort) obj));
|
||||||
|
};
|
||||||
|
|
||||||
|
base_exporters_table[typeof (uint)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write (Convert.ToUInt64 ((uint) obj));
|
||||||
|
};
|
||||||
|
|
||||||
|
base_exporters_table[typeof (ulong)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write ((ulong) obj);
|
||||||
|
};
|
||||||
|
|
||||||
|
base_exporters_table[typeof(DateTimeOffset)] =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
writer.Write(((DateTimeOffset)obj).ToString("yyyy-MM-ddTHH:mm:ss.fffffffzzz", datetime_format));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RegisterBaseImporters ()
|
||||||
|
{
|
||||||
|
ImporterFunc importer;
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToByte ((int) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (int),
|
||||||
|
typeof (byte), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToUInt64 ((int) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (int),
|
||||||
|
typeof (ulong), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToInt64((int)input);
|
||||||
|
};
|
||||||
|
RegisterImporter(base_importers_table, typeof(int),
|
||||||
|
typeof(long), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToSByte ((int) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (int),
|
||||||
|
typeof (sbyte), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToInt16 ((int) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (int),
|
||||||
|
typeof (short), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToUInt16 ((int) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (int),
|
||||||
|
typeof (ushort), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToUInt32 ((int) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (int),
|
||||||
|
typeof (uint), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToSingle ((int) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (int),
|
||||||
|
typeof (float), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToDouble ((int) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (int),
|
||||||
|
typeof (double), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToDecimal ((double) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (double),
|
||||||
|
typeof (decimal), importer);
|
||||||
|
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToUInt32 ((long) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (long),
|
||||||
|
typeof (uint), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToChar ((string) input);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (string),
|
||||||
|
typeof (char), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return Convert.ToDateTime ((string) input, datetime_format);
|
||||||
|
};
|
||||||
|
RegisterImporter (base_importers_table, typeof (string),
|
||||||
|
typeof (DateTime), importer);
|
||||||
|
|
||||||
|
importer = delegate (object input) {
|
||||||
|
return DateTimeOffset.Parse((string)input, datetime_format);
|
||||||
|
};
|
||||||
|
RegisterImporter(base_importers_table, typeof(string),
|
||||||
|
typeof(DateTimeOffset), importer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RegisterImporter (
|
||||||
|
IDictionary<Type, IDictionary<Type, ImporterFunc>> table,
|
||||||
|
Type json_type, Type value_type, ImporterFunc importer)
|
||||||
|
{
|
||||||
|
if (! table.ContainsKey (json_type))
|
||||||
|
table.Add (json_type, new Dictionary<Type, ImporterFunc> ());
|
||||||
|
|
||||||
|
table[json_type][value_type] = importer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteValue (object obj, JsonWriter writer,
|
||||||
|
bool writer_is_private,
|
||||||
|
int depth)
|
||||||
|
{
|
||||||
|
if (depth > max_nesting_depth)
|
||||||
|
throw new JsonException (
|
||||||
|
String.Format ("Max allowed object depth reached while " +
|
||||||
|
"trying to export from type {0}",
|
||||||
|
obj.GetType ()));
|
||||||
|
|
||||||
|
if (obj == null) {
|
||||||
|
writer.Write (null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is IJsonWrapper) {
|
||||||
|
if (writer_is_private)
|
||||||
|
writer.TextWriter.Write (((IJsonWrapper) obj).ToJson ());
|
||||||
|
else
|
||||||
|
((IJsonWrapper) obj).ToJson (writer);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is String) {
|
||||||
|
writer.Write ((string) obj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is Double) {
|
||||||
|
writer.Write ((double) obj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is Int32) {
|
||||||
|
writer.Write ((int) obj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is Boolean) {
|
||||||
|
writer.Write ((bool) obj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is Int64) {
|
||||||
|
writer.Write ((long) obj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is Array) {
|
||||||
|
writer.WriteArrayStart ();
|
||||||
|
|
||||||
|
foreach (object elem in (Array) obj)
|
||||||
|
WriteValue (elem, writer, writer_is_private, depth + 1);
|
||||||
|
|
||||||
|
writer.WriteArrayEnd ();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is IList) {
|
||||||
|
writer.WriteArrayStart ();
|
||||||
|
foreach (object elem in (IList) obj)
|
||||||
|
WriteValue (elem, writer, writer_is_private, depth + 1);
|
||||||
|
writer.WriteArrayEnd ();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is IDictionary dictionary) {
|
||||||
|
writer.WriteObjectStart ();
|
||||||
|
foreach (DictionaryEntry entry in dictionary) {
|
||||||
|
var propertyName = entry.Key is string key ?
|
||||||
|
key
|
||||||
|
: Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
|
||||||
|
writer.WritePropertyName (propertyName);
|
||||||
|
WriteValue (entry.Value, writer, writer_is_private,
|
||||||
|
depth + 1);
|
||||||
|
}
|
||||||
|
writer.WriteObjectEnd ();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type obj_type = obj.GetType ();
|
||||||
|
|
||||||
|
// See if there's a custom exporter for the object
|
||||||
|
if (custom_exporters_table.ContainsKey (obj_type)) {
|
||||||
|
ExporterFunc exporter = custom_exporters_table[obj_type];
|
||||||
|
exporter (obj, writer);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not, maybe there's a base exporter
|
||||||
|
if (base_exporters_table.ContainsKey (obj_type)) {
|
||||||
|
ExporterFunc exporter = base_exporters_table[obj_type];
|
||||||
|
exporter (obj, writer);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Last option, let's see if it's an enum
|
||||||
|
if (obj is Enum) {
|
||||||
|
Type e_type = Enum.GetUnderlyingType (obj_type);
|
||||||
|
|
||||||
|
if (e_type == typeof (long)
|
||||||
|
|| e_type == typeof (uint)
|
||||||
|
|| e_type == typeof (ulong))
|
||||||
|
writer.Write ((ulong) obj);
|
||||||
|
else
|
||||||
|
writer.Write ((int) obj);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Okay, so it looks like the input should be exported as an
|
||||||
|
// object
|
||||||
|
AddTypeProperties (obj_type);
|
||||||
|
IList<PropertyMetadata> props = type_properties[obj_type];
|
||||||
|
|
||||||
|
writer.WriteObjectStart ();
|
||||||
|
foreach (PropertyMetadata p_data in props) {
|
||||||
|
if (p_data.IsField) {
|
||||||
|
writer.WritePropertyName (p_data.Info.Name);
|
||||||
|
WriteValue (((FieldInfo) p_data.Info).GetValue (obj),
|
||||||
|
writer, writer_is_private, depth + 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PropertyInfo p_info = (PropertyInfo) p_data.Info;
|
||||||
|
|
||||||
|
if (p_info.CanRead) {
|
||||||
|
writer.WritePropertyName (p_data.Info.Name);
|
||||||
|
WriteValue (p_info.GetValue (obj, null),
|
||||||
|
writer, writer_is_private, depth + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writer.WriteObjectEnd ();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
public static string ToJson (object obj)
|
||||||
|
{
|
||||||
|
lock (static_writer_lock) {
|
||||||
|
static_writer.Reset ();
|
||||||
|
|
||||||
|
WriteValue (obj, static_writer, true, 0);
|
||||||
|
|
||||||
|
return static_writer.ToString ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ToJson (object obj, JsonWriter writer)
|
||||||
|
{
|
||||||
|
WriteValue (obj, writer, false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonData ToObject (JsonReader reader)
|
||||||
|
{
|
||||||
|
return (JsonData) ToWrapper (
|
||||||
|
delegate { return new JsonData (); }, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonData ToObject (TextReader reader)
|
||||||
|
{
|
||||||
|
JsonReader json_reader = new JsonReader (reader);
|
||||||
|
|
||||||
|
return (JsonData) ToWrapper (
|
||||||
|
delegate { return new JsonData (); }, json_reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonData ToObject (string json)
|
||||||
|
{
|
||||||
|
return (JsonData) ToWrapper (
|
||||||
|
delegate { return new JsonData (); }, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T ToObject<T> (JsonReader reader)
|
||||||
|
{
|
||||||
|
return (T) ReadValue (typeof (T), reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T ToObject<T> (TextReader reader)
|
||||||
|
{
|
||||||
|
JsonReader json_reader = new JsonReader (reader);
|
||||||
|
|
||||||
|
return (T) ReadValue (typeof (T), json_reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T ToObject<T> (string json)
|
||||||
|
{
|
||||||
|
JsonReader reader = new JsonReader (json);
|
||||||
|
|
||||||
|
return (T) ReadValue (typeof (T), reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static object ToObject(string json, Type ConvertType )
|
||||||
|
{
|
||||||
|
JsonReader reader = new JsonReader(json);
|
||||||
|
|
||||||
|
return ReadValue(ConvertType, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IJsonWrapper ToWrapper (WrapperFactory factory,
|
||||||
|
JsonReader reader)
|
||||||
|
{
|
||||||
|
return ReadValue (factory, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IJsonWrapper ToWrapper (WrapperFactory factory,
|
||||||
|
string json)
|
||||||
|
{
|
||||||
|
JsonReader reader = new JsonReader (json);
|
||||||
|
|
||||||
|
return ReadValue (factory, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterExporter<T> (ExporterFunc<T> exporter)
|
||||||
|
{
|
||||||
|
ExporterFunc exporter_wrapper =
|
||||||
|
delegate (object obj, JsonWriter writer) {
|
||||||
|
exporter ((T) obj, writer);
|
||||||
|
};
|
||||||
|
|
||||||
|
custom_exporters_table[typeof (T)] = exporter_wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterImporter<TJson, TValue> (
|
||||||
|
ImporterFunc<TJson, TValue> importer)
|
||||||
|
{
|
||||||
|
ImporterFunc importer_wrapper =
|
||||||
|
delegate (object input) {
|
||||||
|
return importer ((TJson) input);
|
||||||
|
};
|
||||||
|
|
||||||
|
RegisterImporter (custom_importers_table, typeof (TJson),
|
||||||
|
typeof (TValue), importer_wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UnregisterExporters ()
|
||||||
|
{
|
||||||
|
custom_exporters_table.Clear ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UnregisterImporters ()
|
||||||
|
{
|
||||||
|
custom_importers_table.Clear ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 961fd85ffa7394dcda7426e3d498d166
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
#region Header
|
||||||
|
/**
|
||||||
|
* JsonMockWrapper.cs
|
||||||
|
* Mock object implementing IJsonWrapper, to facilitate actions like
|
||||||
|
* skipping data more efficiently.
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
|
|
||||||
|
namespace LitJson
|
||||||
|
{
|
||||||
|
public class JsonMockWrapper : IJsonWrapper
|
||||||
|
{
|
||||||
|
public bool IsArray { get { return false; } }
|
||||||
|
public bool IsBoolean { get { return false; } }
|
||||||
|
public bool IsDouble { get { return false; } }
|
||||||
|
public bool IsInt { get { return false; } }
|
||||||
|
public bool IsLong { get { return false; } }
|
||||||
|
public bool IsObject { get { return false; } }
|
||||||
|
public bool IsString { get { return false; } }
|
||||||
|
|
||||||
|
public bool GetBoolean () { return false; }
|
||||||
|
public double GetDouble () { return 0.0; }
|
||||||
|
public int GetInt () { return 0; }
|
||||||
|
public JsonType GetJsonType () { return JsonType.None; }
|
||||||
|
public long GetLong () { return 0L; }
|
||||||
|
public string GetString () { return ""; }
|
||||||
|
|
||||||
|
public void SetBoolean (bool val) {}
|
||||||
|
public void SetDouble (double val) {}
|
||||||
|
public void SetInt (int val) {}
|
||||||
|
public void SetJsonType (JsonType type) {}
|
||||||
|
public void SetLong (long val) {}
|
||||||
|
public void SetString (string val) {}
|
||||||
|
|
||||||
|
public string ToJson () { return ""; }
|
||||||
|
public void ToJson (JsonWriter writer) {}
|
||||||
|
|
||||||
|
|
||||||
|
bool IList.IsFixedSize { get { return true; } }
|
||||||
|
bool IList.IsReadOnly { get { return true; } }
|
||||||
|
|
||||||
|
object IList.this[int index] {
|
||||||
|
get { return null; }
|
||||||
|
set {}
|
||||||
|
}
|
||||||
|
|
||||||
|
int IList.Add (object value) { return 0; }
|
||||||
|
void IList.Clear () {}
|
||||||
|
bool IList.Contains (object value) { return false; }
|
||||||
|
int IList.IndexOf (object value) { return -1; }
|
||||||
|
void IList.Insert (int i, object v) {}
|
||||||
|
void IList.Remove (object value) {}
|
||||||
|
void IList.RemoveAt (int index) {}
|
||||||
|
|
||||||
|
|
||||||
|
int ICollection.Count { get { return 0; } }
|
||||||
|
bool ICollection.IsSynchronized { get { return false; } }
|
||||||
|
object ICollection.SyncRoot { get { return null; } }
|
||||||
|
|
||||||
|
void ICollection.CopyTo (Array array, int index) {}
|
||||||
|
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator () { return null; }
|
||||||
|
|
||||||
|
|
||||||
|
bool IDictionary.IsFixedSize { get { return true; } }
|
||||||
|
bool IDictionary.IsReadOnly { get { return true; } }
|
||||||
|
|
||||||
|
ICollection IDictionary.Keys { get { return null; } }
|
||||||
|
ICollection IDictionary.Values { get { return null; } }
|
||||||
|
|
||||||
|
object IDictionary.this[object key] {
|
||||||
|
get { return null; }
|
||||||
|
set {}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDictionary.Add (object k, object v) {}
|
||||||
|
void IDictionary.Clear () {}
|
||||||
|
bool IDictionary.Contains (object key) { return false; }
|
||||||
|
void IDictionary.Remove (object key) {}
|
||||||
|
|
||||||
|
IDictionaryEnumerator IDictionary.GetEnumerator () { return null; }
|
||||||
|
|
||||||
|
|
||||||
|
object IOrderedDictionary.this[int idx] {
|
||||||
|
get { return null; }
|
||||||
|
set {}
|
||||||
|
}
|
||||||
|
|
||||||
|
IDictionaryEnumerator IOrderedDictionary.GetEnumerator () {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
void IOrderedDictionary.Insert (int i, object k, object v) {}
|
||||||
|
void IOrderedDictionary.RemoveAt (int i) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 833453b1400fa416bb1bff5d772e8f88
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,478 @@
|
||||||
|
#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.Globalization;
|
||||||
|
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 readonly 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 bool skip_non_members;
|
||||||
|
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 SkipNonMembers {
|
||||||
|
get { return skip_non_members; }
|
||||||
|
set { skip_non_members = 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 ()
|
||||||
|
{
|
||||||
|
parse_table = 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;
|
||||||
|
|
||||||
|
skip_non_members = true;
|
||||||
|
|
||||||
|
this.reader = reader;
|
||||||
|
reader_is_owned = owned;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Static Methods
|
||||||
|
private static IDictionary<int, IDictionary<int, int[]>> PopulateParseTable ()
|
||||||
|
{
|
||||||
|
// See section A.2. of the manual for details
|
||||||
|
IDictionary<int, IDictionary<int, int[]>> parse_table = new Dictionary<int, IDictionary<int, int[]>> ();
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Array);
|
||||||
|
TableAddCol (parse_table, ParserToken.Array, '[',
|
||||||
|
'[',
|
||||||
|
(int) ParserToken.ArrayPrime);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.ArrayPrime);
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, '"',
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, '[',
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, ']',
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, '{',
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.Number,
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.True,
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.False,
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.Null,
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Object);
|
||||||
|
TableAddCol (parse_table, ParserToken.Object, '{',
|
||||||
|
'{',
|
||||||
|
(int) ParserToken.ObjectPrime);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.ObjectPrime);
|
||||||
|
TableAddCol (parse_table, ParserToken.ObjectPrime, '"',
|
||||||
|
(int) ParserToken.Pair,
|
||||||
|
(int) ParserToken.PairRest,
|
||||||
|
'}');
|
||||||
|
TableAddCol (parse_table, ParserToken.ObjectPrime, '}',
|
||||||
|
'}');
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Pair);
|
||||||
|
TableAddCol (parse_table, ParserToken.Pair, '"',
|
||||||
|
(int) ParserToken.String,
|
||||||
|
':',
|
||||||
|
(int) ParserToken.Value);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.PairRest);
|
||||||
|
TableAddCol (parse_table, ParserToken.PairRest, ',',
|
||||||
|
',',
|
||||||
|
(int) ParserToken.Pair,
|
||||||
|
(int) ParserToken.PairRest);
|
||||||
|
TableAddCol (parse_table, ParserToken.PairRest, '}',
|
||||||
|
(int) ParserToken.Epsilon);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.String);
|
||||||
|
TableAddCol (parse_table, ParserToken.String, '"',
|
||||||
|
'"',
|
||||||
|
(int) ParserToken.CharSeq,
|
||||||
|
'"');
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Text);
|
||||||
|
TableAddCol (parse_table, ParserToken.Text, '[',
|
||||||
|
(int) ParserToken.Array);
|
||||||
|
TableAddCol (parse_table, ParserToken.Text, '{',
|
||||||
|
(int) ParserToken.Object);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Value);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, '"',
|
||||||
|
(int) ParserToken.String);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, '[',
|
||||||
|
(int) ParserToken.Array);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, '{',
|
||||||
|
(int) ParserToken.Object);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.Number,
|
||||||
|
(int) ParserToken.Number);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.True,
|
||||||
|
(int) ParserToken.True);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.False,
|
||||||
|
(int) ParserToken.False);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.Null,
|
||||||
|
(int) ParserToken.Null);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.ValueRest);
|
||||||
|
TableAddCol (parse_table, ParserToken.ValueRest, ',',
|
||||||
|
',',
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest);
|
||||||
|
TableAddCol (parse_table, ParserToken.ValueRest, ']',
|
||||||
|
(int) ParserToken.Epsilon);
|
||||||
|
|
||||||
|
return parse_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TableAddCol (IDictionary<int, IDictionary<int, int[]>> parse_table, ParserToken row, int col,
|
||||||
|
params int[] symbols)
|
||||||
|
{
|
||||||
|
parse_table[(int) row].Add (col, symbols);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TableAddRow (IDictionary<int, IDictionary<int, int[]>> parse_table, 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, NumberStyles.Any, CultureInfo.InvariantCulture, out n_double)) {
|
||||||
|
token = JsonToken.Double;
|
||||||
|
token_value = n_double;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int n_int32;
|
||||||
|
if (int.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int32)) {
|
||||||
|
token = JsonToken.Int;
|
||||||
|
token_value = n_int32;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long n_int64;
|
||||||
|
if (long.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int64)) {
|
||||||
|
token = JsonToken.Long;
|
||||||
|
token_value = n_int64;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong n_uint64;
|
||||||
|
if (ulong.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_uint64))
|
||||||
|
{
|
||||||
|
token = JsonToken.Long;
|
||||||
|
token_value = n_uint64;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
using(reader){}
|
||||||
|
}
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 20add0e9f6d594869833f92e1f83a690
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,473 @@
|
||||||
|
#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 readonly 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 bool lower_case_properties;
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LowerCaseProperties {
|
||||||
|
get { return lower_case_properties; }
|
||||||
|
set { lower_case_properties = 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;
|
||||||
|
lower_case_properties = false;
|
||||||
|
|
||||||
|
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 (Environment.NewLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ();
|
||||||
|
string propertyName = (property_name == null || !lower_case_properties)
|
||||||
|
? property_name
|
||||||
|
: property_name.ToLowerInvariant();
|
||||||
|
|
||||||
|
PutString (propertyName);
|
||||||
|
|
||||||
|
if (pretty_print) {
|
||||||
|
if (propertyName.Length > context.Padding)
|
||||||
|
context.Padding = propertyName.Length;
|
||||||
|
|
||||||
|
for (int i = context.Padding - propertyName.Length;
|
||||||
|
i >= 0; i--)
|
||||||
|
writer.Write (' ');
|
||||||
|
|
||||||
|
writer.Write (": ");
|
||||||
|
} else
|
||||||
|
writer.Write (':');
|
||||||
|
|
||||||
|
context.ExpectingValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e85ecd79220b14d90916018e3209a9f9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,912 @@
|
||||||
|
#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 readonly int[] fsm_return_table;
|
||||||
|
private static readonly 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 (out fsm_handler_table, out fsm_return_table);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (out StateHandler[] fsm_handler_table, out int[] fsm_return_table)
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 073348533845249e0b2724d4c7ef1ba8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
#if NETSTANDARD1_5
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
namespace LitJson
|
||||||
|
{
|
||||||
|
internal static class Netstandard15Polyfill
|
||||||
|
{
|
||||||
|
internal static Type GetInterface(this Type type, string name)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().GetInterface(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool IsClass(this Type type)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().IsClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool IsEnum(this Type type)
|
||||||
|
{
|
||||||
|
return type.GetTypeInfo().IsEnum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 621990aae7c344d3e8f972d732d45ec8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9031a963aaabc4ea4a2cbe7b60930880
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
|
|
@ -0,0 +1,91 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e81f4f2831f5f49799f7693a27d4a796
|
||||||
|
TextureImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 10
|
||||||
|
mipmaps:
|
||||||
|
mipMapMode: 0
|
||||||
|
enableMipMap: 1
|
||||||
|
sRGBTexture: 1
|
||||||
|
linearTexture: 0
|
||||||
|
fadeOut: 0
|
||||||
|
borderMipMap: 0
|
||||||
|
mipMapsPreserveCoverage: 0
|
||||||
|
alphaTestReferenceValue: 0.5
|
||||||
|
mipMapFadeDistanceStart: 1
|
||||||
|
mipMapFadeDistanceEnd: 3
|
||||||
|
bumpmap:
|
||||||
|
convertToNormalMap: 0
|
||||||
|
externalNormalMap: 0
|
||||||
|
heightScale: 0.25
|
||||||
|
normalMapFilter: 0
|
||||||
|
isReadable: 0
|
||||||
|
streamingMipmaps: 0
|
||||||
|
streamingMipmapsPriority: 0
|
||||||
|
grayScaleToAlpha: 0
|
||||||
|
generateCubemap: 6
|
||||||
|
cubemapConvolution: 0
|
||||||
|
seamlessCubemap: 0
|
||||||
|
textureFormat: 1
|
||||||
|
maxTextureSize: 2048
|
||||||
|
textureSettings:
|
||||||
|
serializedVersion: 2
|
||||||
|
filterMode: -1
|
||||||
|
aniso: -1
|
||||||
|
mipBias: -100
|
||||||
|
wrapU: -1
|
||||||
|
wrapV: -1
|
||||||
|
wrapW: -1
|
||||||
|
nPOTScale: 1
|
||||||
|
lightmap: 0
|
||||||
|
compressionQuality: 50
|
||||||
|
spriteMode: 0
|
||||||
|
spriteExtrude: 1
|
||||||
|
spriteMeshType: 1
|
||||||
|
alignment: 0
|
||||||
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
|
spritePixelsToUnits: 100
|
||||||
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
spriteGenerateFallbackPhysicsShape: 1
|
||||||
|
alphaUsage: 1
|
||||||
|
alphaIsTransparency: 0
|
||||||
|
spriteTessellationDetail: -1
|
||||||
|
textureType: 0
|
||||||
|
textureShape: 1
|
||||||
|
singleChannelComponent: 0
|
||||||
|
maxTextureSizeSet: 0
|
||||||
|
compressionQualitySet: 0
|
||||||
|
textureFormatSet: 0
|
||||||
|
platformSettings:
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: DefaultTexturePlatform
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 1
|
||||||
|
spriteSheet:
|
||||||
|
serializedVersion: 2
|
||||||
|
sprites: []
|
||||||
|
outline: []
|
||||||
|
physicsShape: []
|
||||||
|
bones: []
|
||||||
|
spriteID:
|
||||||
|
internalID: 0
|
||||||
|
vertices: []
|
||||||
|
indices:
|
||||||
|
edges: []
|
||||||
|
weights: []
|
||||||
|
secondaryTextures: []
|
||||||
|
spritePackingTag:
|
||||||
|
pSDRemoveMatte: 0
|
||||||
|
pSDShowRemoveMatteOption: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4f7d9775824f34defaecdf24870a56f4
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -752,7 +752,7 @@ PlayerSettings:
|
||||||
scriptingDefineSymbols:
|
scriptingDefineSymbols:
|
||||||
1: TextMeshPro
|
1: TextMeshPro
|
||||||
4: TextMeshPro;Notifications;IssuePerson
|
4: TextMeshPro;Notifications;IssuePerson
|
||||||
7: ANDROID_CN;TextMeshPro
|
7: ANDROID_CN;TextMeshPro;JOYPAC_ReYun;JOYPAC_Volcano
|
||||||
13: TextMeshPro
|
13: TextMeshPro
|
||||||
14: TextMeshPro
|
14: TextMeshPro
|
||||||
19: TextMeshPro
|
19: TextMeshPro
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue