[OpenXR] XR Interaction Toolkit 2.4.3 / XR Ray Interaction

VR/XR Interaction Toolkit 2024. 1. 4. 01:04
반응형

 
https://youtube.com/playlist?list=PLTFRwWXfOIYBIPKhWi-ZO_ITXqtNuqj6j&si=XhyHS26tNDP6u7CA

XR Interaction Toolkit 2.4.3

XR Interaction Toolkit 2.4.3 OpenXR Oculus

www.youtube.com


멀리 있는 Interactable과 상호작용하는 데 사용되는 Interactor입니다.
이는 이 인터랙터에 대한 현재 유효한 타겟 세트를 업데이트하는 레이 캐스트를 통해 처리됩니다.
 
https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.4/manual/xr-ray-interactor.html

XR Ray Interactor | XR Interaction Toolkit | 2.4.3

XR Ray Interactor Interactor used for interacting with Interactables at a distance. This is handled via ray casts that update the current set of valid targets for this interactor. Property Description Interaction Manager The XRInteractionManager that this

docs.unity3d.com

 
 
새 씬을 만들고 메인 카메라를 제거후 XR Origin을 생성 

 
기본으로 Left / Right Controller에 Ray Interactor가 붙어 있음 
 
프로젝트 창에도 프리팹으로 지원 

 
 
샘플을 보면 여러 인터렉터들을 사용할수 있기 때문에 Left Controller자식으로 붙어 있는 모습 

 
 
Left Controller 에는 다음과 같은 컴포넌트들이 붙어 있음 

 
 
 
우리는 XR Ray Interactor와 XR Interactio Group만 일단 알아볼거기 때문에 
 
Left / Right Controller를 제거후 XR Controller컴포넌트이외 컴포넌트들은 제거 한다 

 
프로젝트 창에서 Ray Interactor를 검색해 Left, Right Controller에 넣어 준다 

 
실행후 결과를 확인 한다 
 

 
 
지난 시간에 사용했던 스시로 테스트 해본다 
 

 
 

 
 


Force Grab강제 잡기는 멀리서 개체와 상호 작용하는 대신 개체를 손으로 이동시킵니다.

 
 

 
 


 

Anchor Control사용자가 조이스틱을 사용하여 부착 앵커 포인트를 이동할 수 있습니다.

 

 


Translate Speed앵커가 변환되는 속도입니다. 앵커 제어가 활성화된 경우에만 사용 및 표시됩니다.

 

 
 


Rotate Reference Frame부착 앵커 포인트를 회전할 때 위쪽 축을 정의하는 선택적 참조 프레임입니다. 설정되지 않은 경우 연결 변환의 로컬 위쪽 축을 기준으로 회전합니다. 앵커 제어가 활성화된 경우에만 사용 및 표시됩니다.

 
 

설정 안했을때

 
 

 

설정했을떄

 


 

Rotation Mode앵커 회전을 제어하는 방법을 지정합니다. 앵커 제어가 활성화된 경우에만 사용 및 표시됩니다.

 

 Rotate Over Time회전 입력이 활성화된 동안 시간에 따른 앵커 회전을 제어하려면 회전 모드를 시간에 따른 회전으로 설정하세요.
 Match Direction회전 모드를 방향 일치로 설정하여 앵커 회전을 2차원 회전 입력 방향과 일치시킵니다.

 

Match Direction

 


 

Rotate Speed앵커가 회전하는 속도입니다. 앵커 제어가 활성화되고 회전 모드가 시간에 따른 회전으로 설정된 경우에만 사용 및 표시됩니다.
Match Direction모드에서는 안보임

 


 
 

Attach TransformInteractable의 연결 지점으로 사용되는 변환입니다.
자동으로 인스턴스화되고 Awake if None으로 설정됩니다.
이를 설정하면 이전 개체가 자동으로 삭제되지 않습니다.

 

비워두면 자동으로 생성됨

 
 
 
설정해본다 

 

 
일단 레이가 나오는 시작지점부터 달라짐 

 
 


 
 

Ray Origin Transform광선 투사의 시작 위치와 방향입니다.
자동으로 인스턴스화되고 Awake if None으로 설정되며 XRBaseInteractor.attachTransform의 포즈로 초기화됩니다.
이를 설정하면 이전 개체가 자동으로 삭제되지 않습니다.
그냥 자동으로 만들어짐

 
생성해서 넣어보자 

 

 
 
 
 


 

Disable Visuals When Blocked In Group이 인터랙터가 상호 작용 그룹의 일부이고
그룹 내 다른 인터랙터의 활성 상호 작용으로 인해 상호 작용할 수 없는 경우 시각적 개체를 비활성화할지 여부입니다.

 
 
 
 


Line TypeThe type of ray cast.
 Straight Line설정된 광선 길이로 장면에 단일 광선 투사를 수행하려면 선 유형을 직선으로 설정합니다.
 Projectile Curve발사체 곡선을 생성하기 위해 발사체의 궤적을 샘플링하려면 선 유형을 발사체 곡선으로 설정합니다.
 Bezier Curve제어점과 끝점을 사용하여 2차 베지어 곡선을 생성하려면 선 유형을 베지어 곡선으로 설정하세요.

 
 

Max Raycast Distance선 유형이 직선인 경우에만 사용 및 표시됩니다. 이 값을 늘리면 선이 더 멀리 도달하게 됩니다.

 
 
 


 
 

 

Reference Frame선 유형이 투영 곡선 또는 베지어 곡선인 경우에만 사용 및 표시됩니다. 
지면과 위쪽을 정의하는 곡선의 참조 프레임입니다. 
시작 시 설정되지 않은 경우 XROrigin.Origin GameObject를 찾으려고 시도하고, 존재하지 않는 경우 기본적으로 글로벌 up 및 원점을 사용합니다.
Velocity선 유형이 발사체 곡선인 경우에만 사용 및 표시됩니다. 발사체의 초기 속도. 이 값을 늘리면 곡선이 더 멀리 도달하게 됩니다.

 

Acceleration선 유형이 발사체 곡선인 경우에만 사용 및 표시됩니다. 참조 프레임에서 발사체의 중력입니다.

 

Additional Flight Time선 유형이 발사체 곡선인 경우에만 사용 및 표시됩니다. 발사체가 조정된 지면에 착륙한 후 추가 비행 시간입니다. 이 값을 늘리면 끝점의 높이가 낮아집니다.

 

Sample Frequency선 유형이 투영 곡선 또는 베지어 곡선인 경우에만 사용 및 표시됩니다. 
Unity가 곡선 경로를 근사화하는 데 사용하는 샘플 포인트 수입니다. 
값이 클수록 광선 투사 수로 인해 성능이 저하되는 대신 더 나은 품질을 얻을 수 있습니다. n 값은 레이 캐스팅을 위해 n - 1개의 선 세그먼트를 생성합니다. 
유효한 값은 항상 2이므로 직선 유형을 사용할 때 이 속성은 사용되지 않습니다.

 
 


 
 
 

 


 
 

Raycast Mask광선 투사 대상을 제한하는 데 사용되는 레이어 마스크입니다.

 
오른손 왼손 레이어 마스크 적용해본다 
 
오른손 

왼손 


 

 
 
마키를 선택하고 

레이어 Test로 변경하고 
 

 
해당 레이어가 아니면 레이가 줄어듬 

 
https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.4/manual/xr-interactor-line-visual.html

XR Interactor Line Visual | XR Interaction Toolkit | 2.4.3

XR Interactor Line Visual Interactor helper object aligns a LineRenderer with the Interactor. Property Description Line Width Controls the width of the line. Width Curve Controls the relative width of the line from start to end. Override Line Origin Contro

docs.unity3d.com

Auto Adjust Line Length유효한 적중이나 선택이 발생하지 않을 때 시간이 지남에 따라 선 길이가 줄어들지 여부를 결정합니다.

 
체크 해제 하면 라인이 안줄어 듬 

 


 
 

Raycast Trigger Interaction레이캐스트를 통한 트리거 충돌체와의 상호 작용 유형입니다.

 
3가지 옵션이 있음 

 
이건 머선 옵션인지 잘 몰겠네...

Is Trigger를 체크 하고

 
Raycast Trigger Interaction을 Collide로 변경하면 

 
감지가 되야 하는거 아닌가?

 
 
레이어도 문제 없고 

 
 

/// <summary>
/// Whether ray cast should include or ignore hits on trigger colliders that are snap volume colliders,
/// even if the ray cast is set to ignore triggers.
/// If you are not using gaze assistance or XR Interactable Snap Volume components, you should set this property
/// to <see cref="QuerySnapVolumeInteraction.Ignore"/> to avoid the performance cost.
/// </summary>
/// <remarks>
/// When set to <see cref="QuerySnapVolumeInteraction.Collide"/> when <see cref="raycastTriggerInteraction"/> is set to ignore trigger colliders
/// (when set to <see cref="QueryTriggerInteraction.Ignore"/> or when set to <see cref="QueryTriggerInteraction.UseGlobal"/>
/// while <see cref="Physics.queriesHitTriggers"/> is <see langword="false"/>),
/// the ray cast query will be modified to include trigger colliders, but then this behavior will ignore any trigger collider
/// hits that are not snap volumes.
/// <br />
/// When set to <see cref="QuerySnapVolumeInteraction.Ignore"/> when <see cref="raycastTriggerInteraction"/> is set to hit trigger colliders
/// (when set to <see cref="QueryTriggerInteraction.Collide"/> or when set to <see cref="QueryTriggerInteraction.UseGlobal"/>
/// while <see cref="Physics.queriesHitTriggers"/> is <see langword="true"/>),
/// this behavior will ignore any trigger collider hits that are snap volumes.
/// </remarks>
/// <seealso cref="raycastTriggerInteraction"/>
/// <seealso cref="XRInteractableSnapVolume.snapCollider"/>

/// <요약>
         /// 레이 캐스트가 스냅 볼륨 충돌체인 트리거 충돌체에 대한 적중을 포함할지 아니면 무시할지 여부,
         /// 레이캐스트가 트리거를 무시하도록 설정된 경우에도 마찬가지입니다.
         /// 응시 지원 또는 XR Interactable Snap Volume 구성 요소를 사용하지 않는 경우 이 속성을 설정해야 합니다.
         /// 성능 비용을 방지하려면 <see cref="QuerySnapVolumeInteraction.Ignore"/>로 설정하세요.
         /// </summary>
         /// <비고>
         /// <see cref="raycastTriggerInteraction"/>이 트리거 충돌자를 무시하도록 설정된 경우 <see cref="QuerySnapVolumeInteraction.Collide"/>로 설정된 경우
         /// (<see cref="QueryTriggerInteraction.Ignore"/>로 설정된 경우 또는 <see cref="QueryTriggerInteraction.UseGlobal"/>로 설정된 경우)
         /// <see cref="Physics.queriesHitTriggers"/>가 <see langword="false"/>인 동안),
         /// 레이캐스트 쿼리는 트리거 충돌체를 포함하도록 수정되지만 이 동작은 모든 트리거 충돌체를 무시합니다.
         /// 스냅 볼륨이 아닌 적중입니다.
         /// <br />
         /// <see cref="raycastTriggerInteraction"/>이 트리거 충돌을 적중하도록 설정된 경우 <see cref="QuerySnapVolumeInteraction.Ignore"/>로 설정된 경우
         /// ( <see cref="QueryTriggerInteraction.Collide"/>로 설정된 경우 또는 <see cref="QueryTriggerInteraction.UseGlobal"/>로 설정된 경우
         /// <see cref="Physics.queriesHitTriggers"/>가 <see langword="true"/>인 동안),
         /// 이 동작은 스냅 볼륨인 트리거 충돌체 적중을 무시합니다.
         /// </비고>
         /// <see also cref="raycastTriggerInteraction"/>
         /// <see also cref="XRInteractableSnapVolume.snapCollider"/>
 
 

 
 
아니 근데 왜 콜라이더를 벗어났는데도 감지를 하는거냐는거지
 

 
어딘가 오프셋이 있나본데
스시도 동일함 
 
띠용...Hit Detection Type이 Sphere Cast였음 ㅋㅋㅋ 하하핳....
 

 
다시 바꾸고 

 
테스트 
오키 잘 동작 하고 

 
 
다시 트리거 테스트 

 

 
진짜 노이해...

 

https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.4/manual/xr-ray-interactor.html

 

 

When set to QuerySnapVolumeInteraction.Collide when raycastTriggerInteraction is set to ignore trigger colliders
(when set to QueryTriggerInteraction.Ignore or when set to QueryTriggerInteraction.UseGlobal
while Physics.queriesHitTriggers is false.
the ray cast query will be modified to include trigger colliders, but then this behavior will ignore any trigger collider
hits that are not snap volumes.
 
raycastTriggerInteraction이 트리거 충돌체를 무시하도록 설정된 경우 QuerySnapVolumeInteraction.Collide로 설정된 경우
(QueryTriggerInteraction.Ignore로 설정된 경우 또는 QueryTriggerInteraction.UseGlobal로 설정된 경우
Physics.queriesHitTriggers는 false입니다.
레이 캐스트 쿼리는 트리거 충돌체를 포함하도록 수정되지만 이 동작은 트리거 충돌체를 무시합니다.
스냅 볼륨이 아닌 적중.
 
 
 
 
Whether ray cast should include or ignore hits on trigger colliders that are snap volume colliders, even if the ray cast is set to ignore triggers.
If you are not using gaze assistance or XR Interactable Snap Volume components, you should set this property QuerySnapVolumeInteraction.Ignore to avoid the performance cost.
 
레이 캐스트가 트리거를 무시하도록 설정된 경우에도 레이 캐스트가 스냅 볼륨 충돌자인 트리거 충돌기의 적중을 포함해야 하는지 아니면 무시해야 하는지 여부입니다.
시선 지원 또는 XR Interactable Snap Volume 구성 요소를 사용하지 않는 경우 성능 비용을 방지하려면 이 속성 QuerySnapVolumeInteraction.Ignore를 설정해야 합니다.
 
 
 
 
When set to QuerySnapVolumeInteraction.Ignore when raycastTriggerInteraction is set to hit trigger colliders
(when set to QueryTriggerInteraction.Collide or when set to QueryTriggerInteraction.UseGlobal while Physics.queriesHitTriggers is true this behavior will ignore any trigger collider hits that are snap volumes.
 
QuerySnapVolumeInteraction.Ignore로 설정된 경우 raycastTriggerInteraction이 트리거 충돌체를 적중하도록 설정된 경우
(QueryTriggerInteraction.Collide로 설정되거나 Physics.queriesHitTriggers가 true인 동안 QueryTriggerInteraction.UseGlobal로 설정된 경우 이 동작은 스냅 볼륨인 모든 트리거 충돌체 적중을 무시합니다.
 
 
아무래도 볼륨이랑 연관이 있는듯 하다 ...


 
 
 
 

Raycast Snap Volume Interaction레이 캐스트가 트리거를 무시하도록 설정된 경우에도 레이 캐스트가 스냅 볼륨 충돌자인 트리거 충돌기의 적중을 포함해야 하는지 아니면 무시해야 하는지 여부입니다. 응시 지원 또는 XR Interactable Snap Volume 구성 요소를 사용하지 않는 경우 성능 비용을 방지하려면 이 속성을 무시로 설정해야 합니다.

 

 
https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.4/manual/xr-interactable-snap-volume.html

XR Interactable Snap Volume | XR Interaction Toolkit | 2.4.3

XR Interactable Snap Volume Component that enables an XR Ray Interactor to visually snap to an associated interactable. This component requires a collider that is a trigger. This behavior automatically registers itself with the XR Interaction Manager to cr

docs.unity3d.com

 
XR Ray Interactor가 연관된 상호작용 가능 항목에 시각적으로 스냅될 수 있도록 하는 구성 요소입니다. 이 구성 요소에는 트리거인 충돌체가 필요합니다. 이 동작은 자동으로 XR Interaction Manager에 등록되어 Snap Collider와 Interactable Object 간의 연결을 생성합니다. 이 구성 요소는 일반적으로 상호 작용 가능 항목의 하위 GameObject에 추가되어야 합니다.
 
Snap Collider
충돌/충돌 시 상호작용 가능 항목과 연결할 트리거 충돌체입니다. 광선은 여기에서 Snap To Collider로 스냅됩니다.

 

Disable Snap Collider When Selected
상호 작용 가능 항목을 선택하거나 선택 취소할 때 Snap Collider를 자동으로 비활성화하거나 활성화합니다.

 
트리거모드에서도 된다 이거고 

 
 
 
 


 

Hit Detection Type레이 캐스트에 사용할 적중 감지 유형입니다.

 

Raycast적중 감지 유형을 Raycast로 설정하여 Physics Raycast를 사용하여 충돌을 감지합니다.
 Sphere CastPhysics Sphere Cast를 사용하여 충돌을 감지하려면 적중 감지 유형을 Sphere Cast로 설정하세요.

 

 
자세히 보면 스피어가 보임 

 
 


 

Hit Closest OnlyUnity가 가장 가까운 Interactable만 상호 작용의 유효한 대상으로 간주하는지 여부입니다. 가장 가까운 Interactable만 호버 이벤트를 수신하도록 하려면 이 옵션을 활성화합니다. 그렇지 않으면 모든 적중 Interactable이 유효한 것으로 간주되고 이 Interactor는 다중 호버링됩니다.

 

 
 


 

Blend Visual Line PointsUnity가 광선 캐스팅에 사용하는 라인 샘플 포인트를 컨트롤러의 현재 포즈와 혼합합니다. 이를 사용하면 라인이 뒤처지지 않고 컨트롤러와 시각적으로 연결된 상태를 유지할 수 있습니다. 컨트롤러가 입력 대기 시간을 줄이기 위해 렌더링하기 전에 직접 추적 입력을 샘플링하도록 구성되면 컨트롤러는 레이 캐스팅에 사용되는 샘플 곡선의 시작점을 기준으로 새로운 위치 또는 회전에 있을 수 있습니다. 값이 false이면 선이 광선 투사 선의 끝을 향해 구부러지거나 휘어지는 대신 고정 참조 프레임에 시각적으로 유지됩니다.

 
 
Unity가 광선 캐스팅에 사용하는 라인 샘플 포인트를 컨트롤러의 현재 포즈와 혼합합니다. 
 
이를 사용하면 라인이 뒤처지지 않고 컨트롤러와 시각적으로 연결된 상태를 유지할 수 있습니다. 
 
컨트롤러가 입력 대기 시간을 줄이기 위해 렌더링하기 전에 직접 추적 입력을 샘플링하도록 구성되면 컨트롤러는 레이 캐스팅에 사용되는 샘플 곡선의 시작점을 기준으로 새로운 위치 또는 회전에 있을 수 있습니다. 
 
값이 false이면 선이 광선 투사 선의 끝을 향해 구부러지거나 휘어지는 대신 고정 참조 프레임에 시각적으로 유지됩니다.
 
 

 
 


Select Action TriggerUnity가 컨트롤러의 입력 동작 선택을 해석하는 방법을 선택합니다. 버튼이 현재 눌려져 있는지 또는 활성 상태를 토글하는지 여부와 같이 이 인터랙터가 선택할 수 있는지 여부를 결정하기 위해 다양한 입력 스타일을 제어합니다. 이것이 상태로 설정되고 여러 상호작용자가 InteractableSelectMode.Single로 설정된 상호작용 가능 항목을 선택하면 상호작용 가능 항목 선택이 매 프레임마다 상호작용자 간에 앞뒤로 전달되는 바람직하지 않은 동작이 발생할 수 있습니다. 이로 인해 선택 상호 작용 이벤트가 각 프레임을 실행하게 될 수도 있습니다. 이는 기본 권장 옵션인 State Change로 설정하여 해결할 수 있습니다.

 

StateUnity는 버튼을 누르고 있는 동안 입력이 활성화된 것으로 간주합니다. 사용자는 상호 작용이 가능해지기 전에 버튼을 누르고 있을 수 있으며 가능할 때 상호 작용을 계속 트리거할 수 있습니다.
 State ChangeUnity는 버튼을 누른 프레임에서만 입력이 활성화된 것으로 간주하고 성공하면 입력이 해제될 때까지 계속 연결된 상태를 유지합니다. 사용자는 상호작용이 가능한 동안 버튼을 눌러야 상호작용이 실행됩니다. 상호작용이 가능해지기 전에 버튼을 누르기 시작하면 상호작용이 실행되지 않습니다.
 Toggle상호 작용은 입력을 누른 프레임에서 시작되고 입력을 두 번째로 누를 때까지 계속 사용됩니다.
 Sticky상호 작용은 입력이 눌려진 프레임에서 시작되고 두 번째 입력이 해제될 때까지 계속 사용됩니다.

 

 
Unity가 컨트롤러의 입력 동작 선택을 해석하는 방법을 선택합니다. 
 
버튼이 현재 눌려져 있는지 또는 활성 상태를 토글하는지 여부와 같이 이 인터랙터가 선택할 수 있는지 여부를 결정하기 위해 다양한 입력 스타일을 제어합니다. 
 
이것이 State로 설정되고 여러 Interactor가 InteractableSelectMode.Single로 설정된 상호작용 가능 항목을 선택하면 상호작용 가능 항목 선택이 매 프레임마다 상호작용자 간에 앞뒤로 전달되는 바람직하지 않은 동작이 발생할 수 있습니다. 
 
이로 인해 선택 상호 작용 이벤트가 각 프레임을 실행하게 될 수도 있습니다. 
 
이는 기본 권장 옵션인 State Change로 설정하여 해결할 수 있습니다.
 
 
 
이걸 테스트 해보기는 쉽지 않겠는걸...


 
이건 이전시간에 테스트 해봤음 텔레포트 할때 잡고 있을거냐 놓을거냐 이거임 

Keep Selected Target Valid더 이상 유효한 대상이 아닌 경우에도 상호작용 가능 항목을 처음 선택한 후 계속 선택할지 여부입니다. Interactable이 유효한 대상 목록에 포함되지 않은 경우에도 XRInteractionManager가 선택을 유지하도록 하려면 활성화합니다. 유효한 대상 목록에 없는 경우 상호 작용 관리자가 선택 항목을 지우도록 하려면 비활성화합니다. 이를 비활성화하는 일반적인 용도는 순간 이동에 사용되는 Ray Interactor가 현재 가리키고 있지 않을 때 순간 이동 Interactable을 더 이상 선택하지 않도록 만드는 것입니다.

 


 
 

Hide Controller On Select이 인터랙터가 선택 시 컨트롤러 모델을 숨겨야 하는지 여부를 제어합니다.

뭐지요?
 
안숨겨 지는디요?
 
 

 
이것 때문인가요?

 
 

 
네 맞습니다요 

 

 


Allow Hovered Activate현재 선택 항목이 없을 때 이 인터랙터를 마우스로 가리키지만 선택되지 않은 상호 작용 가능 항목에 활성화 및 비활성화 이벤트를 보낼지 여부를 제어합니다. 

기본적으로 인터랙터는 선택한 인터랙티브 개체에만 활성화 및 비활성화 이벤트를 보냅니다.

 

 
 
인터랙터는 선택한 인터랙티브 개체에만 활성화 및 비활성화 이벤트를 보냅니다.
 
By default, the interactor will only send activate and deactivate events to interactables that it's selected.
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;

public class Maki : XRGrabInteractable
{
    protected override void OnActivated(ActivateEventArgs args)
    {
        Debug.LogFormat("OnActivated: {0}", args.interactorObject);
        base.OnActivated(args);
    }

    protected override void OnDeactivated(DeactivateEventArgs args)
    {
        Debug.LogFormat("OnDeactivated: {0}", args.interactorObject);
        base.OnDeactivated(args);
    }
}

 

https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.4/api/UnityEngine.XR.Interaction.Toolkit.XRBaseInteractable.html

 
 
XRBaseControllerInteractor는 Interactor가 이 Interactable에서 활성화 이벤트를 시작할 때 이 메서드를 호출합니다.
 
활성화/비활성화 이벤트?

 

   /// <summary>
        /// <see cref="XRBaseControllerInteractor"/> calls this method when the
        /// Interactor begins an activation event on this Interactable.
        /// </summary>
        /// <param name="args">Event data containing the Interactor that is sending the activate event.</param>
        /// <remarks>
        /// <paramref name="args"/> is only valid during this method call, do not hold a reference to it.
        /// </remarks>
        /// <seealso cref="OnDeactivated"/>
        protected virtual void OnActivated(ActivateEventArgs args)
        {
            m_Activated?.Invoke(args);

#pragma warning disable 618 // Calling deprecated method to help with backwards compatibility with existing user code.
            OnActivate(args.interactor);
#pragma warning restore 618
        }

        /// <summary>
        /// <see cref="XRBaseControllerInteractor"/> calls this method when the
        /// Interactor ends an activation event on this Interactable.
        /// </summary>
        /// <param name="args">Event data containing the Interactor that is sending the deactivate event.</param>
        /// <remarks>
        /// <paramref name="args"/> is only valid during this method call, do not hold a reference to it.
        /// </remarks>
        /// <seealso cref="OnActivated"/>
        protected virtual void OnDeactivated(DeactivateEventArgs args)
        {
            m_Deactivated?.Invoke(args);

#pragma warning disable 618 // Calling deprecated method to help with backwards compatibility with existing user code.
            OnDeactivate(args.interactor);
#pragma warning restore 618
        }

 
XRBaseControllerInteractor calls this method when the Interactor begins an activation event on this Interactable.

 
 
https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.0/manual/interactable-events.html

Interactable Events | XR Interaction Toolkit | 2.0.4

Interactable Events These are events that can be hooked into in the editor the same way you would respond to a UI button press. These apply to Interactables - objects that Interactors can interact with. Property Description First Hover Entered The event th

docs.unity3d.com

 

ActivatedThe event that is called when the selecting Interactor activates this Interactable.
Not to be confused with activating or deactivating a GameObject with GameObject.SetActive. This is a generic event when an Interactor wants to activate an Interactable, such as from a trigger pull on a controller.
The ActivateEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
DeactivatedThe event that is called when an Interactor deactivates this Interactable.
Not to be confused with activating or deactivating a GameObject with GameObject.SetActive. This is a generic event when an Interactor wants to deactivate an Interactable, such as from a trigger release on a controller.
The DeactivateEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.

 
Activated
 
The event that is called when the selecting Interactor activates this Interactable. Not to be confused with activating or deactivating a GameObject with GameObject.SetActive. This is a generic event when an Interactor wants to activate an Interactable, such as from a trigger pull on a controller. The ActivateEventArgs passed to each listener is only valid while the event is invoked, do not hold a reference to it.
 
Interactable을 활성화할 때?
 

 

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;

public class Maki : XRGrabInteractable
{
    protected override void OnSelectEntering(SelectEnterEventArgs args)
    {
        Debug.LogFormat("<color=yellow>OnSelectEntering</color>");
        base.OnSelectEntering(args);
    }

    protected override void OnSelectEntered(SelectEnterEventArgs args)
    {
        Debug.LogFormat("<color=yellow>OnSelectEntered</color>");
        base.OnSelectEntered(args);
    }

    protected override void OnActivated(ActivateEventArgs args)
    {
        Debug.LogFormat("<color=lime>OnActivated</color>");
        base.OnActivated(args);
    }

    protected override void OnHoverEntering(HoverEnterEventArgs args)
    {
        Debug.LogFormat("<color=yellow>OnHoverEntering</color>");
        base.OnHoverEntering(args);
    }

    protected override void OnHoverEntered(HoverEnterEventArgs args)
    {
        Debug.LogFormat("<color=yellow>OnHoverEntered</color>");
        base.OnHoverEntered(args);
    }
}

 
 
왜 OnActivated만 호출이 안되는거지?
 

 
 
Send activate and deactivate events to interactables that this interactor is hovered over
이 인터랙터 위에 마우스를 올려놓은 상호작용 가능 항목에 활성화 및 비활성화 이벤트를 보냅니다.
 
but not selected when there is no current selection 
하지만 현재 선택 항목이 없으면 선택되지 않습니다.

https://forum.unity.com/threads/xr-simple-interaction-activate.1154033/

 

아..
 
핸드 트리거로 잡고 인덱스 트리거 땡기면 호출 되는구만..
 
For the Activate events on the Interactable (Activated/Deactivated), the object must be selected first. So if you pick up an object by selecting it with the grip, and then pull the trigger to activate, it will fire the Activated event. This is for something like a flashlight that you can pick up and then use the trigger to toggle the light.
 
grip : 핸드 트리거 
trigger  : 인덱스 트리거 
 
용어 헷갈리네 Oculus SDK 하다 와서 ㅋㅋ


 
일단 속성은 여기 까지 파고 실습 예제 만들기 
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;

public class Flashlight : MonoBehaviour
{
    public Material material; // 렌더러의 메터리얼
    public GameObject light;

    private bool isOn = false;
    public void Activated(ActivateEventArgs args)
    {
        Debug.LogFormat("Activated: {0}", args.interactorObject);
        this.isOn = !isOn;

        if (isOn)
        {
            this.ActivateEmission();
            this.light.SetActive(true);
        }
        else
        {
            DeactivateEmission();
            this.light.SetActive(false);
        }
    }

    public void Deactivated(DeactivateEventArgs args)
    {
        // Debug.LogFormat("Deactivated: {0}", args.interactorObject);
        // DeactivateEmission();
        // this.light.SetActive(false);
    }
    // Emission을 활성화하는 함수
    public void ActivateEmission()
    {
        if (material != null)
        {
            material.EnableKeyword("_EMISSION");
            material.SetColor("_EmissionColor", Color.yellow); // 원하는 색상으로 설정 가능
        }
    }

    // Emission을 비활성화하는 함수
    public void DeactivateEmission()
    {
        if (material != null)
        {
            material.DisableKeyword("_EMISSION");
        }
    }
}

 


 
연관 
https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.4/manual/xr-interaction-group.html
 
 
 

반응형
: