Search Unity

Question Extending SocketInteractor To Consider the Orientation of Interactable

Discussion in 'XR Interaction Toolkit and Input' started by slippyfrog, Sep 9, 2021.

  1. slippyfrog

    slippyfrog

    Joined:
    Jan 18, 2016
    Posts:
    42
    Hey all,

    I hope whomever reads this is doing well!

    I am trying to build a DirectionalSocketInteractor by extending the XRSocketInterator.

    The desired behavior is as such:
    • The Interactable is only accepted by the socket if the Socket and the Interactable have forward vectors that are nearly parallel
    • When the socket can accept the interactable, the socket renders using the HoverMeshMaterial
    • When the interactable is not accepted, the socket renders using the CantHoverMeshMaterial
      • More specifically, if the interactable is within proximity of the socket, and their forward-vectors are not nearly parallel, then the the socket will render with CantHoverMeshMaterial
    I've tried two approaches:
    1. Extending the XRSocketInteractor class
    2. Copying the XRSocketInteractor class as a boiler plate and then modifying the code to support the desired functionality.

    The implementation should be quite simple but...The issue:
    • XRSocketInteractor is not implemented to be extensible. Solution #1 can be sort of implemented but it is quite a nasty hack.
    • Pulling XRSocketInteractor code and then modifying would work but there are many package protected references to other classes, or static functions that would require hackish-reflection invocations to work around.
    In either case, this should be a simple solution but XRSocketInteractor doesn't seem to be very permissive in extensibility.

    My questions:
    Is there a recommended way of implementing this behavior on top of XRSocketInteractor? or would I it be best to not use XRSocketInteractor and just build something from the ground up (but still ontop of XRI)?

    Thanks!!
     
  2. DejaMooGames

    DejaMooGames

    Joined:
    Apr 1, 2019
    Posts:
    108
    Correct me if I am wrong, but the only thing you would need to change in the socket interactor to get the selection behaviour would be overriding the GetValidTargets method and adding your code to strip misaligned interactables.

    Code (CSharp):
    1. public class DirectionalSocketInteractor: XRSocketInteractor
    2. {
    3.      //necessary fields for detecting alignment
    4.  
    5.     public override void GetValidTargets(List<XRBaseInteractable> targets)
    6.     {
    7.         RemoveMisalignedTargets(targets);
    8.         base.GetValidTargets(targets);
    9.     }
    10.  
    11.     public void RemoveMisalignedTargets(List<XRBaseInteractable> targets)
    12.     {
    13.         //your code
    14.     }
    15. }
    You would need to override CanHover, DrawHoveredInteractables for the mesh drawing behavior, but those are perfectly extensible.
     
  3. slippyfrog

    slippyfrog

    Joined:
    Jan 18, 2016
    Posts:
    42
    Hi Joshua, Thanks for the rely here. I ended up writing my own Directional Socket class but that looks super simple -- I'll give that a shot to see which hits my requirements better.
     
  4. DejaMooGames

    DejaMooGames

    Joined:
    Apr 1, 2019
    Posts:
    108
    For sure, I hope you get the behavior you want without too much hassle.
     
    slippyfrog likes this.