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
274f3796
Commit
274f3796
authored
Oct 16, 2025
by
wushaojie
🏀
Browse files
Merge branch 'feat-dev-ios' into 'main'
Feat dev ios See merge request unity-cross/UnityDemo!6
parents
3b5b3df0
7606c86a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Assets/Plugins/Editor/IOSPostBuildProcessor.cs
View file @
274f3796
...
...
@@ -156,16 +156,13 @@ public static class IOSPostBuildProcessor
}
}
/// <summary>
/// 修复 PBX 工程文件中对 UnityAppController 的错误引用
/// </summary>
private
static
void
FixFileReference
(
PBXProject
proj
,
string
targetGuid
,
string
pathToBuiltProject
)
{
string
newPathH
=
"Classes/UnityAppController.h"
;
string
newPathMM
=
"Classes/UnityAppController.mm"
;
// 删除旧的 .h 文件引用
var
oldPathH
=
"Libraries/Plugins/
Ios
/UnityAppController.h"
;
var
oldPathH
=
"Libraries/Plugins/
iOS
/UnityAppController.h"
;
var
oldGUID_H
=
proj
.
FindFileGuidByProjectPath
(
oldPathH
);
if
(!
string
.
IsNullOrEmpty
(
oldGUID_H
)){
proj
.
RemoveFileFromBuild
(
targetGuid
,
oldGUID_H
);
...
...
@@ -174,7 +171,7 @@ public static class IOSPostBuildProcessor
}
// 删除旧的 .mm 文件引用
var
oldPathMM
=
"Libraries/Plugins/
Ios
/UnityAppController.mm"
;
var
oldPathMM
=
"Libraries/Plugins/
iOS
/UnityAppController.mm"
;
var
oldGUID_MM
=
proj
.
FindFileGuidByProjectPath
(
oldPathMM
);
if
(!
string
.
IsNullOrEmpty
(
oldGUID_MM
)){
proj
.
RemoveFileFromBuild
(
targetGuid
,
oldGUID_MM
);
...
...
Assets/Plugins/iOS/UnityAppController.h.meta
deleted
100644 → 0
View file @
3b5b3df0
fileFormatVersion: 2
guid: 7c52c6bae4f6d42c296f0de9df536ef5
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:
Assets/Plugins/iOS/UnityAppController.mm.meta
deleted
100644 → 0
View file @
3b5b3df0
fileFormatVersion: 2
guid: 12d3c24cb8df145abb64f72b45206b99
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:
Assets/Plugins/iOS/UnityBridge.h.meta
deleted
100644 → 0
View file @
3b5b3df0
fileFormatVersion: 2
guid: fbcc30c9db7014f8f8e136ddfd11516e
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:
Assets/Plugins/iOS/UnityBridge.mm
View file @
274f3796
...
...
@@ -38,24 +38,24 @@ extern "C" {
@"channelId"
:
@
(
initResult
.
channelId
)
};
NSString
*
json
=
jsonStringWithObject
(
dict
);
UnitySendMessage
(
"
SdkManager"
,
"OnSdkInit
"
,
[
json
UTF8String
]);
UnitySendMessage
(
"
PlatformCallback"
,
"onInitSuccess
"
,
[
json
UTF8String
]);
}
-
(
void
)
initFailed
{
NSLog
(
@"🍎 SDK初始化失败"
);
UnitySendMessage
(
"
SdkManager"
,
"OnSdkInit
"
,
"failed"
);
UnitySendMessage
(
"
PlatformCallback"
,
"onInitFailed
"
,
"failed"
);
}
#pragma mark - HLPaymentDelegate
-
(
void
)
paySuccess
{
NSLog
(
@"🍎 支付成功"
);
UnitySendMessage
(
"
SdkManager"
,
"OnSdkPay
"
,
"pay_success"
);
UnitySendMessage
(
"
PlatformCallback"
,
"onPaySuccess
"
,
"pay_success"
);
}
-
(
void
)
payError
:(
NSError
*
)
error
{
NSLog
(
@"🍎 支付失败: %@"
,
error
.
localizedDescription
);
NSString
*
errorMsg
=
[
NSString
stringWithFormat
:
@"pay_failed:%@"
,
error
.
localizedDescription
];
UnitySendMessage
(
"
SdkManager"
,
"OnSdkPay
"
,
[
errorMsg
UTF8String
]);
UnitySendMessage
(
"
PlatformCallback"
,
"onPayFailed
"
,
[
errorMsg
UTF8String
]);
}
-
(
void
)
payGoodsList
:(
NSArray
<
AccessGoodsInfo
*>*
)
info
{
...
...
@@ -76,12 +76,12 @@ extern "C" {
[
array
addObject
:
dict
];
}
NSString
*
json
=
jsonStringWithObject
(
array
);
UnitySendMessage
(
"
SdkManager
"
,
"
O
nPayGoodsList"
,
[
json
UTF8String
]);
UnitySendMessage
(
"
PlatformCallback
"
,
"
o
nPayGoodsList"
,
[
json
UTF8String
]);
}
-
(
void
)
payGpodsListFail
{
NSLog
(
@"🍎 获取商品列表失败"
);
UnitySendMessage
(
"
SdkManager
"
,
"OnGoodsList"
,
"get_goods_failed"
);
UnitySendMessage
(
"
PlatformCallback
"
,
"OnGoodsList"
,
"get_goods_failed"
);
}
#pragma mark - HLAccountDelegate
...
...
@@ -96,7 +96,7 @@ extern "C" {
@"extendInfo"
:
accountInfo
.
extendInfo
?:
@{}
};
NSString
*
json
=
jsonStringWithObject
(
dict
);
UnitySendMessage
(
"
SdkManager
"
,
"OnLoginSuccess"
,
[
json
UTF8String
]);
UnitySendMessage
(
"
PlatformCallback
"
,
"OnLoginSuccess"
,
[
json
UTF8String
]);
}
-
(
void
)
refreshUser
:(
AccessLoginInfo
*
)
refreshAccountInfo
{
...
...
@@ -110,28 +110,28 @@ extern "C" {
@"extendInfo"
:
refreshAccountInfo
.
extendInfo
?:
@{}
};
NSString
*
json
=
jsonStringWithObject
(
dict
);
UnitySendMessage
(
"
SdkManager
"
,
"OnUserRefresh"
,
[
json
UTF8String
]);
UnitySendMessage
(
"
PlatformCallback
"
,
"OnUserRefresh"
,
[
json
UTF8String
]);
}
-
(
void
)
loginFailure
{
NSLog
(
@"🍎 登录失败"
);
UnitySendMessage
(
"
SdkManager
"
,
"OnSdkLogin"
,
"login_failed"
);
UnitySendMessage
(
"
PlatformCallback
"
,
"OnSdkLogin"
,
"login_failed"
);
}
-
(
void
)
logout
{
NSLog
(
@"🍎 用户登出"
);
UnitySendMessage
(
"
SdkManager
"
,
"OnSdkLogout"
,
"logout_success"
);
UnitySendMessage
(
"
PlatformCallback
"
,
"OnSdkLogout"
,
"logout_success"
);
}
#pragma mark - HLShareCallback
-
(
void
)
shareSucceeded
:(
BOOL
)
result
{
NSLog
(
@"🍎 分享成功: %@"
,
result
?
@"YES"
:
@"NO"
);
UnitySendMessage
(
"
SdkManager
"
,
"OnSdkShare"
,
"share_success"
);
UnitySendMessage
(
"
PlatformCallback
"
,
"OnSdkShare"
,
"share_success"
);
}
-
(
void
)
shareFailed
:(
BOOL
)
result
{
NSLog
(
@"🍎 分享失败: %@"
,
result
?
@"YES"
:
@"NO"
);
UnitySendMessage
(
"
SdkManager
"
,
"OnSdkShare"
,
"share_failed"
);
UnitySendMessage
(
"
PlatformCallback
"
,
"OnSdkShare"
,
"share_failed"
);
}
@end
...
...
@@ -255,12 +255,12 @@ extern "C" {
if
(
error
)
return
;
// 直接映射字段
payInfo
.
productIdentifier
=
jsonDict
[
@"
Product
Id"
]
?
[
NSString
stringWithFormat
:
@"%@"
,
jsonDict
[
@"
Product
Id"
]]
:
@""
;
payInfo
.
price
=
jsonDict
[
@"
Price
"
]
?
[
jsonDict
[
@"
Price
"
]
intValue
]
:
0
;
payInfo
.
currencyLocale
=
jsonDict
[
@"
C
urrency"
]
?
[
NSString
stringWithFormat
:
@"%@"
,
jsonDict
[
@"
C
urrency"
]]
:
@""
;
payInfo
.
notifyUrl
=
jsonDict
[
@"
N
otifyUrl"
]
?
[
NSString
stringWithFormat
:
@"%@"
,
jsonDict
[
@"
N
otifyUrl"
]]
:
@""
;
payInfo
.
gameInfo
=
jsonDict
[
@"
Game
Info"
]
?
[
NSString
stringWithFormat
:
@"%@"
,
jsonDict
[
@"
Game
Info"
]]
:
@""
;
payInfo
.
productIdentifier
=
jsonDict
[
@"
item
Id"
]
?
[
NSString
stringWithFormat
:
@"%@"
,
jsonDict
[
@"
item
Id"
]]
:
@""
;
payInfo
.
price
=
jsonDict
[
@"
amount
"
]
?
[
jsonDict
[
@"
amount
"
]
intValue
]
:
0
;
payInfo
.
currencyLocale
=
jsonDict
[
@"
c
urrency"
]
?
[
NSString
stringWithFormat
:
@"%@"
,
jsonDict
[
@"
c
urrency"
]]
:
@""
;
payInfo
.
notifyUrl
=
jsonDict
[
@"
n
otifyUrl"
]
?
[
NSString
stringWithFormat
:
@"%@"
,
jsonDict
[
@"
n
otifyUrl"
]]
:
@""
;
payInfo
.
gameInfo
=
jsonDict
[
@"
callback
Info"
]
?
[
NSString
stringWithFormat
:
@"%@"
,
jsonDict
[
@"
callback
Info"
]]
:
@""
;
NSLog
(
@"🍎 支付信息: productId=%@, price=%d"
,
payInfo
.
productIdentifier
,
payInfo
.
price
);
[
sdk
pay
:
payInfo
];
}
...
...
Assets/Plugins/iOS/UnityBridge.mm.meta
deleted
100644 → 0
View file @
3b5b3df0
fileFormatVersion: 2
guid: 8a2bed7a3301d4300827ecb96648cd28
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/sdk/core/PlatformCallback.cs
View file @
274f3796
...
...
@@ -67,6 +67,9 @@ public class PlatformCallback : MonoBehaviour
public
void
onInitSuccess
(
string
jsonStr
)
{
Debug
.
Log
(
"Unity onInitSuccess: "
+
jsonStr
);
NativeLogger
.
I
(
"fastsdk_unity_result"
,
"[AndroidBrigsCall] onInitSuccess called with result: "
+
jsonStr
);
InitResult
result
=
JsonConvert
.
DeserializeObject
<
InitResult
>(
jsonStr
);
if
(
result
!=
null
)
...
...
@@ -150,6 +153,8 @@ public class PlatformCallback : MonoBehaviour
public
void
onPayGoodsList
(
string
jsonStr
)
{
Debug
.
Log
(
"Unity 收到商品列表: "
+
jsonStr
);
NativeLogger
.
I
(
"fastsdk_unity_result"
,
"[Unity] onPayGoodsList called with message: "
+
jsonStr
);
//goodsList = JsonConvert.DeserializeObject<List<GoodsInfo>(jsonStr);
// 方法一:直接解析为List<GoodsInfo>
...
...
Assets/Scripts/sdk/util/NativeLogger.cs
View file @
274f3796
...
...
@@ -29,7 +29,7 @@ public static class NativeLogger
#elif UNITY_IOS
// 在 iOS 设备上,调用自定义的 NSLog 封装
// (需要在 Xcode 项目中添加一个 .mm 文件来实现 _logToConsole)
//
_logToConsole($"[I] [{tag}] {message}");
_logToConsole
(
$"[I] [
{
tag
}
]
{
message
}
"
);
#endif
}
...
...
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