이 예제는 "사용자 지정 장치 인터랙션 구현" 예제를 기반으로 합니다. 이 예제를 먼저 검토하십시오. 여기서는 동일한 기능을 사용할 수 있으며, 이와 함께 동일한 인터랙션 그룹의 기본 인터랙션을 사용할 수 있습니다. 이렇게 하려면 기본 인터랙션 객체를 가져오고 동일한 인터랙션 그룹에 대한 지원을 추가해야 합니다.
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()