适用于svr SDK APP开发的controller插件
controller插件框架,unity使用的是controller插件,controller.cs脚本应用可以根据自己情况进行调整实现。controller plugin这一部分使用java代码实现,以aar库的形式存在于controller插件中。AIDLControllerService和ControllerService是以common service方式存在,代码打包在GvrLctService.apk中,此代码会编译到系统system.img中。controller.cs 和controller plugin在app进程中运行,AIDLcontrollerService和ControllerService运行在com.google.vr.vrcore进程中。
controller支持大多数daydream app的手柄行为 。 实现上主要采用与daydream手柄service同名的controllerservice实现。Daydream app可以bind到针对手柄实现的ConrollerServices. 使用daydream sdk约定的listener(IControllerListener)进行通信。如图:
在设计AirMouse的操作实现的时候,通过对google controller service进行一层封装。应用通过调用AIDL controller service来对controller service进行操作。由于google/vr/vrcore/controller实现的方式是通过打包到system/priv-app/GvrLctService中,因此这里需要进行CS通信,这里使用的是LocalBroadcastManager的方式,进行通信。
发送方:
import android.support.v4.content.LocalBroadcastManager;
LocalBroadcastManager localBroadcastManager;
public void onCreate(){
super.onCreate();
localBroadcastManager = LocalBroadcastManager.getInstance(this);
......
@Override
public void updateAirMouseControllerState(boolean enable){
Log.d(TAG,"UpdateAirMouseControllerState"+" enable = "+enable);
mAirMouseControllerState = enable;
Intent intent = new Intent();
intent.putExtra("enable", enable);
intent.setAction("FREEZE_HAND_DEVICES");
localBroadcastManager.sendBroadcast(intent);
}
接收方:
import android.support.v4.content.LocalBroadcastManager;
private LocalBroadcastManager localBroadcastManager;
@Override
public void onCreate() {
super.onCreate();
localBroadcastManager = LocalBroadcastManager.getInstance(this);
IntentFilter filter = new IntentFilter();
filter.addAction("FREEZE_HAND_DEVICES");
localBroadcastManager.registerReceiver(eventReceiver,filter);
}
public class EventReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if("OPEN_VIBRATOR_ACTION".equals(action)) {
controlJoystickVibrate(3, 5);
}else if("OPEN_VIBRATOR_TIME_ACTION".equals(action)) {
long time = intent.getLongExtra("time", -1);
controlJoystickVibrate(3, (int)time);
......
}else if("FREEZE_HAND_DEVICES".equals(action)){
boolean status = intent.getBooleanExtra("enable", false);
mFreezeAirMouseDayDream = status;
}
}
}
......
这里的成员变量是手柄在2d和3d场景下切换的控制flag
// add: Freeze DayDream hand devices activity when enable 2D dialog
boolean mFreezeAirMouseDayDream = false;