备份CatanBuilding瘦身独立工程
This commit is contained in:
@@ -0,0 +1,233 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace AIHelp
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
|
||||
public class AIHelpAndroidCore : IAIHelpCore
|
||||
{
|
||||
|
||||
private AndroidJavaClass javaSupport;
|
||||
private AndroidJavaObject currentActivity;
|
||||
|
||||
public AIHelpAndroidCore()
|
||||
{
|
||||
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
||||
javaSupport = new AndroidJavaClass("net.aihelp.init.AIHelpSupport");
|
||||
currentActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");
|
||||
}
|
||||
|
||||
public void Initialize(string domain, string appId, string language)
|
||||
{
|
||||
if (javaSupport != null && currentActivity != null)
|
||||
{
|
||||
javaSupport.CallStatic("initialize", currentActivity, domain, appId, language);
|
||||
}
|
||||
}
|
||||
|
||||
private AndroidJavaObject getLoginConfig(LoginConfig config)
|
||||
{
|
||||
AndroidJavaObject builder = new AndroidJavaObject("net.aihelp.config.LoginConfig$Builder");
|
||||
builder.Call<AndroidJavaObject>("setUserId", config.UserId);
|
||||
builder.Call<AndroidJavaObject>("setUserConfig", getUserConfig(config.UserConfig));
|
||||
builder.Call<AndroidJavaObject>("setEnterpriseAuth", config.EnterpriseAuth);
|
||||
return builder.Call<AndroidJavaObject>("build");
|
||||
}
|
||||
|
||||
private AndroidJavaObject getApiConfig(ApiConfig config)
|
||||
{
|
||||
AndroidJavaObject builder = new AndroidJavaObject("net.aihelp.config.ApiConfig$Builder");
|
||||
return builder.Call<AndroidJavaObject>("build", config.EntranceId, config.WelcomeMessage);
|
||||
}
|
||||
|
||||
private AndroidJavaObject getUserConfig(UserConfig config)
|
||||
{
|
||||
if(config == null) return null;
|
||||
AndroidJavaObject builder = new AndroidJavaObject("net.aihelp.config.UserConfig$Builder");
|
||||
builder.Call<AndroidJavaObject>("setUserName", config.UserName);
|
||||
builder.Call<AndroidJavaObject>("setServerId", config.ServerId);
|
||||
builder.Call<AndroidJavaObject>("setUserTags", config.UserTags);
|
||||
builder.Call<AndroidJavaObject>("setCustomData", config.CustomData);
|
||||
return builder.Call<AndroidJavaObject>("build");
|
||||
}
|
||||
|
||||
private AndroidJavaObject getPublishCountryOrRegion(PublishCountryOrRegion countryOrRegion)
|
||||
{
|
||||
AndroidJavaClass clz = new AndroidJavaClass("net.aihelp.config.enums.PublishCountryOrRegion");
|
||||
return clz.CallStatic<AndroidJavaObject>("fromValue", (int)countryOrRegion);
|
||||
}
|
||||
|
||||
private AndroidJavaObject getPushPlatform(PushPlatform platform)
|
||||
{
|
||||
AndroidJavaClass clz = new AndroidJavaClass("net.aihelp.config.enums.PushPlatform");
|
||||
return clz.CallStatic<AndroidJavaObject>("fromValue", (int)platform);
|
||||
}
|
||||
|
||||
private AndroidJavaObject getShowConversationMoment(ConversationMoment conversationMoment)
|
||||
{
|
||||
AndroidJavaClass clz = new AndroidJavaClass("net.aihelp.config.enums.ShowConversationMoment");
|
||||
return clz.CallStatic<AndroidJavaObject>("fromValue", (int)conversationMoment);
|
||||
}
|
||||
|
||||
private AndroidJavaObject getEventType(EventType eventType)
|
||||
{
|
||||
AndroidJavaClass clz = new AndroidJavaClass("net.aihelp.event.EventType");
|
||||
return clz.CallStatic<AndroidJavaObject>("fromValue", (int)eventType);
|
||||
}
|
||||
|
||||
public bool Show(string entranceId)
|
||||
{
|
||||
if (javaSupport != null && currentActivity != null)
|
||||
{
|
||||
return javaSupport.CallStatic<bool>("show", entranceId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Show(ApiConfig apiConfig)
|
||||
{
|
||||
if (javaSupport != null && currentActivity != null)
|
||||
{
|
||||
return javaSupport.CallStatic<bool>("show", getApiConfig(apiConfig));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ShowSingleFAQ(string faqId, ConversationMoment conversationMoment)
|
||||
{
|
||||
if (javaSupport != null && currentActivity != null)
|
||||
{
|
||||
javaSupport.CallStatic("showSingleFAQ", faqId, getShowConversationMoment(conversationMoment));
|
||||
}
|
||||
}
|
||||
|
||||
public void Login(LoginConfig loginConfig)
|
||||
{
|
||||
if (javaSupport != null && currentActivity != null)
|
||||
{
|
||||
javaSupport.CallStatic("login", getLoginConfig(loginConfig));
|
||||
}
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
if (javaSupport != null && currentActivity != null)
|
||||
{
|
||||
javaSupport.CallStatic("logout");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateUserInfo(UserConfig config)
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
javaSupport.CallStatic("updateUserInfo", getUserConfig(config));
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetUserInfo()
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
javaSupport.CallStatic("resetUserInfo");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateSDKLanguage(string language)
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
javaSupport.CallStatic("updateSDKLanguage", language);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetUploadLogPath(string logPath)
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
javaSupport.CallStatic("setUploadLogPath", logPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPushTokenAndPlatform(string logPath, PushPlatform pushPlatform)
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
javaSupport.CallStatic("setPushTokenAndPlatform", logPath, getPushPlatform(pushPlatform));
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterAsyncEventListener(AIHelp.EventType eventType, AIHelpDelegate.AsyncEventListener listener)
|
||||
{
|
||||
javaSupport.CallStatic("registerAsyncEventListener", getEventType(eventType), listener == null ? null : new AsyncEventListenerProxy(listener));
|
||||
}
|
||||
|
||||
public void UnregisterAsyncEventListener(AIHelp.EventType eventType)
|
||||
{
|
||||
javaSupport.CallStatic("unregisterAsyncEventListener", getEventType(eventType));
|
||||
}
|
||||
|
||||
public void FetchUnreadMessageCount()
|
||||
{
|
||||
javaSupport.CallStatic("fetchUnreadMessageCount");
|
||||
}
|
||||
|
||||
public void FetchUnreadTaskCount()
|
||||
{
|
||||
javaSupport.CallStatic("fetchUnreadTaskCount");
|
||||
}
|
||||
|
||||
public void ShowUrl(string url)
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
javaSupport.CallStatic("showUrl", url);
|
||||
}
|
||||
}
|
||||
|
||||
public void AdditionalSupportFor(PublishCountryOrRegion countryOrRegion)
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
javaSupport.CallStatic("additionalSupportFor", getPublishCountryOrRegion(countryOrRegion));
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSDKVersion()
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
return javaSupport.CallStatic<string>("getSDKVersion");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public bool IsAIHelpShowing()
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
return javaSupport.CallStatic<bool>("isAIHelpShowing");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void EnableLogging(bool isOpen)
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
javaSupport.CallStatic("enableLogging", isOpen);
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (javaSupport != null)
|
||||
{
|
||||
javaSupport.CallStatic("close");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5025625f2980b4854a698e38b5e1478f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
190
LocalPackages/aihelp-5.3/Runtime/AIHelp/Core/AIHelpCore.cs
Normal file
190
LocalPackages/aihelp-5.3/Runtime/AIHelp/Core/AIHelpCore.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
namespace AIHelp
|
||||
{
|
||||
public class AIHelpCore
|
||||
{
|
||||
private IAIHelpCore helpCore;
|
||||
private static AIHelpCore sInstance;
|
||||
|
||||
private AIHelpCore()
|
||||
{
|
||||
|
||||
#if UNITY_ANDROID
|
||||
if (Application.platform == RuntimePlatform.Android) {
|
||||
helpCore = new AIHelpAndroidCore();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_IOS
|
||||
if (Application.platform == RuntimePlatform.IPhonePlayer)
|
||||
{
|
||||
helpCore = new AIHelpiOSCore();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static AIHelpCore getInstance()
|
||||
{
|
||||
if (sInstance == null)
|
||||
{
|
||||
sInstance = new AIHelpCore();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void Initialize(string domain, string appId, string language)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.Initialize(domain, appId, language);
|
||||
}
|
||||
|
||||
public void Initialize(string domain, string appId)
|
||||
{
|
||||
Initialize(domain, appId, "");
|
||||
}
|
||||
|
||||
public bool Show(string entranceId)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return false;
|
||||
return helpCore.Show(entranceId);
|
||||
}
|
||||
|
||||
public bool Show(ApiConfig apiConfig)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return false;
|
||||
return helpCore.Show(apiConfig);
|
||||
}
|
||||
|
||||
public void ShowSingleFAQ(string faqId, ConversationMoment moment)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.ShowSingleFAQ(faqId, moment);
|
||||
}
|
||||
|
||||
public void Login(LoginConfig loginConfig)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.Login(loginConfig);
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.Logout();
|
||||
}
|
||||
|
||||
public void UpdateUserInfo(UserConfig userConfig)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.UpdateUserInfo(userConfig);
|
||||
}
|
||||
|
||||
public void ResetUserInfo()
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.ResetUserInfo();
|
||||
}
|
||||
|
||||
public void UpdateSDKLanguage(string language)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.UpdateSDKLanguage(language);
|
||||
}
|
||||
|
||||
public void SetUploadLogPath(string path)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.SetUploadLogPath(path);
|
||||
}
|
||||
|
||||
public void SetPushTokenAndPlatform(string pushToken, PushPlatform platform)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.SetPushTokenAndPlatform(pushToken, platform);
|
||||
}
|
||||
|
||||
public void FetchUnreadMessageCount()
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.FetchUnreadMessageCount();
|
||||
}
|
||||
|
||||
public void FetchUnreadTaskCount()
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.FetchUnreadTaskCount();
|
||||
}
|
||||
|
||||
public string GetSDKVersion()
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return "";
|
||||
return helpCore.GetSDKVersion();
|
||||
}
|
||||
|
||||
public bool IsAIHelpShowing()
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return false;
|
||||
return helpCore.IsAIHelpShowing();
|
||||
}
|
||||
|
||||
public void EnableLogging(bool enable)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.EnableLogging(enable);
|
||||
}
|
||||
|
||||
public void ShowUrl(string url)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.ShowUrl(url);
|
||||
}
|
||||
|
||||
public void AdditionalSupportFor(PublishCountryOrRegion countryOrRegion)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.AdditionalSupportFor(countryOrRegion);
|
||||
}
|
||||
|
||||
public void RegisterAsyncEventListener(AIHelp.EventType eventType, AIHelpDelegate.AsyncEventListener listener)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.RegisterAsyncEventListener(eventType, listener);
|
||||
}
|
||||
|
||||
public void UnregisterAsyncEventListener(AIHelp.EventType eventType)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.UnregisterAsyncEventListener(eventType);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.Close();
|
||||
}
|
||||
|
||||
#if UNITY_IOS
|
||||
|
||||
public void SetRequestedOrientation(int requestedOrientation)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.SetRequestedOrientation(requestedOrientation);
|
||||
}
|
||||
|
||||
public void SetSDKAppearanceMode(int mode)
|
||||
{
|
||||
if (!IsHelpCorePrepared()) return;
|
||||
helpCore.SetSDKAppearanceMode(mode);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private bool IsHelpCorePrepared()
|
||||
{
|
||||
return helpCore != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f9ac1ead074e4a2586b265550d1fae8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
160
LocalPackages/aihelp-5.3/Runtime/AIHelp/Core/AIHelpiOSCore.cs
Normal file
160
LocalPackages/aihelp-5.3/Runtime/AIHelp/Core/AIHelpiOSCore.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
// We need this one for importing our IOS functions
|
||||
using System.Runtime.InteropServices;
|
||||
using AOT;
|
||||
using System;
|
||||
namespace AIHelp
|
||||
{
|
||||
|
||||
#if UNITY_IOS
|
||||
public partial class AIHelpiOSCore : IAIHelpCore
|
||||
{
|
||||
|
||||
public void Initialize(string domain, string appId, string language = "")
|
||||
{
|
||||
unity_initiailize(domain, appId, language);
|
||||
}
|
||||
|
||||
public void RegisterAsyncEventListener(AIHelp.EventType eventType, AIHelpDelegate.AsyncEventListener listener)
|
||||
{
|
||||
eventListeners[eventType] = listener;
|
||||
unity_registerAsyncEventListener(eventType, OCAsyncEventListener);
|
||||
}
|
||||
|
||||
public void UnregisterAsyncEventListener(AIHelp.EventType eventType)
|
||||
{
|
||||
unity_unregisterAsyncEventListener(eventType);
|
||||
}
|
||||
|
||||
public bool Show(string entranceId)
|
||||
{
|
||||
return unity_show(entranceId, "");
|
||||
}
|
||||
|
||||
public bool Show(ApiConfig apiConfig)
|
||||
{
|
||||
return unity_show(apiConfig.EntranceId, apiConfig.WelcomeMessage);
|
||||
}
|
||||
|
||||
public void ShowSingleFAQ(string faqId, ConversationMoment moment)
|
||||
{
|
||||
unity_showSingleFAQ(faqId, (int)moment);
|
||||
}
|
||||
|
||||
public void Login(LoginConfig loginConfig) {
|
||||
var userConfig = loginConfig.UserConfig;
|
||||
if (userConfig == null) {
|
||||
userConfig = new UserConfig.Builder().Build();
|
||||
}
|
||||
unity_login(loginConfig.UserId, userConfig.UserName, userConfig.ServerId, userConfig.UserTags, userConfig.CustomData, loginConfig.EnterpriseAuth);
|
||||
}
|
||||
|
||||
public void Logout() {
|
||||
unity_logout();
|
||||
}
|
||||
|
||||
public void UpdateUserInfo(UserConfig userConfig)
|
||||
{
|
||||
unity_updateUserInfo(userConfig.UserName, userConfig.ServerId, userConfig.UserTags, userConfig.CustomData);
|
||||
}
|
||||
|
||||
public void ResetUserInfo()
|
||||
{
|
||||
unity_resetUserInfo();
|
||||
}
|
||||
|
||||
public void UpdateSDKLanguage(string language)
|
||||
{
|
||||
unity_updateSDKLanguage(language);
|
||||
}
|
||||
|
||||
public void SetUploadLogPath(string path)
|
||||
{
|
||||
unity_setUploadLogPath(path);
|
||||
}
|
||||
|
||||
public void SetPushTokenAndPlatform(string pushToken, PushPlatform platform)
|
||||
{
|
||||
unity_setPushTokenAndPlatform(pushToken, getPushPlatform(platform));
|
||||
}
|
||||
|
||||
public void FetchUnreadMessageCount()
|
||||
{
|
||||
unity_fetchUnreadMessageCount();
|
||||
}
|
||||
|
||||
public void FetchUnreadTaskCount()
|
||||
{
|
||||
unity_fetchUnreadTaskCount();
|
||||
}
|
||||
|
||||
public string GetSDKVersion()
|
||||
{
|
||||
return unity_getSDKVersion();
|
||||
}
|
||||
|
||||
public bool IsAIHelpShowing()
|
||||
{
|
||||
return unity_isAIHelpShowing();
|
||||
}
|
||||
|
||||
public void EnableLogging(bool enable)
|
||||
{
|
||||
unity_enableLogging(enable);
|
||||
}
|
||||
|
||||
public void ShowUrl(string url)
|
||||
{
|
||||
unity_showUrl(url);
|
||||
}
|
||||
|
||||
public void AdditionalSupportFor(PublishCountryOrRegion countryOrRegion)
|
||||
{
|
||||
unity_additionalSupportFor(countryOrRegion);
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
unity_close();
|
||||
}
|
||||
|
||||
public void SetRequestedOrientation(int requestedOrientation)
|
||||
{
|
||||
unity_setSDKInterfaceOrientationMask(requestedOrientation);
|
||||
}
|
||||
|
||||
public void SetSDKAppearanceMode(int mode)
|
||||
{
|
||||
unity_setSDKInterfaceOrientationMask(mode);
|
||||
}
|
||||
|
||||
private int getPushPlatform(PushPlatform platform){
|
||||
int tempPlatform = 2;
|
||||
if (platform == PushPlatform.APNS)
|
||||
{
|
||||
tempPlatform = 1;
|
||||
}
|
||||
else if (platform == PushPlatform.FIREBASE)
|
||||
{
|
||||
tempPlatform = 2;
|
||||
}
|
||||
else if (platform == PushPlatform.JIGUANG)
|
||||
{
|
||||
tempPlatform = 3;
|
||||
}
|
||||
else if (platform == PushPlatform.GETUI)
|
||||
{
|
||||
tempPlatform = 4;
|
||||
}
|
||||
else if (platform == PushPlatform.HUAWEI)
|
||||
{
|
||||
tempPlatform = 6;
|
||||
}
|
||||
else if (platform == PushPlatform.ONE_SIGNAL)
|
||||
{
|
||||
tempPlatform = 7;
|
||||
}
|
||||
return tempPlatform;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2a510a461fd54d4881c024ad42035ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b10e874e5837b4579b62e9924a20f806
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace AIHelp
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
public class AsyncEventListenerProxy : AndroidJavaProxy
|
||||
{
|
||||
private readonly AIHelpDelegate.AsyncEventListener eventListener;
|
||||
private AndroidJavaObject ackRef;
|
||||
|
||||
public AsyncEventListenerProxy(AIHelpDelegate.AsyncEventListener eventListener) : base("net.aihelp.event.AsyncEventListener")
|
||||
{
|
||||
this.eventListener = eventListener;
|
||||
}
|
||||
|
||||
void onAsyncEventReceived(string jsonEventData, AndroidJavaObject ack)
|
||||
{
|
||||
ackRef = ack;
|
||||
var jniThread = System.Threading.Thread.CurrentThread;
|
||||
|
||||
Action<string> acknowledge = jsonAckData =>
|
||||
{
|
||||
bool isAttached = false;
|
||||
bool isAsync = System.Threading.Thread.CurrentThread != jniThread;
|
||||
try
|
||||
{
|
||||
// Attach the current thread to the JNI environment
|
||||
if (AndroidJNI.AttachCurrentThread() == (int)IntPtr.Zero)
|
||||
{
|
||||
isAttached = true;
|
||||
}
|
||||
if (ackRef != null)
|
||||
{
|
||||
ackRef.Call("acknowledge", jsonAckData);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Handle any exceptions that may occur during the JNI call
|
||||
Debug.LogError("Exception during JNI call: " + e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (isAsync && isAttached)
|
||||
{
|
||||
// Ensure we detach the current thread from the JNI environment if it was attached
|
||||
AndroidJNI.DetachCurrentThread();
|
||||
}
|
||||
}
|
||||
};
|
||||
eventListener(jsonEventData, acknowledge);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 212c0cec872fc40fca66b6827ac48f80
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
LocalPackages/aihelp-5.3/Runtime/AIHelp/Core/IAIHelpCore.cs
Normal file
43
LocalPackages/aihelp-5.3/Runtime/AIHelp/Core/IAIHelpCore.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
|
||||
namespace AIHelp
|
||||
{
|
||||
public interface IAIHelpCore
|
||||
{
|
||||
void Initialize(string domain, string appId, string language);
|
||||
|
||||
bool Show(string entranceId);
|
||||
bool Show(ApiConfig apiConfig);
|
||||
void ShowSingleFAQ(string faqId, ConversationMoment moment);
|
||||
|
||||
void Login(LoginConfig loginConfig);
|
||||
void Logout();
|
||||
void UpdateUserInfo(UserConfig userConfig);
|
||||
void ResetUserInfo();
|
||||
|
||||
void UpdateSDKLanguage(string language);
|
||||
void SetUploadLogPath(string path);
|
||||
void SetPushTokenAndPlatform(string pushToken, PushPlatform platform);
|
||||
|
||||
void FetchUnreadMessageCount();
|
||||
void FetchUnreadTaskCount();
|
||||
|
||||
string GetSDKVersion();
|
||||
bool IsAIHelpShowing();
|
||||
void EnableLogging(bool enable);
|
||||
void ShowUrl(string url);
|
||||
void AdditionalSupportFor(PublishCountryOrRegion countryOrRegion);
|
||||
|
||||
void RegisterAsyncEventListener(AIHelp.EventType eventType, AIHelpDelegate.AsyncEventListener listener);
|
||||
void UnregisterAsyncEventListener(AIHelp.EventType eventType);
|
||||
|
||||
void Close();
|
||||
|
||||
#if UNITY_IOS
|
||||
void SetRequestedOrientation(int requestedOrientation); // ios only
|
||||
void SetSDKAppearanceMode(int mode); // iOS only 0: follow the system 1: light mode 2: dark mode
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b63a845cae20749c1be5d13f2ccd2ede
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
LocalPackages/aihelp-5.3/Runtime/AIHelp/Core/iOS.meta
Normal file
8
LocalPackages/aihelp-5.3/Runtime/AIHelp/Core/iOS.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54ad73766cfa345e6a6859b9ade52598
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using AOT;
|
||||
|
||||
namespace AIHelp
|
||||
{
|
||||
#if UNITY_IOS
|
||||
public partial class AIHelpiOSCore
|
||||
{
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_initiailize(string domainName, string appId, string language);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_registerAsyncEventListener(AIHelp.EventType eventType, AIHelpAsyncEventListener listener);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_unregisterAsyncEventListener(AIHelp.EventType eventType);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_login(string userId, string userName, string serverId, string userTags, string customData, bool isEnterpriseAuth);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_logout();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_updateUserInfo(string userName, string serverId, string userTags, string customData);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_resetUserInfo();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_updateSDKLanguage(string language);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_setUploadLogPath(string path);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_setPushTokenAndPlatform(string pushToken, int pushPlatform);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern string unity_getSDKVersion();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern bool unity_isAIHelpShowing();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_enableLogging(bool enable);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_close();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern bool unity_show(string entranceId, string welcomeMessage);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_showSingleFAQ(string faqId, int conversationMoment);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_fetchUnreadMessageCount();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_fetchUnreadTaskCount();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_showUrl(string url);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_additionalSupportFor(PublishCountryOrRegion countryOrRegion);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_setSDKAppearanceMode(int mode);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void unity_setSDKInterfaceOrientationMask(int interfaceOrientationMask);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35414e6ccf0a84d9bb2566d2180a0a6f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using AOT;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AIHelp
|
||||
{
|
||||
#if UNITY_IOS
|
||||
public partial class AIHelpiOSCore
|
||||
{
|
||||
private static Dictionary<AIHelp.EventType, AIHelpDelegate.AsyncEventListener> eventListeners =
|
||||
new Dictionary<AIHelp.EventType, AIHelpDelegate.AsyncEventListener>();
|
||||
|
||||
// 在 cs 注册的回调方法
|
||||
static event AIHelpDelegate.AsyncEventListener csAsyncEventListener;
|
||||
|
||||
// oc 传过来的 ack 回调,缓存下来异步使用
|
||||
public static Acknowledgement AckDelegate { get; set; }
|
||||
|
||||
// 声明一个符合 ack 回调的代理,用来持有 ack 回调指针的时候使用
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void Acknowledgement(string ackJsonData);
|
||||
|
||||
// OC 回调方法签名 - event, ack
|
||||
public delegate void AIHelpAsyncEventListener(string jsonEventData, IntPtr acknowledgePtr);
|
||||
|
||||
[MonoPInvokeCallback(typeof(AIHelpAsyncEventListener))]
|
||||
private static void OCAsyncEventListener(string jsonEventData, IntPtr acknowledgePtr)
|
||||
{
|
||||
var intEventType = SimpleJsonParser.ExtractEventTypeFromJson(jsonEventData);
|
||||
if (intEventType != -1) {
|
||||
AIHelp.EventType eventType = (AIHelp.EventType)SimpleJsonParser.ExtractEventTypeFromJson(jsonEventData);
|
||||
if (eventListeners.TryGetValue(eventType, out var listener))
|
||||
{
|
||||
Action<string> acknowledge = jsonAckData => {
|
||||
if (acknowledgePtr != IntPtr.Zero) {
|
||||
AckDelegate = Marshal.GetDelegateForFunctionPointer<Acknowledgement>(acknowledgePtr);
|
||||
AckDelegate?.Invoke(jsonAckData);
|
||||
}
|
||||
};
|
||||
listener?.Invoke(jsonEventData, acknowledge);
|
||||
} else {
|
||||
Debug.LogError($"[AIHelp] Unable to find any listener for event type: {eventType}. Have you declared it?");
|
||||
}
|
||||
} else {
|
||||
Debug.LogError($"[AIHelp] Unable to retrieve eventType from eventData: {jsonEventData}");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07b537e2737b74ea38fb190ca953a218
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
|
||||
public static class SimpleJsonParser
|
||||
{
|
||||
public static int ExtractEventTypeFromJson(string json)
|
||||
{
|
||||
string fieldValue = ExtractFieldFromJson(json, "eventType");
|
||||
if (string.IsNullOrEmpty(fieldValue))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return int.Parse(fieldValue);
|
||||
}
|
||||
|
||||
public static string ExtractFieldFromJson(string json, string fieldName)
|
||||
{
|
||||
string target = $"\"{fieldName}\":";
|
||||
int startIndex = json.IndexOf(target, StringComparison.OrdinalIgnoreCase);
|
||||
if (startIndex >= 0)
|
||||
{
|
||||
startIndex += target.Length;
|
||||
// Skip whitespace
|
||||
while (char.IsWhiteSpace(json[startIndex])) startIndex++;
|
||||
|
||||
// Determine if the value is a string or number
|
||||
if (json[startIndex] == '"') // string value
|
||||
{
|
||||
startIndex++;
|
||||
int endIndex = json.IndexOf('"', startIndex);
|
||||
if (endIndex > startIndex)
|
||||
{
|
||||
return json.Substring(startIndex, endIndex - startIndex);
|
||||
}
|
||||
}
|
||||
else // numeric value
|
||||
{
|
||||
int endIndex = json.IndexOfAny(new[] { ',', '}', ' ' }, startIndex);
|
||||
if (endIndex > startIndex)
|
||||
{
|
||||
return json.Substring(startIndex, endIndex - startIndex).Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb9be6b068ec448f48556f9a85df870c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user