Commit f13190e0 authored by gaorui's avatar gaorui
Browse files

Merge branch 'feat-preserv' into 'develop'

Feat preserv

See merge request !22
parents f902e76b ccd0e37f
...@@ -3989,7 +3989,7 @@ RectTransform: ...@@ -3989,7 +3989,7 @@ RectTransform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1562069058} m_GameObject: {fileID: 1562069058}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 50} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
......
{
"name": "HoolaiDemo",
"rootNamespace": "HoolaiDemo",
"references": [
"HoolaiSDK",
"Unity.TextMeshPro"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
fileFormatVersion: 2
guid: 4ad29b91a96fd4dd0a7c1c680da6e981
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine; using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.UI; using UnityEngine.UI;
[Preserve]
public class ExitConfirmationDialog : MonoBehaviour public class ExitConfirmationDialog : MonoBehaviour
{ {
public GameObject dialog; // Reference to the dialog panel public GameObject dialog; // Reference to the dialog panel
......
...@@ -2,13 +2,16 @@ using System.Collections; ...@@ -2,13 +2,16 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using UnityEngine; using UnityEngine;
using UnityEngine.Scripting;
[Preserve]
public class GameManager : MonoBehaviour public class GameManager : MonoBehaviour
{ {
public ExitConfirmationDialog exitDialog; // 在 Inspector 中设置 public ExitConfirmationDialog exitDialog; // 在 Inspector 中设置
private bool isExiting = false; // 防止重复调用退出 private bool isExiting = false; // 防止重复调用退出
[Preserve]
private void Awake() private void Awake()
{ {
// 触发单例构造,内部会调用 PlatformCallback.SetListener(this) // 触发单例构造,内部会调用 PlatformCallback.SetListener(this)
...@@ -18,6 +21,7 @@ public class GameManager : MonoBehaviour ...@@ -18,6 +21,7 @@ public class GameManager : MonoBehaviour
//Android 需监听返回事件,如果当前场景没有游戏业务处理了(比如拦截返回上一个场景,此时无需调用,但返回到顶级场景后继续返回需处理此逻辑)需调用 SDK 的退出接口 //Android 需监听返回事件,如果当前场景没有游戏业务处理了(比如拦截返回上一个场景,此时无需调用,但返回到顶级场景后继续返回需处理此逻辑)需调用 SDK 的退出接口
[Preserve]
void Update() void Update()
{ {
if (Input.GetKey(KeyCode.Escape)) if (Input.GetKey(KeyCode.Escape))
...@@ -26,6 +30,8 @@ public class GameManager : MonoBehaviour ...@@ -26,6 +30,8 @@ public class GameManager : MonoBehaviour
HandleExit(); HandleExit();
} }
} }
[Preserve]
private void HandleExit() private void HandleExit()
{ {
// 防止重复调用 // 防止重复调用
...@@ -39,11 +45,13 @@ public class GameManager : MonoBehaviour ...@@ -39,11 +45,13 @@ public class GameManager : MonoBehaviour
Invoke("ResetExitFlag", 0.5f); Invoke("ResetExitFlag", 0.5f);
} }
[Preserve]
private void ResetExitFlag() private void ResetExitFlag()
{ {
isExiting = false; isExiting = false;
} }
[Preserve]
public void OnLoginBtnClicked() public void OnLoginBtnClicked()
{ {
NativeLogger.I("Game_Unity_Log", "clicked login"); NativeLogger.I("Game_Unity_Log", "clicked login");
...@@ -51,12 +59,14 @@ public class GameManager : MonoBehaviour ...@@ -51,12 +59,14 @@ public class GameManager : MonoBehaviour
HoolaiSdkManager.Login(); HoolaiSdkManager.Login();
} }
[Preserve]
public void OnLogoutBtnClicked() public void OnLogoutBtnClicked()
{ {
NativeLogger.I("Game_Unity_Log", "clicked logout"); NativeLogger.I("Game_Unity_Log", "clicked logout");
HoolaiSdkManager.Logout(); HoolaiSdkManager.Logout();
} }
[Preserve]
public void OnEnterServerBtnClicked() public void OnEnterServerBtnClicked()
{ {
NativeLogger.I("Game_Unity_Log", "clicked EnterServer"); NativeLogger.I("Game_Unity_Log", "clicked EnterServer");
...@@ -67,7 +77,7 @@ public class GameManager : MonoBehaviour ...@@ -67,7 +77,7 @@ public class GameManager : MonoBehaviour
playerInfo.ZoneId = "1"; playerInfo.ZoneId = "1";
playerInfo.ZoneName = "傲视九重天"; playerInfo.ZoneName = "傲视九重天";
playerInfo.ServerId = "1"; playerInfo.ServerId = "1";
playerInfo.ServerName = "牛逼格拉斯"; playerInfo.ServerName = "傲视九重天";
playerInfo.Balance = "9999"; playerInfo.Balance = "9999";
playerInfo.Vip = "99"; playerInfo.Vip = "99";
playerInfo.PartyName = "少林寺"; playerInfo.PartyName = "少林寺";
...@@ -78,10 +88,10 @@ public class GameManager : MonoBehaviour ...@@ -78,10 +88,10 @@ public class GameManager : MonoBehaviour
playerInfo.Phylum = "100"; playerInfo.Phylum = "100";
playerInfo.ClassField = "滴滴滴答"; playerInfo.ClassField = "滴滴滴答";
playerInfo.AddExtra("intKey", 55); //Game Extra sample Data(optional)
playerInfo.AddExtra("longLongKey", 66786658787676); // playerInfo.AddExtra("intKey", 55);
playerInfo.AddExtra("stringKey", "Hello111"); // playerInfo.AddExtra("longLongKey", 66786658787676);
// playerInfo.AddExtra("stringKey", "Hello111");
HoolaiSdkManager.SendEvent(EventType.EnterServer, playerInfo); HoolaiSdkManager.SendEvent(EventType.EnterServer, playerInfo);
NativeLogger.I("Game_Unity_Log", "clicked EnterServer"); NativeLogger.I("Game_Unity_Log", "clicked EnterServer");
...@@ -94,6 +104,7 @@ public class GameManager : MonoBehaviour ...@@ -94,6 +104,7 @@ public class GameManager : MonoBehaviour
} }
[Preserve]
public void OnPayBtnClicked1() public void OnPayBtnClicked1()
{ {
NativeLogger.I("Game_Unity_Log", "clicked Pay"); NativeLogger.I("Game_Unity_Log", "clicked Pay");
...@@ -105,18 +116,21 @@ public class GameManager : MonoBehaviour ...@@ -105,18 +116,21 @@ public class GameManager : MonoBehaviour
ItemId = "com.nekki.sf3.cn_1", ItemId = "com.nekki.sf3.cn_1",
ItemName = "礼包0", ItemName = "礼包0",
CallbackInfo = "123456_8888_987654321", CallbackInfo = "123456_8888_987654321",
NotifyUrl = "", NotifyUrl = "", //支付回调地址,默认使用客户端传递的
Count = 1, Count = 1,
Currency = "CNY" Currency = "CNY"
}; };
payParams.AddOptionalParameter("test", "daily_bonus");
payParams.AddOptionalParameter("player_id", "p-98765"); // 2. 添加可选参数
//payParams.AddOptionalParameter("test", "daily_bonus");
//payParams.AddOptionalParameter("player_id", "p-98765");
NativeLogger.I("Game_Unity_Log", $"clicked Exit jsonString: {payParams}"); NativeLogger.I("Game_Unity_Log", $"clicked Exit jsonString: {payParams}");
HoolaiSdkManager.StartPay(payParams); HoolaiSdkManager.StartPay(payParams);
} }
[Preserve]
public void OnPayBtnClicked6() public void OnPayBtnClicked6()
{ {
NativeLogger.I("Game_Unity_Log", "clicked Pay"); NativeLogger.I("Game_Unity_Log", "clicked Pay");
...@@ -139,6 +153,7 @@ public class GameManager : MonoBehaviour ...@@ -139,6 +153,7 @@ public class GameManager : MonoBehaviour
HoolaiSdkManager.StartPay(payParams); HoolaiSdkManager.StartPay(payParams);
} }
[Preserve]
public void OnPayBtnClicked68() public void OnPayBtnClicked68()
{ {
NativeLogger.I("Game_Unity_Log", "clicked Pay"); NativeLogger.I("Game_Unity_Log", "clicked Pay");
...@@ -161,6 +176,7 @@ public class GameManager : MonoBehaviour ...@@ -161,6 +176,7 @@ public class GameManager : MonoBehaviour
HoolaiSdkManager.StartPay(payParams); HoolaiSdkManager.StartPay(payParams);
} }
[Preserve]
public void OnPayBtnClicked128() public void OnPayBtnClicked128()
{ {
NativeLogger.I("Game_Unity_Log", "clicked Pay"); NativeLogger.I("Game_Unity_Log", "clicked Pay");
...@@ -183,12 +199,14 @@ public class GameManager : MonoBehaviour ...@@ -183,12 +199,14 @@ public class GameManager : MonoBehaviour
HoolaiSdkManager.StartPay(payParams); HoolaiSdkManager.StartPay(payParams);
} }
[Preserve]
public void OnExitBtnClicked() public void OnExitBtnClicked()
{ {
NativeLogger.I("Game_Unity_Log", "clicked Exit"); NativeLogger.I("Game_Unity_Log", "clicked Exit");
HoolaiSdkManager.ExitGame(); HoolaiSdkManager.ExitGame();
} }
[Preserve]
public void OnGetProductInfoBtnClicked() public void OnGetProductInfoBtnClicked()
{ {
NativeLogger.I("Game_Unity_Log", "clicked QueryGoodsInfo"); NativeLogger.I("Game_Unity_Log", "clicked QueryGoodsInfo");
...@@ -197,6 +215,7 @@ public class GameManager : MonoBehaviour ...@@ -197,6 +215,7 @@ public class GameManager : MonoBehaviour
// 添加方法用于根据索引获取单个商品信息 // 添加方法用于根据索引获取单个商品信息
[Preserve]
public static GoodsInfo GetGoodsInfoByIndex(List<GoodsInfo> goodsList, int index) public static GoodsInfo GetGoodsInfoByIndex(List<GoodsInfo> goodsList, int index)
{ {
if (goodsList != null && if (goodsList != null &&
...@@ -210,6 +229,7 @@ public class GameManager : MonoBehaviour ...@@ -210,6 +229,7 @@ public class GameManager : MonoBehaviour
// 新增方法:使用指定索引的商品数据进行支付 // 新增方法:使用指定索引的商品数据进行支付
[Preserve]
public void OnPayWithSpecificGoodsBtnClicked(int goodsIndex) public void OnPayWithSpecificGoodsBtnClicked(int goodsIndex)
{ {
NativeLogger.I("Game_Unity_Log", "clicked Pay With Random Goods"); NativeLogger.I("Game_Unity_Log", "clicked Pay With Random Goods");
...@@ -250,6 +270,7 @@ public class GameManager : MonoBehaviour ...@@ -250,6 +270,7 @@ public class GameManager : MonoBehaviour
// 添加方法用于将GoodsInfo转换为PayParams // 添加方法用于将GoodsInfo转换为PayParams
[Preserve]
public PayParams ConvertGoodsInfoToPayParams(GoodsInfo goodsInfo, int count = 1) public PayParams ConvertGoodsInfoToPayParams(GoodsInfo goodsInfo, int count = 1)
{ {
if (goodsInfo == null) return null; if (goodsInfo == null) return null;
...@@ -270,6 +291,7 @@ public class GameManager : MonoBehaviour ...@@ -270,6 +291,7 @@ public class GameManager : MonoBehaviour
return payParams; return payParams;
} }
[Preserve]
public void OnCDKBtnClicked() public void OnCDKBtnClicked()
{ {
NativeLogger.I("Game_Unity_Log", "clicked CDKey"); NativeLogger.I("Game_Unity_Log", "clicked CDKey");
...@@ -277,18 +299,21 @@ public class GameManager : MonoBehaviour ...@@ -277,18 +299,21 @@ public class GameManager : MonoBehaviour
} }
[Preserve]
public void OnShareBtnClicked() public void OnShareBtnClicked()
{ {
NativeLogger.I("Game_Unity_Log", "clicked shareData"); NativeLogger.I("Game_Unity_Log", "clicked shareData");
HoolaiSdkManager.ShareData(1, 1, "test"); HoolaiSdkManager.ShareData(1, 1, "test");
} }
[Preserve]
public void OnOpenServiceBtnClicked() public void OnOpenServiceBtnClicked()
{ {
NativeLogger.I("Game_Unity_Log", "clicked openService"); NativeLogger.I("Game_Unity_Log", "clicked openService");
HoolaiSdkManager.OpenService(); HoolaiSdkManager.OpenService();
} }
[Preserve]
public void OnOpenAccountBtnClicked() public void OnOpenAccountBtnClicked()
{ {
NativeLogger.I("Game_Unity_Log", "clicked openAccount"); NativeLogger.I("Game_Unity_Log", "clicked openAccount");
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Scripting;
[Preserve]
public class HoolaiListener : IPlatformCallbackListener public class HoolaiListener : IPlatformCallbackListener
{ {
private static HoolaiListener _instance; private static HoolaiListener _instance;
...@@ -25,52 +28,60 @@ public class HoolaiListener : IPlatformCallbackListener ...@@ -25,52 +28,60 @@ public class HoolaiListener : IPlatformCallbackListener
private HoolaiListener() private HoolaiListener()
{ {
// 自动设置监听器 PlatformCallback.SetListener(this);;
PlatformCallback.SetListener(this);
} }
// 初始化退出标准警告 // 初始化退出标准警告
[Preserve]
public void SetExitConfirmationDialog(ExitConfirmationDialog dialog) public void SetExitConfirmationDialog(ExitConfirmationDialog dialog)
{ {
exitDialog = dialog; // 保存对话框实例 exitDialog = dialog; // 保存对话框实例
} }
[Preserve]
public void OnInitSuccess(InitResult result) public void OnInitSuccess(InitResult result)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnInitSuccess GameId:{result.gameId} channel:{result.channel} channelId:{result.channelId}"); NativeLogger.I("Game_Unity_Callback", $"OnInitSuccess GameId:{result.gameId} channel:{result.channel} channelId:{result.channelId}");
} }
[Preserve]
public void OnInitFailed(string reason) public void OnInitFailed(string reason)
{ {;
NativeLogger.I("Game_Unity_Callback", $"OnInitFailed reason:{reason}"); NativeLogger.I("Game_Unity_Callback", $"OnInitFailed reason:{reason}");
} }
[Preserve]
public void OnLoginFailed(string reason) public void OnLoginFailed(string reason)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnLoginFailed reason:{reason}"); NativeLogger.I("Game_Unity_Callback", $"OnLoginFailed reason:{reason}");
} }
[Preserve]
public void OnLoginSuccess(LoginResult result) public void OnLoginSuccess(LoginResult result)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnLoginSuccess uid:{result.uid} channel:{result.channel} channelId:{result.accessToken}"); NativeLogger.I("Game_Unity_Callback", $"OnLoginSuccess uid:{result.uid} channel:{result.channel} channelId:{result.accessToken}");
} }
[Preserve]
public void OnRefreshUser(LoginResult result) public void OnRefreshUser(LoginResult result)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnRefreshUser uid:{result.uid} channel:{result.channel} channelId:{result.accessToken}"); NativeLogger.I("Game_Unity_Callback", $"OnRefreshUser uid:{result.uid} channel:{result.channel} channelId:{result.accessToken}");
} }
[Preserve]
public void OnLogout(string message) public void OnLogout(string message)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnLogout reason:{message}"); NativeLogger.I("Game_Unity_Callback", $"OnLogout reason:{message}");
} }
[Preserve]
public void OnPayFailed(string reason) public void OnPayFailed(string reason)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnPayFailed reason:{reason}"); NativeLogger.I("Game_Unity_Callback", $"OnPayFailed reason:{reason}");
} }
[Preserve]
public void OnPayGoodsList(List<GoodsInfo> goodsList) public void OnPayGoodsList(List<GoodsInfo> goodsList)
{ {
_cachedGoodsList = goodsList; _cachedGoodsList = goodsList;
...@@ -78,32 +89,37 @@ public class HoolaiListener : IPlatformCallbackListener ...@@ -78,32 +89,37 @@ public class HoolaiListener : IPlatformCallbackListener
NativeLogger.I("Game_Unity_Callback", $"OnPayGoodsList count:{goodsList?.Count ?? 0}"); NativeLogger.I("Game_Unity_Callback", $"OnPayGoodsList count:{goodsList?.Count ?? 0}");
} }
// 获取缓存的商品列表 [Preserve]
public List<GoodsInfo> GetCachedGoodsList() public List<GoodsInfo> GetCachedGoodsList()
{ {
return _cachedGoodsList; return _cachedGoodsList;
} }
[Preserve]
public void OnPaySuccess(string message) public void OnPaySuccess(string message)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnPaySuccess message:{message}"); NativeLogger.I("Game_Unity_Callback", $"OnPaySuccess message:{message}");
} }
[Preserve]
public void OnShareFailed(string reason) public void OnShareFailed(string reason)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnShareFailed reason:{reason}"); NativeLogger.I("Game_Unity_Callback", $"OnShareFailed reason:{reason}");
} }
[Preserve]
public void OnShareSuccess(string reason) public void OnShareSuccess(string reason)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnShareSuccess reason:{reason}"); NativeLogger.I("Game_Unity_Callback", $"OnShareSuccess reason:{reason}");
} }
[Preserve]
public void OnUpdate(string data) public void OnUpdate(string data)
{ {
NativeLogger.I("Game_Unity_Callback", $"OnUpdate data:{data}"); NativeLogger.I("Game_Unity_Callback", $"OnUpdate data:{data}");
} }
[Preserve]
public void OnCustomExit() public void OnCustomExit()
{ {
NativeLogger.I("Game_Unity_Callback", $"OnCustomExit show Game Exit Dialog!"); NativeLogger.I("Game_Unity_Callback", $"OnCustomExit show Game Exit Dialog!");
......
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.UI; using UnityEngine.UI;
[Preserve]
public class LogViewer : MonoBehaviour public class LogViewer : MonoBehaviour
{ {
[Header("UI References")] [Header("UI References")]
...@@ -13,19 +16,25 @@ public class LogViewer : MonoBehaviour ...@@ -13,19 +16,25 @@ public class LogViewer : MonoBehaviour
public bool autoScroll = true; public bool autoScroll = true;
public int lineHeight = 33; public int lineHeight = 33;
[Preserve]
private Queue<string> logQueue = new Queue<string>(); private Queue<string> logQueue = new Queue<string>();
[Preserve]
private bool isDirty = false; private bool isDirty = false;
[Preserve]
void OnEnable() void OnEnable()
{ {
Application.logMessageReceived += HandleLog; Application.logMessageReceived += HandleLog;
} }
[Preserve]
void OnDisable() void OnDisable()
{ {
Application.logMessageReceived -= HandleLog; Application.logMessageReceived -= HandleLog;
} }
[Preserve]
void HandleLog(string logString, string stackTrace, LogType type) void HandleLog(string logString, string stackTrace, LogType type)
{ {
string time = System.DateTime.Now.ToString("HH:mm:ss"); string time = System.DateTime.Now.ToString("HH:mm:ss");
...@@ -34,6 +43,7 @@ public class LogViewer : MonoBehaviour ...@@ -34,6 +43,7 @@ public class LogViewer : MonoBehaviour
isDirty = true; isDirty = true;
} }
[Preserve]
void Update() void Update()
{ {
if (isDirty) if (isDirty)
...@@ -44,6 +54,7 @@ public class LogViewer : MonoBehaviour ...@@ -44,6 +54,7 @@ public class LogViewer : MonoBehaviour
} }
[Preserve]
void UpdateLogText() void UpdateLogText()
{ {
if (logText == null || scrollRect == null) if (logText == null || scrollRect == null)
...@@ -67,40 +78,60 @@ public class LogViewer : MonoBehaviour ...@@ -67,40 +78,60 @@ public class LogViewer : MonoBehaviour
logText.text = sb.ToString(); logText.text = sb.ToString();
// ✅ 动态计算 Text 实际高度 // 动态设置尺寸
float preferredHeight = CalculateTextHeight(logText.text, logText); RectTransform textRect = logText.GetComponent<RectTransform>();
RectTransform contentRect = logText.GetComponent<RectTransform>().parent as RectTransform; RectTransform contentRect = scrollRect.content;
if (contentRect != null) RectTransform viewportRect = scrollRect.viewport;
if (textRect != null && contentRect != null && viewportRect != null)
{ {
contentRect.sizeDelta = new Vector2(contentRect.sizeDelta.x, Mathf.Max(preferredHeight, 500)); // 设置 Text 和 Content 的宽度等于 Viewport 宽度
float viewportWidth = viewportRect.rect.width;
textRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, viewportWidth);
contentRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, viewportWidth);
// 计算文本内容的实际高度
float textHeight = CalculateTextHeight(logText.text, logText, viewportWidth);
// 设置 Content 的高度
contentRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, textHeight);
// 强制更新布局
LayoutRebuilder.ForceRebuildLayoutImmediate(contentRect);
Canvas.ForceUpdateCanvases();
} }
// 自动滚动到底部 // 自动滚动到底部
if (autoScroll) if (autoScroll)
{ {
Canvas.ForceUpdateCanvases(); ScrollToBottomNow();
StartCoroutine(ScrollToBottom());
} }
} }
// ✅ 计算 Text 实际高度 // 计算文本内容的实际高度
float CalculateTextHeight(string text, Text textComponent) [Preserve]
float CalculateTextHeight(string text, Text textComponent, float width)
{ {
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(text))
return 0; return 100;
// 创建生成设置
var settings = textComponent.GetGenerationSettings(new Vector2(width, 0));
// 获取文本的首选高度
float height = textComponent.cachedTextGenerator.GetPreferredHeight(text, settings);
var style = textComponent.GetGenerationSettings(textComponent.rectTransform.rect.size);
var height = textComponent.cachedTextGenerator.GetPreferredHeight(text, style);
return height / textComponent.pixelsPerUnit; return height / textComponent.pixelsPerUnit;
} }
[Preserve]
System.Collections.IEnumerator ScrollToBottom() void ScrollToBottomNow()
{ {
yield return null; // 等待一帧 // 滚动到底部
scrollRect.verticalNormalizedPosition = 0f; scrollRect.verticalNormalizedPosition = 0f;
} }
[Preserve]
public void ClearLogs() public void ClearLogs()
{ {
logQueue.Clear(); logQueue.Clear();
......
{ {
"name": "NewAssembly", "name": "HoolaiSDK",
"rootNamespace": "", "rootNamespace": "HoolaiSDK",
"references": [ "references": [
"Unity.TextMeshPro" "Newtonsoft.Json"
], ],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [], "excludePlatforms": [],
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
"versionDefines": [ "versionDefines": [
{ {
"name": "com.unity.nuget.newtonsoft-json", "name": "com.unity.nuget.newtonsoft-json",
"expression": "", "expression": "3.0.0",
"define": "" "define": "NEWTONSOFT_JSON_AVAILABLE"
} }
], ],
"noEngineReferences": false "noEngineReferences": false
......
using UnityEngine; using UnityEngine;
using UnityEngine.Scripting;
[Preserve]
public class AndroidSdkInterface : MonoBehaviour public class AndroidSdkInterface : MonoBehaviour
{ {
private static AndroidJavaClass _serviceClass; private static AndroidJavaClass _serviceClass;
...@@ -105,7 +107,7 @@ public class AndroidSdkInterface : MonoBehaviour ...@@ -105,7 +107,7 @@ public class AndroidSdkInterface : MonoBehaviour
} }
catch (System.Exception ex) catch (System.Exception ex)
{ {
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.enterServer 异常: {ex.Message}"); NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.sendEvent 异常: {ex.Message}");
} }
} }
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
using UnityEngine; using UnityEngine;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System; using System;
using UnityEngine.Scripting;
[Preserve]
public class IosSdkInterface public class IosSdkInterface
{ {
// ================== DllImport 声明 ================== // ================== DllImport 声明 ==================
......
...@@ -2,7 +2,9 @@ using System; ...@@ -2,7 +2,9 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Scripting;
[Preserve]
public class UnityMainThreadDispatcher : MonoBehaviour public class UnityMainThreadDispatcher : MonoBehaviour
{ {
private static readonly Queue<Action> _executionQueue = new Queue<Action>(); private static readonly Queue<Action> _executionQueue = new Queue<Action>();
......
using Newtonsoft.Json; using Newtonsoft.Json;
using UnityEngine; using UnityEngine;
using UnityEngine.Scripting;
[Preserve]
public static class HoolaiSdkManager public static class HoolaiSdkManager
{ {
// ==================== 登录 ==================== // ==================== 登录 ====================
...@@ -43,7 +45,15 @@ public static class HoolaiSdkManager ...@@ -43,7 +45,15 @@ public static class HoolaiSdkManager
// ==================== 数据上报 ==================== // ==================== 数据上报 ====================
public static void SendEvent(EventType eventType, PlayerInfo playerInfo) public static void SendEvent(EventType eventType, PlayerInfo playerInfo)
{ {
string jsonStr = JsonConvert.SerializeObject(playerInfo); if (playerInfo.Extra == null)
{
playerInfo.SetExtra(string.Empty);
}
string jsonStr = JsonConvert.SerializeObject(playerInfo, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Include,
DefaultValueHandling = DefaultValueHandling.Include
});
#if UNITY_ANDROID && !UNITY_EDITOR #if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkSendEvent(eventType, jsonStr); AndroidSdkInterface.CallSdkSendEvent(eventType, jsonStr);
#elif UNITY_IOS && !UNITY_EDITOR #elif UNITY_IOS && !UNITY_EDITOR
......
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine.Scripting;
[Preserve]
public interface IPlatformCallbackListener public interface IPlatformCallbackListener
{ {
void OnInitSuccess(InitResult result); void OnInitSuccess(InitResult result);
......
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using UnityEngine; using UnityEngine;
using UnityEngine.Scripting;
[Preserve]
[System.Serializable] [System.Serializable]
public class InitResult public class InitResult
{ {
[JsonProperty("channel")]
public string channel; public string channel;
[JsonProperty("gameId")]
public int gameId; public int gameId;
[JsonProperty("channelId")]
public int channelId; public int channelId;
} }
[Preserve]
[System.Serializable] [System.Serializable]
public class LoginResult public class LoginResult
{ {
[JsonProperty("uid")]
public long uid; public long uid;
[JsonProperty("accessToken")]
public string accessToken; public string accessToken;
[JsonProperty("channel")]
public string channel; public string channel;
public string channelUid; // 已弃用,默认为0
[JsonProperty("channelUid")]
public string channelUid; // deprecated,default value is 0
[JsonProperty("serverArea")]
public string serverArea; public string serverArea;
public string extendInfo; // 扩展参数转 JSON 字符串再传过来
[JsonProperty("extendInfo")]
public string extendInfo;
} }
[Preserve]
[System.Serializable] [System.Serializable]
public class GoodsInfo public class GoodsInfo
{ {
[JsonProperty("currency")]
public string currency; public string currency;
[JsonProperty("itemId")]
public string itemId; public string itemId;
[JsonProperty("itemName")]
public string itemName; public string itemName;
[JsonProperty("itemCount")]
public string itemCount; public string itemCount;
[JsonProperty("itemPrice")]
public string itemPrice; public string itemPrice;
[JsonProperty("showTag")]
public string showTag; public string showTag;
} }
[Preserve]
public class PlatformCallback : MonoBehaviour public class PlatformCallback : MonoBehaviour
{ {
private static IPlatformCallbackListener _listener; private static IPlatformCallbackListener _listener;
...@@ -64,6 +96,7 @@ public class PlatformCallback : MonoBehaviour ...@@ -64,6 +96,7 @@ public class PlatformCallback : MonoBehaviour
NativeLogger.I("PlatformCallback", $"[PlatformCallback] Initialized with GameObject name: {gameObject.name}"); NativeLogger.I("PlatformCallback", $"[PlatformCallback] Initialized with GameObject name: {gameObject.name}");
} }
[Preserve]
public static void SetListener(IPlatformCallbackListener listener) public static void SetListener(IPlatformCallbackListener listener)
{ {
_listener = listener; _listener = listener;
......
 using UnityEngine.Scripting;
[Preserve]
public enum AccessActivityType public enum AccessActivityType
{ {
CD_KEY = 1 //CD_KEY CD_KEY = 1 //CD_KEY
} }
\ No newline at end of file
using UnityEngine.Scripting;
[Preserve]
public enum EventType public enum EventType
{ {
EnterServer = 1, //进服 EnterServer = 1,
LevelUp = 2, //升级 LevelUp = 2,
CreateRole = 3, //创角 CreateRole = 3,
CustomerAction = 4 //自定义报送 CustomerAction = 4
} }
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using UnityEngine.Scripting;
[Preserve]
public class PayParams public class PayParams
{ {
[JsonProperty("amount")] [JsonProperty("amount")]
public int Amount { get; set; } public int Amount;
[JsonProperty("itemId")] [JsonProperty("itemId")]
public string ItemId { get; set; } public string ItemId;
[JsonProperty("itemName")] [JsonProperty("itemName")]
public string ItemName { get; set; } public string ItemName;
[JsonProperty("count")] [JsonProperty("count")]
public int Count { get; set; } public int Count;
[JsonProperty("callbackInfo")] [JsonProperty("callbackInfo")]
public string CallbackInfo { get; set; } public string CallbackInfo;
[JsonProperty("notifyUrl")] [JsonProperty("notifyUrl")]
public string NotifyUrl { get; set; } public string NotifyUrl;
[JsonProperty("currency")] [JsonProperty("currency")]
public string Currency { get; set; } public string Currency;
[JsonProperty("opt")] [JsonProperty("opt")]
public Dictionary<string, string> Opt { get; private set; } public Dictionary<string, string> Opt;
public PayParams() public PayParams()
{ {
......
using Newtonsoft.Json; using Newtonsoft.Json;
using UnityEngine.Scripting;
[Preserve]
public class PlayerInfo public class PlayerInfo
{ {
[JsonProperty("roleId")] [JsonProperty("roleId")]
public string RoleId { get; set; } public string RoleId;
[JsonProperty("roleName")] [JsonProperty("roleName")]
public string RoleName { get; set; } public string RoleName;
[JsonProperty("roleLevel")] [JsonProperty("roleLevel")]
public string RoleLevel { get; set; } public string RoleLevel;
[JsonProperty("zoneId")] [JsonProperty("zoneId")]
public string ZoneId { get; set; } public string ZoneId;
[JsonProperty("zoneName")] [JsonProperty("zoneName")]
public string ZoneName { get; set; } public string ZoneName;
[JsonProperty("serverId")] [JsonProperty("serverId")]
public string ServerId { get; set; } public string ServerId;
[JsonProperty("serverName")] [JsonProperty("serverName")]
public string ServerName { get; set; } public string ServerName;
[JsonProperty("balance")] [JsonProperty("balance")]
public string Balance { get; set; } public string Balance;
[JsonProperty("vip")] [JsonProperty("vip")]
public string Vip { get; set; } public string Vip;
[JsonProperty("partyName")] [JsonProperty("partyName")]
public string PartyName { get; set; } public string PartyName;
[JsonProperty("appVersion")] [JsonProperty("appVersion")]
public string AppVersion { get; set; } public string AppVersion;
[JsonProperty("appResVersion")] [JsonProperty("appResVersion")]
public string AppResVersion { get; set; } public string AppResVersion;
[JsonProperty("extendAction")] [JsonProperty("extendAction")]
public string ExtendAction { get; set; } public string ExtendAction;
[JsonProperty("roleCreateTime")] [JsonProperty("roleCreateTime")]
public string RoleCreateTime { get; set; } public string RoleCreateTime;
[JsonProperty("phylum")] [JsonProperty("phylum")]
public string Phylum { get; set; } public string Phylum;
[JsonProperty("classField")] [JsonProperty("classField")]
public string ClassField { get; set; } public string ClassField;
[Preserve]
[JsonProperty("extra")] [JsonProperty("extra")]
public string Extra { get; private set; } private string _extra;
/// <summary>
/// 获取 Extra 字段的值(只读)
/// </summary>
[JsonIgnore]
public string Extra => _extra;
/// <summary>
/// 设置 Extra 字段的值
/// </summary>
public void SetExtra(string value)
{
_extra = value ?? string.Empty;
}
public void AddExtra(string key, int value) public void AddExtra(string key, int value)
{ {
if (string.IsNullOrEmpty(key)) return; if (string.IsNullOrEmpty(key)) return;
Extra += key+":"+CrateValue(value)+","; _extra += key + ":" + CreateValue(value) + ",";
} }
public void AddExtra(string key, double value) public void AddExtra(string key, double value)
{ {
if (string.IsNullOrEmpty(key)) return; if (string.IsNullOrEmpty(key)) return;
Extra += key + ":" + CrateValue(value) + ","; _extra += key + ":" + CreateValue(value) + ",";
} }
public void AddExtra(string key, string value) public void AddExtra(string key, string value)
{ {
if (string.IsNullOrEmpty(key) || value == null) return; if (string.IsNullOrEmpty(key) || value == null) return;
Extra += key + ":" + CrateValue(value) + ","; _extra += key + ":" + CreateValue(value) + ",";
} }
private string CrateValue(int val) private string CreateValue(int val)
{ {
return "INT|||" + val; return "INT|||" + val;
} }
private string CrateValue(double val) private string CreateValue(double val)
{ {
return "DOUBLE|||" + val; return "DOUBLE|||" + val;
} }
private string CrateValue(string val) private string CreateValue(string val)
{ {
return val; return val;
} }
......
using UnityEngine; using UnityEngine;
using UnityEngine.Scripting;
/// <summary> /// <summary>
/// 原生日志记录器。 /// 原生日志记录器。
/// 该类直接调用 Android 或 iOS 的系统级日志API,可以绕过 Unity 的 Debug.Log 剥离机制。 /// 该类直接调用 Android 或 iOS 的系统级日志API,可以绕过 Unity 的 Debug.Log 剥离机制。
/// 这意味着即使在 Release Build (非 Development Build) 中,日志也能被输出到 Logcat (Android) 或 Console (iOS)。 /// 这意味着即使在 Release Build (非 Development Build) 中,日志也能被输出到 Logcat (Android) 或 Console (iOS)。
/// </summary> /// </summary>
[Preserve]
public static class NativeLogger public static class NativeLogger
{ {
#if UNITY_ANDROID && !UNITY_EDITOR #if UNITY_ANDROID && !UNITY_EDITOR
// 为 Android 平台缓存 Java Log Class,避免重复查找
private static readonly AndroidJavaClass _logClass = new AndroidJavaClass("android.util.Log"); private static readonly AndroidJavaClass _logClass = new AndroidJavaClass("android.util.Log");
#endif #endif
...@@ -20,16 +21,9 @@ public static class NativeLogger ...@@ -20,16 +21,9 @@ public static class NativeLogger
public static void I(string tag, object message) public static void I(string tag, object message)
{ {
Debug.Log($"[{tag}] {message}"); Debug.Log($"[{tag}] {message}");
#if UNITY_EDITOR #if UNITY_ANDROID && !UNITY_EDITOR
// 在编辑器中,我们仍然使用 Debug.Log,因为它功能更丰富(例如可以点击跳转) // 在 Android 设备上,额外调用 android.util.Log.i 输出到 Logcat
Debug.Log($"[{tag}] {message}");
#elif UNITY_ANDROID
// 在 Android 设备上,直接调用 android.util.Log.i(tag, message)
_logClass.CallStatic<int>("i", tag, message.ToString()); _logClass.CallStatic<int>("i", tag, message.ToString());
#elif UNITY_IOS
// 在 iOS 设备上,调用自定义的 NSLog 封装
// (需要在 Xcode 项目中添加一个 .mm 文件来实现 _logToConsole)
//_logToConsole($"[I] [{tag}] {message}");
#endif #endif
} }
...@@ -40,12 +34,9 @@ public static class NativeLogger ...@@ -40,12 +34,9 @@ public static class NativeLogger
/// <param name="message">日志内容</param> /// <param name="message">日志内容</param>
public static void W(string tag, object message) public static void W(string tag, object message)
{ {
#if UNITY_EDITOR
Debug.LogWarning($"[{tag}] {message}"); Debug.LogWarning($"[{tag}] {message}");
#elif UNITY_ANDROID #if UNITY_ANDROID && !UNITY_EDITOR
_logClass.CallStatic<int>("w", tag, message.ToString()); _logClass.CallStatic<int>("w", tag, message.ToString());
#elif UNITY_IOS
// _logToConsole($"[W] [{tag}] {message}");
#endif #endif
} }
...@@ -56,12 +47,9 @@ public static class NativeLogger ...@@ -56,12 +47,9 @@ public static class NativeLogger
/// <param name="message">日志内容</param> /// <param name="message">日志内容</param>
public static void E(string tag, object message) public static void E(string tag, object message)
{ {
#if UNITY_EDITOR
Debug.LogError($"[{tag}] {message}"); Debug.LogError($"[{tag}] {message}");
#elif UNITY_ANDROID #if UNITY_ANDROID && !UNITY_EDITOR
_logClass.CallStatic<int>("e", tag, message.ToString()); _logClass.CallStatic<int>("e", tag, message.ToString());
#elif UNITY_IOS
// _logToConsole($"[E] [{tag}] {message}");
#endif #endif
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment