// Specialized picking call used in anim mode
 public static Uni2DSmoothBindingBone PickNearestBoneInAnimMode(Uni2DSprite a_rSprite,
                                                                Vector2 a_f2MouseGUIPos,
                                                                out BoneHandle a_ePickedHandle,
                                                                Uni2DSmoothBindingBone a_rExclude = null)
 {
     return(Uni2DEditorSmoothBindingUtils.PickNearestBone(a_rSprite,
                                                          a_f2MouseGUIPos,
                                                          out a_ePickedHandle,
                                                          a_rExclude,
                                                          true,
                                                          Uni2DEditorSmoothBindingUtils.boneAnimPickRadius,
                                                          Uni2DEditorSmoothBindingUtils.boneLinkAnimPickRadius));
 }
 // Specialized picking call used in posing mode and when drawing disc handles
 public static Uni2DSmoothBindingBone PickNearestBoneArticulationInPosingMode(Uni2DSprite a_rSprite,
                                                                              Vector2 a_f2MouseGUIPos,
                                                                              out BoneHandle a_ePickedHandle,
                                                                              Uni2DSmoothBindingBone a_rExclude = null)
 {
     return(Uni2DEditorSmoothBindingUtils.PickNearestBone(a_rSprite,
                                                          a_f2MouseGUIPos,
                                                          out a_ePickedHandle,
                                                          a_rExclude,
                                                          false,
                                                          Uni2DEditorSmoothBindingUtils.bonePosingPickRadius,
                                                          Uni2DEditorSmoothBindingUtils.boneLinkPosingPickRadius));
 }
    ///// Picking /////
    private static Uni2DSmoothBindingBone PickNearestBone( Uni2DSprite a_rSprite,
		Vector2 a_f2MouseGUIPos,
		out BoneHandle a_ePickedHandle,
		Uni2DSmoothBindingBone a_rExclude = null,
		bool a_bAlsoPickBoneLink    = false,
		float a_fBonePickRadius     = Uni2DEditorSmoothBindingUtils.bonePosingPickRadius,
		float a_fBoneLinkPickRadius = Uni2DEditorSmoothBindingUtils.boneLinkAnimPickRadius )
    {
        Uni2DSmoothBindingBone rNearestBone     = null;
        Uni2DSmoothBindingBone rNearestBoneLink = null;

        // Squarred pick radius
        float fMinSqrBoneDistance  = a_fBonePickRadius * a_fBonePickRadius;
        float fMinBoneLinkDistance = a_fBoneLinkPickRadius;

        Uni2DSmoothBindingBone[ ] rBones = a_rSprite.Bones; //rSpriteTransform.GetComponentsInChildren<Transform>( false ).Except( oBonesToExclude ).ToArray( );

        // Look for nearest bone
        for( int iBoneIndex = 0, iBoneCount = rBones.Length; iBoneIndex < iBoneCount; ++iBoneIndex )
        {
            Uni2DSmoothBindingBone rBone = rBones[ iBoneIndex ];

            if( a_rExclude != rBone && rBone.IsFakeRootBone == false )
            {
                Vector2 f2BoneGUIPos = HandleUtility.WorldToGUIPoint( rBone.transform.position );
                Vector2 f2BoneToMouseGUI = a_f2MouseGUIPos - f2BoneGUIPos;

                float fSqrDistance = f2BoneToMouseGUI.sqrMagnitude;

                // New min/nearest
                if( fSqrDistance < fMinSqrBoneDistance )
                {
                    rNearestBone = rBone;
                    fMinSqrBoneDistance = fSqrDistance;
                }

                // Look for nearest bone link
                Uni2DSmoothBindingBone rBoneParent = rBone.Parent;
                if( a_bAlsoPickBoneLink && rBoneParent != null )
                {
                    float fLinkDistance = HandleUtility.DistancePointToLineSegment( a_f2MouseGUIPos,
                        f2BoneGUIPos,
                        HandleUtility.WorldToGUIPoint( rBoneParent.transform.position ) );

                    if( fLinkDistance < fMinBoneLinkDistance )
                    {
                        fMinBoneLinkDistance = fLinkDistance;
                        rNearestBoneLink = rBone;
                    }
                }
            }
        }

        // Picking result
        if( rNearestBone == null && rNearestBoneLink == null )
        {
            a_ePickedHandle = BoneHandle.None;
        }
        else if( rNearestBone != null )
        {
            if( fMinSqrBoneDistance <= a_fBonePickRadius * a_fBonePickRadius * 0.25f )
            {
                a_ePickedHandle = /*invertActionAreas == false ?*/ BoneHandle.InnerDisc; //: BoneHandle.OuterDisc;
            }
            else
            {
                a_ePickedHandle = /*invertActionAreas == false ?*/ BoneHandle.OuterDisc; //: BoneHandle.InnerDisc;
            }
        }
        else
        {
            rNearestBone    = rNearestBoneLink;
            a_ePickedHandle = BoneHandle.Link;
        }

        return rNearestBone;
    }
    // Specialized picking call used in posing mode
    public static Uni2DSmoothBindingBone PickNearestBoneInPosingMode( Uni2DSprite a_rSprite,
		Vector2 a_f2MouseGUIPos,
		out BoneHandle a_ePickedHandle,
		Uni2DSmoothBindingBone a_rExclude = null )
    {
        return Uni2DEditorSmoothBindingUtils.PickNearestBone( a_rSprite,
            a_f2MouseGUIPos,
            out a_ePickedHandle,
            a_rExclude,
            true,
            Uni2DEditorSmoothBindingUtils.bonePosingPickRadius,
            Uni2DEditorSmoothBindingUtils.boneLinkPosingPickRadius );
    }
    ///// Picking /////
    private static Uni2DSmoothBindingBone PickNearestBone(Uni2DSprite a_rSprite,
                                                          Vector2 a_f2MouseGUIPos,
                                                          out BoneHandle a_ePickedHandle,
                                                          Uni2DSmoothBindingBone a_rExclude = null,
                                                          bool a_bAlsoPickBoneLink          = false,
                                                          float a_fBonePickRadius           = Uni2DEditorSmoothBindingUtils.bonePosingPickRadius,
                                                          float a_fBoneLinkPickRadius       = Uni2DEditorSmoothBindingUtils.boneLinkAnimPickRadius)
    {
        Uni2DSmoothBindingBone rNearestBone     = null;
        Uni2DSmoothBindingBone rNearestBoneLink = null;

        // Squarred pick radius
        float fMinSqrBoneDistance  = a_fBonePickRadius * a_fBonePickRadius;
        float fMinBoneLinkDistance = a_fBoneLinkPickRadius;

        Uni2DSmoothBindingBone[] rBones = a_rSprite.Bones;          //rSpriteTransform.GetComponentsInChildren<Transform>( false ).Except( oBonesToExclude ).ToArray( );

        // Look for nearest bone
        for (int iBoneIndex = 0, iBoneCount = rBones.Length; iBoneIndex < iBoneCount; ++iBoneIndex)
        {
            Uni2DSmoothBindingBone rBone = rBones[iBoneIndex];

            if (a_rExclude != rBone && rBone.IsFakeRootBone == false)
            {
                Vector2 f2BoneGUIPos     = HandleUtility.WorldToGUIPoint(rBone.transform.position);
                Vector2 f2BoneToMouseGUI = a_f2MouseGUIPos - f2BoneGUIPos;

                float fSqrDistance = f2BoneToMouseGUI.sqrMagnitude;

                // New min/nearest
                if (fSqrDistance < fMinSqrBoneDistance)
                {
                    rNearestBone        = rBone;
                    fMinSqrBoneDistance = fSqrDistance;
                }

                // Look for nearest bone link
                Uni2DSmoothBindingBone rBoneParent = rBone.Parent;
                if (a_bAlsoPickBoneLink && rBoneParent != null)
                {
                    float fLinkDistance = HandleUtility.DistancePointToLineSegment(a_f2MouseGUIPos,
                                                                                   f2BoneGUIPos,
                                                                                   HandleUtility.WorldToGUIPoint(rBoneParent.transform.position));

                    if (fLinkDistance < fMinBoneLinkDistance)
                    {
                        fMinBoneLinkDistance = fLinkDistance;
                        rNearestBoneLink     = rBone;
                    }
                }
            }
        }

        // Picking result
        if (rNearestBone == null && rNearestBoneLink == null)
        {
            a_ePickedHandle = BoneHandle.None;
        }
        else if (rNearestBone != null)
        {
            if (fMinSqrBoneDistance <= a_fBonePickRadius * a_fBonePickRadius * 0.25f)
            {
                a_ePickedHandle = /*invertActionAreas == false ?*/ BoneHandle.InnerDisc;                 //: BoneHandle.OuterDisc;
            }
            else
            {
                a_ePickedHandle = /*invertActionAreas == false ?*/ BoneHandle.OuterDisc;                 //: BoneHandle.InnerDisc;
            }
        }
        else
        {
            rNearestBone    = rNearestBoneLink;
            a_ePickedHandle = BoneHandle.Link;
        }

        return(rNearestBone);
    }