GetTileFracAtPosition() public method

Gets the tile coordinate at position. This can be used to obtain tile or color data explicitly from layers The fractional value returned is the fraction into the current tile Returns true if the position is within the tilemap bounds
public GetTileFracAtPosition ( Vector3 position, float &x, float &y ) : bool
position Vector3
x float
y float
return bool
示例#1
0
    bool UpdateCursorPosition()
    {
        bool isInside = false;

        Plane p    = new Plane(tileMap.transform.forward, tileMap.transform.position);
        Ray   r    = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
        float hitD = 0.0f;

        if (p.Raycast(r, out hitD))
        {
            float fx, fy;
            if (tileMap.GetTileFracAtPosition(r.GetPoint(hitD), out fx, out fy))
            {
                int x = (int)(fx);
                int y = (int)(fy);

                cursorX       = Mathf.Clamp(x, 0, tileMap.width - 1);
                cursorY       = Mathf.Clamp(y, 0, tileMap.height - 1);
                vertexCursorX = (int)Mathf.Round(fx);
                vertexCursorY = (int)Mathf.Round(fy);

                HandleUtility.Repaint();

                isInside = true;
            }
        }

        return(isInside);
    }
示例#2
0
    bool UpdateCursorPosition()
    {
        if (scratchpadGUI.workingHere)
        {
            cursorX = (int)((scratchpadGUI.paintMousePosition.x / scratchpadGUI.scratchZoom) / (tileMapData.tileSize.x / curSpriteDefTexelSize.x));
            cursorY = (int)((scratchpadGUI.paintMousePosition.y / scratchpadGUI.scratchZoom) / (tileMapData.tileSize.y / curSpriteDefTexelSize.y));
            return(true);
        }

        bool isInside = false;

        Vector3 layerDepthOffset = new Vector3(0, 0, GetLayerDepth(editorData.layer));

        layerDepthOffset = tileMap.transform.TransformDirection(layerDepthOffset);

        Plane p    = new Plane(tileMap.transform.forward, tileMap.transform.position + layerDepthOffset);
        Ray   r    = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
        float hitD = 0.0f;

        if (p.Raycast(r, out hitD))
        {
            float fx, fy;
            if (tileMap.GetTileFracAtPosition(r.GetPoint(hitD), out fx, out fy))
            {
                isInside = true;
            }
            int x = (int)(fx);
            int y = (int)(fy);

            cursorX       = x;
            cursorY       = y;
            vertexCursorX = (int)Mathf.Round(fx);
            vertexCursorY = (int)Mathf.Round(fy);

            HandleUtility.Repaint();
        }

        return(isInside);
    }