此示例基于“实现自定义设备交互”示例,应先查看它。此处,除了使用同一交互组中的默认交互外,还提供相同功能。这是通过获取默认交互对象并添加对同一交互组的支持实现的。
teleport = vrDeviceService.getInteraction("Teleport")
teleport.addSupportedInteractionGroup("CustomGroup")
此外,还重映射传送的操作。在此示例中,使用自定义触发器,这是支持接触和非接触事件的扩展触发器。
teleport.setControllerActionMapping("prepare", "right-customtrigger-touched")
teleport.setControllerActionMapping("abort", "right-customtrigger-untouched")
teleport.setControllerActionMapping("execute", "right-customtrigger-pressed")
除了左侧控制器触发的输出外,还可以使用触发器与右侧控制器进行传送。
# Define actions as python functions
class ExampleInteraction:
def __init__(self):
self.active = False
# Create new interaction
self.customInteraction = vrDeviceService.createInteraction("CustomInteraction")
# Limit the interaction to a new mode to not interfere with other interactions
self.customInteraction.setSupportedInteractionGroups(["CustomGroup"])
# Create action objects that a triggered by some input
self.pressed = self.customInteraction.createControllerAction("left-trigger-pressed")
self.released = self.customInteraction.createControllerAction("left-trigger-released")
# Connect these actions to the actual python functions
self.pressed.signal().triggered.connect(self.pressMethod)
self.released.signal().triggered.connect(self.releaseMethod)
# Get the teleport interaction and add the interaction group
teleport = vrDeviceService.getInteraction("Teleport")
teleport.addSupportedInteractionGroup("CustomGroup")
teleport.setControllerActionMapping("prepare", "right-customtrigger-touched")
teleport.setControllerActionMapping("abort", "right-customtrigger-untouched")
teleport.setControllerActionMapping("execute", "right-customtrigger-pressed")
# Activate the mode that supports the new interaction
vrDeviceService.setActiveInteractionGroup("CustomGroup")
def pressMethod(self, action, device):
print("Press")
self.active = True
device.signal().moved.connect(self.moveMethod)
def releaseMethod(self, action, device):
print("Release")
self.active = False
device.signal().moved.disconnect(self.moveMethod)
def moveMethod(self, device):
print("Move")
interaction = ExampleInteraction()