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