private HandBonesTransformations CreateHandTransformations(
        OvrAvatarPhysicsHandTypes.HandType type,
        GameObject ovrAvatarComponent)
    {
        HandBonesTransformations transformations = new HandBonesTransformations();

        if (type == OvrAvatarPhysicsHandTypes.HandType.Left)
        {
            transformations.handBegin        = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetLeftHandBeginName());
            transformations.grip             = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetLeftHandGripName());
            transformations.indexFingerBegin = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetLeftHandIndexFingerBeginName());
            transformations.indexFingerEnd   = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetLeftHandIndexFingerEndName());
            transformations.thumbFingerBegin = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetLeftHandThumbFingerBeginName());
            transformations.thumbFingerEnd   = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetLeftHandThumbFingerEndName());
        }
        else if (type == OvrAvatarPhysicsHandTypes.HandType.Right)
        {
            transformations.handBegin        = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetRightHandBeginName());
            transformations.grip             = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetRightHandGripName());
            transformations.indexFingerBegin = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetRightHandIndexFingerBeginName());
            transformations.indexFingerEnd   = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetRightHandIndexFingerEndName());
            transformations.thumbFingerBegin = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetRightHandThumbFingerBeginName());
            transformations.thumbFingerEnd   = ovrAvatarComponent.transform.Find(OvrAvatarPhysicsHandNames.GetRightHandThumbFingerEndName());
        }

        return(transformations);
    }
    public void AddPhysicsComponent(GameObject ovrAvatarComponent,
                                    OvrAvatarPhysicsHandTypes.HandType type)
    {
        var builder = new OvrAvatarPhysicsHandBuilder();
        var hand    = builder.Build(ovrAvatarComponent, type);

        if (type == OvrAvatarPhysicsHandTypes.HandType.Left)
        {
            leftHand = hand;
        }
        else if (type == OvrAvatarPhysicsHandTypes.HandType.Right)
        {
            rightHand = hand;
        }
    }
    public OvrAvatarPhysicsHand Build(
        GameObject ovrAvatarComponent,
        OvrAvatarPhysicsHandTypes.HandType type)
    {
        Debug.Log("AddPhysicsComponent: " + ovrAvatarComponent.name);

        var handGameObject = new GameObject();
        var hand           = handGameObject.AddComponent <OvrAvatarPhysicsHand>();

        handGameObject.name = ovrAvatarComponent.name + "_physics";
        handGameObject.transform.SetParent(ovrAvatarComponent.transform);
        handGameObject.transform.localPosition = new Vector3(0, 0, 0);

        BuildComponents(hand, type, ovrAvatarComponent);

        return(hand);
    }
    private void BuildComponents(
        OvrAvatarPhysicsHand hand,
        OvrAvatarPhysicsHandTypes.HandType type,
        GameObject ovrAvatarComponent)
    {
        var transformations = CreateHandTransformations(type, ovrAvatarComponent);

        hand.gameObject.transform.localPosition = transformations.handBegin.transform.localPosition;
        hand.gameObject.transform.localRotation = transformations.handBegin.transform.localRotation;

        var handComponents = new HandComponents
        {
            indexComponent = BuildIndexFinger(hand, transformations.indexFingerBegin, transformations.indexFingerEnd),
            thumbComponent = BuildThumb(hand, transformations.thumbFingerBegin, transformations.thumbFingerEnd),
            fistComponent  = BuildFist(hand, transformations.handBegin, transformations.grip)
        };

        hand.Initialize(handComponents, transformations);
    }