需注意:初始化unity的context必须是activity类型的context.
1.build.gradle配置
`aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb', '.bundle', '.unityexp'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"`
}
xxxxxxxxxx
packagingOptions {
doNotStrip '*/armeabi-v7a/*.so'
doNotStrip '*/arm64-v8a/*.so'
}
defaultConfig {中添加
xxxxxxxxxx
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
application添加 tools:replace="android:theme"
xxxxxxxxxx
ndk.dir=ndk路径
xxxxxxxxxx
org.gradle.parallel=true
unityStreamingAssets=
unityTemplateVersion=3
android.useAndroidX=true
org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED
xxxxxxxxxx
UnityLibrary.getInstance().init(this);
xxxxxxxxxx
UnityLibrary.getInstance().setOnInitListener(new OnInitListener() {
@Override
public void success() {
LogUtil.e(TAG,"success ++++++");
}
//预留
@Override
public void onRestart() {}
@Override
public void onResume() {}
@Override
public void onPause() {}
@Override
public void onStop() {}
@Override
public void onDestroy() {}
@Override
public void fail() {}
});
xTextTureView layout = findViewById(R.id.ff1);
private Surface mSurface;
layout.setOpaque(false);
layout.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surfaceTexture, int i, int i1) {
LogUtil.e(TAG,"onSurfaceTextureAvailable");
mSurface = new Surface(surfaceTexture);
//添加Surface
UnityLibrary.getInstance().setSurface(mSurface,"init");
//初始化必须传入形象大小,具体参数解释在文档末尾
UnityLibrary.getInstance().sendAction(new UnityConstants(UnityConstants.SELECT_CHARACTER,UnityConstants.S_MODEL));
}
@Override
public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surfaceTexture, int i, int i1) {
}
@Override
public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surfaceTexture) {
LogUtil.e(TAG,"onSurfaceTextureDestroyed");
UnityLibrary.getInstance().setSurface(null, "自定义");
mSurface.release();
mSurface = null;
return false;
}
@Override
public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surfaceTexture) {
}
});
xxxxxxxxxx
//必须实现
@Override
protected void onPause() {
super.onPause();
LogUtil.e(TAG,"--------------------onPause");
UnityLibrary.getInstance().setSurface(null, "自定义");
}
@Override
protected void onResume() {
super.onResume();
LogUtil.e(TAG,"--------------------onResume");
UnityLibrary.getInstance().setSurface(mSurface, "自定义");
}
@Override
protected void onDestroy() {
super.onDestroy();
LogUtil.e(TAG,"--------------------onDestroy");
UnityLibrary.getInstance().onDestroy();
}
//可选部分
@Override
public boolean onTouchEvent(MotionEvent event) {
return UnityLibrary.getInstance().onTouchEvent(event);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return UnityLibrary.getInstance().onKeyDown(keyCode,event);
}
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
return UnityLibrary.getInstance().onGenericMotionEvent(event);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
return UnityLibrary.getInstance().dispatchKeyEvent(event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return UnityLibrary.getInstance().onKeyUp(keyCode, event);
}
xxxxxxxxxx
UnityConstants unityConstants = new UnityConstants();
unityConstants.setService(UnityConstants.SELECT_CHARACTER);
unityConstants.setValue(UnityConstants.S_MODEL);
UnityLibrary.getInstance().sendAction(unityConstants);
xxxxxxxxxx
UnityLibrary.getInstance().sendAction(unityConstants);
名称 | 类型 | 备注 |
---|---|---|
service | string | 方法名 |
value | string | 单独值 |
service开放方法说明:
名称 | 类型 | 备注 |
---|---|---|
UnityConstants.PLAY_ACTION | string | 调用unity动作方法 |
UnityConstants.SELECT_CHARACTER | string | 调用unity切换大小形象 |
value开放方法说明:
名称 | 类型 | 备注 | 对应Service |
---|---|---|---|
UnityConstants.S_MODEL | string | 小形象 | 切换形象 |
UnityConstants.B_MODEL | 大形象 | 切换形象 | |
UnityConstants.A001 | 待机(默认,不对外开放,无需调用) | 动作 | |
UnityConstants.A002 | 开心 | 动作 | |
UnityConstants.A003 | 难为情 | 动作 | |
UnityConstants.A004 | 询问 | 动作 | |
UnityConstants.A005 | 生气 | 动作 | |
UnityConstants.A006 | 喜欢兴奋 | 动作 |
本协议文档主要是针对赛道模式项目中,赛道模式对外提供功能所制定的协议。通过此文档阅读,帮助大家更方便、更快速的了解赛道模式和熟悉对接
赛道模式专为追求极限驾驶体验的玩家设计。利用Unity引擎的强大功能,我们精心打造了一个充满惊喜的赛道,让玩家在未来城市场景中高速驰骋感受心跳加速的快感。游戏不仅注重画面的精美与流畅,更在物理模拟、车辆真实感,场景精美程度上下足功夫,力求为玩家带来最真实、最震撼的体验
UnityView unityView = UnityLib.getInstance().init(context);
xxxxxxxxxx
view.addView(unityView);
xxxxxxxxxx
unityView.onNewIntent(intent);
unityView.onWindowFocusChanged(hasFocus);
unityView.onResume();
unityView.onPause();
unityView.onDestroy();
xxxxxxxxxx
UnityReiveInfo unityReiveInfo = new UnityReiveInfo();
unityReiveInfo.setOnRenderListener(new OnRenderListener() {
@Override
public void gearProcessingComplete() {
LogUtil.e("Uniyt gearProcessingComplete");
}
});
value1,value2为常量定义在UnityConstants类中,value3为具体数据
xxxxxxxxxx
unityView.unitySendMessage(String value1, String value2, String value3);
xxxxxxxxxx
//设置档位信息
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.GEAR, value);
//设置车速信息
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.CARSPEED,value);
//方向盘转角信息
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.STEERINGWHEELANGLE,value);
//能量条信息
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.POWERDIAL,value);
//加速踏板信息
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.THROTTLEOPENING,value);
//加速度信息
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.ACCELERATION,value);
//远光灯信息
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.SET_OPEN_CAR_BIG_LIGHT,value);
//近光灯信息
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.SET_OPEN_LOW_BEAM_LIGHT,value);
//刹车灯信息
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.THEBRAKE,value);
//左转向灯 1开 0关
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.ZuoZhuanXiang,value);
//右转向灯 1开 0关
UnityView.getInstance(context).unitySendMessage(UnityConstants.TRACKMETHOD, UnityConstants.YouZhuanXiang,value);
//车辆换肤 0,1,2
unityView.unitySendMessage(UnityConstants.SET_CAR_COLOR, value);
//氮气音效开关 1关,0开
unityView.unitySendMessage(UnityConstants.SOUND_CONTROL, value);
[展播3D桌面]Unity3d Android 集成文档(240903更新)1.3D桌面简介2.兼容性说明3.SDK集成包目录结构4.SDK工程配置开始集成 SDK(aar)5.配置权限6.接口流程图7.SDK使用7.1 初始化示例如下:7.2 开始渲染7.3传递触摸及滑动事件7.4应用发生变化时通知unity7.5发送车模控制命令(字段详见类说明)7.6停止渲染7.7销毁释放内存8.类说明:(1)ZBUnityPlayer开放的接口类(2)UnityConstants动作常量类(3)AttributesBean动作数据类1.ZBUnityPlayer API2.UnityConstants常量说明3.AttributesBean结构
模拟车模与车辆信号进行实时交互及与车辆系统数据的实时联动。用户可通过触摸屏幕实现车模的任意角度旋转与缩放,通过操作实现控制实车的车门、车窗等各项操作。
类别 | 兼容范围 |
---|---|
系统 | 支持armv7和armv8架构,兼容android 8.0及以上版本(示例中只提供armv8) |
开发环境 | 建议使用Android Studio 进行开发 |
将SDK zip包解压缩,得到如下文件:
├── Demo UnityDesktopDemo的使用Demo,Demo中已经集成了SDK,您可以参考DEMO,集成SDK。集成前,请先测通Demo,了解调用原理。
├── ReleaseNotes.txt SDK版本日志
├── SDK UnityDesktop SDK
│ └── UnityDesktop.aar
└── UnityDesktop 3D桌面 Android SDK集成文档.pdf
复制UnityDesktop.aar将其导⼊到您当前的⼯程项目的libs目录下, 然后在主Module的build.gradle文件中,增加如下配置:
repositories {
flatDir { dirs 'libs' }
}
implementation(name:'UnityDesktop', ext:'aar')
1.在gradle.properties ⽂件中添加
xxxxxxxxxx
org.gradle.jvmargs=-Xmx4096M
org.gradle.parallel=true
unityStreamingAssets=.json
unityTemplateVersion=3
2.在模块的build.gradle添加如下配置
xandroid {
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb', '.bundle', '.unityexp'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
packagingOptions {
doNotStrip '*/arm64-v8a/*.so'
}
}
暂不需要权限配置
在使用3D桌面功能前,需通过构造方法ZBUnityPlayer()方法构建其实例,然后用该实例调用相应的方法来控制渲染及播放动画. 注意:此示例sdk只支持传入Activity的上下文.
xxxxxxxxxx
ZBUnityPlayer zbUnityPlayer =new ZBUnityPlayer(context);
xxxxxxxxxx
zbUnityPlayer.setView(ViewGroup);
xxxxxxxxxx
@Override
public boolean onTouchEvent(MotionEvent event) {
return zbUnityPlayer.onTouchEvent(event);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return zbUnityPlayer.onKeyDown(keyCode, event);
}
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
return zbUnityPlayer.onGenericMotionEvent(event);
}
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
return zbUnityPlayer.dispatchGenericMotionEvent(event);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
return zbUnityPlayer.dispatchKeyEvent(event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return zbUnityPlayer.onKeyUp(keyCode, event);
}
xxxxxxxxxx
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
zbUnityPlayer.onConfigurationChanged(newConfig);
}
@Override
protected void onNewIntent(Intent intent) {
zbUnityPlayer.onNewIntent(intent);
super.onNewIntent(intent);
}
xxxxxxxxxx
zbUnityPlayer.sendAction(new AttributesBean(UnityConstants.ID_DOOR, 0));
xxxxxxxxxx
zbUnityPlayer.removeView(ViewGroup);
xxxxxxxxxx
zbUnityPlayer.destroy();
返回值类型 | 方法说明 | 必须 | |
---|---|---|---|
void | public void setView(ViewGroup view) | 开启渲染 | √ |
void | public void sendAction(AttributesBean auttributesBean) | 控制车模动作 | |
boolean | public void onTouchEvent(MotionEvent event) | 传递touch事件 | |
boolean | public void onKeyDown(int keyCode, KeyEvent event) | 传递onKeyDown事件 | |
boolean | public void onGenericMotionEvent(MotionEvent event) | 传递onGenericMotionEvent事件 | |
boolean | public void onKeyUp(int keyCode, KeyEvent event) | 传递onKeyUp事件 | |
boolean | public void dispatchGenericMotionEvent(MotionEvent event) | 传递dispatchGenericMotionEvent事件 | |
boolean | public void dispatchKeyEvent(KeyEvent event) | 传递dispatchKeyEvent事件 | |
void | public void onConfigurationChanged(Configuration var1) | 传递onConfigurationChanged事件 | |
void | public void onNewIntent(Intent var1) | 传递onNewIntent事件 | |
void | public void removeView(ViewGroup view) | 停止渲染 | √ |
void | public void destroy() | 销毁释放内存 | √ |
使用示例可以参考Demo.
动作名称 | 类型 | 动作含义 | 备注 |
---|---|---|---|
ID_DOOR | String | 控制车门 | |
ID_TRUNK | String | 控制后备箱 |
字段名称 | 参数 | 类型 | 含义 |
---|---|---|---|
attributesId | 传入对应的UnityConstants常量 | String | 动作ID字段 |
progress | (0-1)数字支持到小数点后一位 | double | 数值 |
双人健身游戏是一种结合了运动与娱乐的健身方式,不仅能够提升身体素质,还能增进人与人之间的情感交流和互动
将arr包导入到项目中,然后对SDK进行初始化
ZBUnityPlayer zbUnityPlayer = new ZBUnityPlayer(this);
对游戏进行参数设置,value1具体参数详见2.3参数列表
xxxxxxxxxx
zbUnityPlayer.unitySendMessage(String value1);
说明 | 参数 |
---|---|
蓝牙通话开始 | UnityConstants.BTPhoneStart |
蓝牙通话结束 | UnityConstants.BTPhoneEnd |
主驾驶右移动 | UnityConstants.OnFaceRightDirMain |
主驾驶左移动 | UnityConstants.OnFaceLeftDirMain |
副驾驶右移动 | UnityConstants.OnRightDir |
副驾驶左移动 | UnityConstants.OnFaceLeftDir |
主驾驶运动 | UnityConstants.OnFaceSwingMain |
副驾驶运动 | UnityConstants.OnFaceSwing |
声音暂停 | UnityConstants.OnSoundPause |
声音恢复 | UnityConstants.OnSoundPlay |
xxxxxxxxxx
@Override
protected void onPause() {
super.onPause();
zbUnityPlayer.removeView(layout);
}
@Override
protected void onResume() {
super.onResume();
zbUnityPlayer.setView(layout);
}
@Override
protected void onDestroy() {
super.onDestroy();
zbUnityPlayer.destroy();
}