Ejemplo n.º 1
0
    public Rect VisibleRect(Camera camera)
    {
        VisibleArea va = MapLayout.CalcRelativeVisibleArea(camera);

        return(new Rect(camera.transform.localPosition.x - va.farHalfWidth,
                        camera.transform.localPosition.z + va.near,
                        va.farHalfWidth * 2f,
                        va.far - va.near));
    }
    public void MoveCamera(Vector3 newPos)
    {
        Vector3 prePos = MapCamera.transform.localPosition;

        MapCamera.transform.localPosition = newPos;

        MapLayout.VisibleArea va = MapLayout.CalcRelativeVisibleArea(MapCamera);

        float xMin = -OutRange;
        float xMax = Layout.HexTileWidth * MapConst.MAP_WIDTH + OutRange;
        float zMin = -OutRange;
        float zMax = Layout.HexTileHeight * MapConst.MAP_HEIGHT + OutRange;

        if (newPos.z + va.near < zMin)
        {
            newPos.z = zMin - va.near;
        }

        if (newPos.z + va.far > zMax)
        {
            newPos.z = zMax - va.far;
        }

        if (newPos.x - va.farHalfWidth < xMin)
        {
            newPos.x = xMin + va.farHalfWidth;
        }

        if (newPos.x + va.farHalfWidth > xMax)
        {
            newPos.x = xMax - va.farHalfWidth;
        }

        MapCamera.transform.localPosition = newPos;
        OnCameraMove(newPos, prePos);
    }