PS4 Unity 接入
Vs环境配置(没有c++开发不需要配置)
vs项目属性->Linker->General->Additional Dependencies添加如下配置
libclang_rt.profile-x86_64.a;libc_lto.a;libc_stub_weak.a;libEdgeAnim.a;libEdgeAnimTool.a;libEdgeAnim_debug.a;libkernel_cpumode_platform_stub_weak.a;libkernel_stub_weak.a;libSceAjm_stub_weak.a;libSceAppContent_stub_weak.a;libSceAt9Enc_stub_weak.a;libSceAudio3d_stub_weak.a;libSceAudiodecCpuHevag_stub_weak.a;libSceAudiodecCpu_stub_weak.a;libSceAudiodec_stub_weak.a;libSceAudioIn_stub_weak.a;libSceAudioLatencyEstimation_stub_weak.a;libSceAudioOut_stub_weak.a;libSceAvPlayer_stub_weak.a;libSceCamera_stub_weak.a;libSceCes.a;libSceCesCs_stub_weak.a;libSceCesUc.a;libSceCommonDialog_stub_weak.a;libSceContentDelete_stub_weak.a;libSceContentExport_stub_weak.a;libSceContentSearch_stub_weak.a;libSceConvertKeycode_stub_weak.a;libSceCoredumpStructuredData.a;libSceCoredump_debug_stub_weak.a;libSceCoredump_stub_weak.a;libSceDbgAddressSanitizer_stub_weak.a;libSceDbgAudioOut_stub_weak.a;libSceDbgEnC.a;libSceDbgKeyboard_stub_weak.a;libSceDbgPlayGo_stub_weak.a;libSceDbgShaderLiveEditing.a;libSceDbgUBSanitizer_stub_weak.a;libSceDbgVideoOut_stub_weak.a;libSceDbg_stub_weak.a;libSceDeci4h_stub_weak.a;libSceDepth_stub_weak.a;libSceErrorDialog_stub_weak.a;libSceFaceTracker_stub_weak.a;libSceFace_stub_weak.a;libSceFiber_stub_weak.a;libSceFios2_debug_stub_weak.a;libSceFios2_stub_weak.a;libSceFontFt_stub_weak.a;libSceFont_stub_weak.a;libSceGameLiveStreaming_stub_weak.a;libSceGnf.a;libSceGnf_debug.a;libSceGnm.a;libSceGnmDriver_stub_weak.a;libSceGnmx.a;libSceGnmx_debug.a;libSceGnmx_lto.a;libSceGnm_debug.a;libSceGnm_lto.a;libSceGpuAddress.a;libSceGpuAddress_debug.a;libSceGpuAddress_lto.a;libSceGpuDebugger_stub_weak.a;libSceHandTracker_stub_weak.a;libSceHand_stub_weak.a;libSceHeadTracker_stub_weak.a;libSceHmac.a;libSceHmdSetupDialog_stub_weak.a;libSceHmd_stub_weak.a;libSceHttp2_stub_weak.a;libSceHttp_stub_weak.a;libSceImeBackend_stub_weak.a;libSceImeDialog_stub_weak.a;libSceIme_stub_weak.a;libSceInvitationDialog_stub_weak.a;libSceJobManagerTest.a;libSceJobManager_stub_weak.a;libSceJpegDec_stub_weak.a;libSceJpegEnc_stub_weak.a;libSceJson2_stub_weak.a;libSceLoginDialog_stub_weak.a;libSceLoginService_stub_weak.a;libSceM4aacEnc_stub_weak.a;libSceMat_stub_weak.a;libSceMd5.a;libSceMouse_stub_weak.a;libSceMoveTracker_stub_weak.a;libSceMove_stub_weak.a;libSceMsgDialog_stub_weak.a;libSceMt19937.a;libSceNetCtlApDialog_stub_weak.a;libSceNetCtlAp_stub_weak.a;libSceNetCtl_stub_weak.a;libSceNetDebug_stub_weak.a;libSceNet_stub_weak.a;libSceNgs2_stub_weak.a;libSceNpAuth_stub_weak.a;libSceNpCommerce_stub_weak.a;libSceNpCommon_stub_weak.a;libSceNpCppWebApi_stub_weak.a;libSceNpEntitlementAccess_stub_weak.a;libSceNpFriendListDialog_stub_weak.a;libSceNpGameIntent_stub_weak.a;libSceNpManager_stub_weak.a;libSceNpMatching2_stub_weak.a;libSceNpParty_stub_weak.a;libSceNpProfileDialog_stub_weak.a;libSceNpScore_stub_weak.a;libSceNpSessionSignaling_stub_weak.a;libSceNpSignaling_stub_weak.a;libSceNpToolkit2_stub_weak.a;libSceNpTrophy_stub_weak.a;libSceNpTus_stub_weak.a;libSceNpUtility_stub_weak.a;libSceNpWebApi2_stub_weak.a;libSceNpWebApi_stub_weak.a;libScePadTracker_stub_weak.a;libScePad_stub_weak.a;libScePerf_stub_weak.a;libScePhysicsEffects.a;libScePlayerInvitationDialog_stub_weak.a;libScePlayGoDialog_stub_weak.a;libScePlayGo_stub_weak.a;libScePm4Dump.a;libScePngDec_stub_weak.a;libScePngEnc_stub_weak.a;libScePosix_stub_weak.a;libSceRandom_stub_weak.a;libSceRazorCpu_debug_stub_weak.a;libSceRazorCpu_stub_weak.a;libSceRazorGpuThreadTrace_stub_weak.a;libSceRemoteplay_stub_weak.a;libSceRtc_stub_weak.a;libSceRudp_stub_weak.a;libSceS3DConversion_stub_weak.a;libSceSaveDataDialog_stub_weak.a;libSceSaveData_stub_weak.a;libSceScream.a;libSceScreamserver.a;libSceScreenShot_stub_weak.a;libSceSecure.a;libSceSecure_stub.a;libSceSecure_stub_weak.a;libSceSfmt11213.a;libSceSfmt1279.a;libSceSfmt132049.a;libSceSfmt19937.a;libSceSfmt216091.a;libSceSfmt2281.a;libSceSfmt4253.a;libSceSfmt44497.a;libSceSfmt607.a;libSceSfmt86243.a;libSceSha0.a;libSceSha1.a;libSceSha224.a;libSceSha256.a;libSceSha256Fast.a;libSceSha384.a;libSceSha512.a;libSceSha512t.a;libSceShaderBinary.a;libSceSharePlay_stub_weak.a;libSceShareUtility_stub_weak.a;libSceSigninDialog_stub_weak.a;libSceSndstream.a;libSceSocialScreenDialog_stub_weak.a;libSceSocialScreen_stub_weak.a;libSceSpeechRecognition.a;libSceSsl_stub_weak.a;libSceSubdiv.a;libSceSulpha_stub_weak.a;libSceSysmodule_stub_weak.a;libSceSystemGesture_stub_weak.a;libSceSystemService_stub.a;libSceSystemService_stub_weak.a;libSceTexturePrep.a;libSceTextureTool.a;libSceUlt_stub_weak.a;libSceUsbd_stub_weak.a;libSceUserService_stub_weak.a;libSceVdecsw_stub_weak.a;libSceVideodec2_stub_weak.a;libSceVideoOut_stub_weak.a;libSceVideoRecording_stub_weak.a;libSceVoiceQoS_stub_weak.a;libSceVoice_stub_weak.a;libSceVrServiceDialog_stub_weak.a;libSceVrTrackerLiveCapture_stub_weak.a;libSceVrTracker_stub_weak.a;libSceWebBrowserDialog_stub_weak.a;libSceXml_stub_weak.a;libSceZlib_stub_weak.a
一、c++层代码改动(非野2游戏不需要关注)
1、ClientInterface所有关于ps4导出方法全部屏蔽
2、PS4DialogMgr、PS4SDKHelper、SDKMessageHandle需要移除
3、Client->InitModule()屏蔽掉初始化代码
二、c#层代码改动(非野2游戏不需要关注)
1、原有接口 SCENpAuthGetAuthorizationCodeV3()更改为SCENpAuthGetAuthorizationCodeV3(const char* ps4_client_id),游戏不需要调用
2、DllInterfaceMgr中ps4的接口声明全部屏蔽
三、Unity Player配置
1、Modules增加libSceNpCppWebApi.prx ,路径在安装路径下D:\soft\SCE\ORBIS SDKs\9.000\target\sce_module
2、欧区和美区配置不一样,需要出多个包
contentid和nptitle.dat要同时替换
contentid获取位置:content pipeline/产品/
nptitle.dat获取位置:Ps5 devnet/Titles/产品/Credentialfiles/Download NP Title Secret 3、需要放置到Assets/Plugins/PS4/目录下的文件如截图所示: 4、Title Voice Recognition Details 需要安装sdk manager,打开Voice Recognition Title Name Tool,编辑并导出 5、奖杯配置(必须配置,不配置无法打开应用) 工具地址ORBIS\Tools\Publishing Tools\bin\orbis-pub-trp.exe,参照文档制作奖杯配置https://ps4.siedev.net/resources/documents/Misc/current/Trophy_Pack_File_Utility-Users_Guide/__toc.html
四、接口
1、设置平台参数接口
调用类 | DHSDKHelper |
---|---|
接口 | setHostPlatformParam |
参数 | json字符串 json value都为string,key定义如下: DHAppId(产品id) DHChannelId(渠道id) DHInviteCode(邀请码) HostUrl(域名) HostPlatformAppId(clientId) mainChannel (主渠道号) subChannel (次渠道号) |
调用说明 | 在初始化接口调用之前设置平台参数(具体参数可以联系平台技术) |
2、设置回调监听接口
调用类 | DHPSSDK |
---|---|
接口 | setAction |
参数1 | Action<int,IntPtr> 会话操作监听 |
参数2 | Action 登出监听 |
调用说明 | 在初始化接口调用之前调用回调监听接口 |
代码示例:
DHPSSDK.setAction(sessionOperate, onPsSignOut);
private void sessionOperate(int i1, IntPtr ss)
{
//处理游戏逻辑
}
private void onPsSignOut()
{
//处理游戏逻辑
}
3、获取商品信息接口
调用类 | DHSDKHelper |
---|---|
接口 | querySkus |
参数1 | 商品id列表 |
参数2 | 回调,回调的requestCode为DHSDKHelper.DHSDKConst.REQ_SKUS |
调用规则 | 登录成功后可以调用,如果返回失败回调,需要再次请求,直至请求成功才可以支付 |
返回值说明
字段 | 说明 | 备注 |
---|---|---|
skuId | 商品id | 支付接口传参请使用该id |
price | 格式化字符串 | 游戏内展示 |
返回值resultData样例
{"list":[{"skuId":"0221349204424909","price":"1.00USD"},{"skuId":"0263685653759062","price":"1.00USD"}, {"skuId":"8973489394369671","price":"1.00USD"}]}
4、创建房间接口
调用类 | DHSDKHelper |
---|---|
接口 | createLobby |
参数 | jsonString 可使用DHSDKPSCreateLobbyBean类进行构造 |
回调说明 | 回调的requestCode为DHSDKHelper.DHSDKConst.REQ_CREATE_LOBBY 配置邀请图片路径:Assets/StreamingAssets/session_image.jpg,分辨率457x257 |
参数类 | DHSDKPSCreateLobbyBean |
---|---|
参数1 | sessionMaxUser,房间最大人数 |
参数2 | sessionType 房间类型 固定值 DHHostPlatformConst.VALUE_SESSION_TYPE_OWNER_MIGRATION |
参数3 | sessionPrivacy 私有房间或公开房间 取值为“private”或“public” |
回调对象字段 | 类型 | 说明 |
---|---|---|
sessionId | string | 房间会话ID |
创建成功后的返回信息如下:(可以使用JsonUtility.FromJson< DHXboxTeamSessionInfo>(data)反序列化对象)
{"sessionId":"aaa9a701-b2f5-4983-b448-6f3560880ea1"}
5、邀请好友接口
调用类 | DHSDKHelper |
---|---|
接口 | inviteFriend |
调用说明 | 调用前提是玩家已在房间中,调用接口后会自动拉起系统界面,选择要邀请的玩家后发送邀请。 |
6、接受好友邀请回调
回调信息 | 回调的requestCode为DHSDKHelper.DHSDKConst.REQ_RECEIVE_FRIEND_INVITE |
---|---|
回调说明 | 收到该回调说明用户已经接受好友邀请并且已经成功登录游戏,要求收到回调后停止一切行为强制进入好友房间,游戏清理完场景后需要调用joinFriendLobbyByInvited接口进入好友房间,收到进入房间成功回调才算真正进入好友房间。游戏需要控制好UI界面来衔接整个强制进入房间过程 |
7、加入好友邀请的房间
调用类 | DHSDKHelper |
---|---|
接口 | joinFriendLobbyByInvited |
回调说明 | 回调的requestCode为DHSDKHelper.DHSDKConst.REQ_LOBBY_JOINED |
8、离开房间
调用类 | DHSDKHelper |
---|---|
接口 | leaveLobby |
回调说明 | 回调的requestCode为DHSDKHelper.DHSDKConst.REQ_LOBBY_LEAVE |
9、邀请指定好友接口
调用类 | DHSDKHelper |
---|---|
接口 | invitePsFriend |
调用说明 | 调用前提是玩家已在房间中,调用接口后会自动拉起系统界面,默认选择指定玩家后发送邀请。 |
10、其他接口参照基本接口调用接入即可
11、注意事项:
- 客户端支付使用的商品id是获取商品信息接口返回的skuId,在ps后台为ProductId,非EntitlementId
- ps测试机是可以切环境的,setting->Debug Settings->PlayStation Network->NP Environment
- sp-int就是开发测试环境,prod-qa是包体提审之后提审那边用的环境,np是线上环境
- 如果接口返回错误如下{"code":2114564,"message":"User not online"},ps设备查看用户状态应该是离线了 查看profile头像左上角会有X提示,正常是蓝色点在线状态
- webapi不能频繁调用,比如获取邀请信息
- ps寄过来的测试机要先让it网络加白,然后Settings > Debug Settings > Boot Parameters,不能设置Release Check Mode,否则无法远程连接,去设备后台https://ps4.siedev.net/hardware/location/o40198/report/找到对应序列号的设备下载激活文件,参照文档使用host pc方式激活,https://ps4.siedev.net/resources/documents/SDK/10.000/DevKit-Setup_Guide/0005.html,然后如果设备系统版本较低,要更新系统,neighborhood里选中设备右键系统更新,非开发机要选择testkit。
- 切记创建项目不能使用ps4,要在ps5里创建,要创建个Server用来登录校验和服务器使用webapi
- 测不同地区的游戏,主机要设置不同的region,否则无法支付(报错0x817B120C,-2122640884)