Assets/FlexibleColorPicker/Scripts/FlexibleColorPicker.cs
/// <summary>
/// Get normalized position of the given pointer event relative to the given rect.
/// (e.g. return [0,1] for top left corner). This method correctly takes into 
/// account relative positions, canvas render mode and general transformations, 
/// including rotations and scale.
/// </summary>
/// <param name="canvas">parent canvas of the rect (and therefore the FCP)</param>
/// <param name="rect">Rect to find relative position to</param>
/// <param name="e">Pointer event for which to find the relative position</param>
Get normalized position of the given pointer event relative to the given rect.
. This method correctly takes into
account relative positions, canvas render mode and general transformations,
including rotations and scale.
Get normalized position of the given pointer event relative to the given rect . . This method correctly takes into account relative positions canvas render mode and general transformations including rotations and scale .
private static Vector2 GetNormalizedPointerPosition(Canvas canvas, RectTransform rect, BaseEventData e) {
        switch(canvas.renderMode) {
        case RenderMode.ScreenSpaceCamera:
        if(canvas.worldCamera == null)
            return GetNormScreenSpace(rect, e);
        else
            return GetNormWorldSpace(canvas, rect, e);
        case RenderMode.ScreenSpaceOverlay:
        return GetNormScreenSpace(rect, e);
        case RenderMode.WorldSpace:
        if(canvas.worldCamera == null) {
            Debug.LogError("FCP in world space render mode requires an event camera to be set up on the parent canvas!");
            return Vector2.zero;
        }
        return GetNormWorldSpace(canvas, rect, e);
        default: return Vector2.zero;
        }
    }
private static Vector2 GetNormalizedPointerPosition ( Canvas canvas , RectTransform rect , BaseEventData e ) { switch ( canvas . renderMode ) { case RenderMode . ScreenSpaceCamera : if ( canvas . worldCamera == null ) return GetNormScreenSpace ( rect , e ) ; else return GetNormWorldSpace ( canvas , rect , e ) ; case RenderMode . ScreenSpaceOverlay : return GetNormScreenSpace ( rect , e ) ; case RenderMode . WorldSpace : if ( canvas . worldCamera == null ) { Debug . LogError ( " " ) ; return Vector2 . zero ; } return GetNormWorldSpace ( canvas , rect , e ) ; default : return Vector2 . zero ; } }
Get normalized position of the given pointer event relative to the given rect.
Get normalized position of the given pointer event relative to the given rect .
canvas
Canvas
parent canvas of the rect (and therefore the FCP)
parent canvas of the rect ( and therefore the FCP )
rect
RectTransform
Rect to find relative position to
Rect to find relative position to
e
BaseEventData
Pointer event for which to find the relative position
Pointer event for which to find the relative position