Exemplo n.º 1
0
    /// <summary>
    /// 获得土地块
    /// </summary>
    /// <param name="screenPos">屏幕坐标系的位置</param>
    /// <returns></returns>
    public LandTiled FindLandTiled(Vector3 screenPos)
    {
        //世界地图坐标
        Vector2 mapPoint = CoordinationConvert.SceneCamToWorldMapPoint(screenPos);

        return(FindLandTiledByMapPoint(mapPoint));
    }
Exemplo n.º 2
0
    /// <summary>
    /// 估算屏幕内所占格子的数量
    /// </summary>
    private void culScreenTiledCount()
    {
        if (halfScreenWidthTiledCount != 0)
        {
            return;
        }

        Vector2 mapLeftTop    = CoordinationConvert.SceneCamToWorldMapPoint(Vector2.zero);
        Vector2 mapRightTop   = CoordinationConvert.SceneCamToWorldMapPoint(new Vector2(Screen.width, 0));
        Vector2 mapLeftButtom = CoordinationConvert.SceneCamToWorldMapPoint(new Vector2(0, Screen.height));

        halfScreenWidthTiledCount  = (int)(mapRightTop.x - mapLeftTop.x) / 2 + 1;
        halfScreenHeightTiledCount = (int)(mapLeftButtom.y - mapLeftTop.y) / 2 + 1;
    }
Exemplo n.º 3
0
    /// <summary>
    /// 主相机移动时的操作
    /// </summary>
    public void CameraChange()
    {
//        this.culScreenTiledCount();
//        Debug.Log("halfTileW:" + halfScreenWidthTiledCount + " , halfTileH:" + halfScreenHeightTiledCount);
        //计算相机中心个点的世界坐标位置
//        Vector2 center = new Vector2(Screen.width / 2 , Screen.height / 2);

        //计算TileIndex索引
        Dictionary <int, WorldSceneData> worldSceneDatas = new Dictionary <int, WorldSceneData>();
//        Vector2 mapPos = CoordinationConvert.SceneCamToSceneMapPoint(center);
//        addSceneTiled(mapPos, worldSceneDatas);
        //        //计算横向
        //        for (int i = 0; i < 2; i++)
        //        {
        //            //横向
        //            float nearX =  mapPos.x - (1 - (i % 2) * 2) * halfScreenWidthTiledCount;
        //            float nearY = mapPos.y + (1 - (i % 2) * 2) * halfScreenWidthTiledCount;
        //            Vector2 nearMapPos = new Vector2(nearX , nearY);
        //            addSceneTiled(nearMapPos, worldSceneDatas);
        //
        //            //纵向
        //            nearX = mapPos.x - (1 - (i % 2) * 2) * halfScreenHeightTiledCount;
        //            nearY = mapPos.y - (1 - (i % 2) * 2) * halfScreenHeightTiledCount;
        //            nearMapPos = new Vector2(nearX, nearY);
        //            addSceneTiled(nearMapPos, worldSceneDatas);
        //        }
        //
        //        //计算四个边角
        //        addShowTiled(Vector2.zero , worldSceneDatas);
        //        addShowTiled(new Vector2(Screen.width , 0), worldSceneDatas);
        //        addShowTiled(new Vector2(0 , Screen.height), worldSceneDatas);
        //        addShowTiled(new Vector2(Screen.width , Screen.height), worldSceneDatas);

        Vector2 mapLeftTop     = CoordinationConvert.SceneCamToWorldMapPoint(Vector2.zero);
        Vector2 mapLeftBottom  = CoordinationConvert.SceneCamToWorldMapPoint(new Vector2(0, Screen.height));
        Vector2 mapRightTop    = CoordinationConvert.SceneCamToWorldMapPoint(new Vector2(Screen.width, 0));
        Vector2 mapRightBottom = CoordinationConvert.SceneCamToWorldMapPoint(new Vector2(Screen.width, Screen.height));

        Debug.Log("Map LT: " + mapLeftTop + " , LB: " + mapLeftBottom + " , RT: " + mapRightTop + " , RB:" + mapRightBottom);

        int count = (int)(mapRightTop.x - mapLeftTop.x) + 2;

        for (int i = 0; i <= count; i++)
        {
            //上边缘
            Vector2 newMapPoint   = mapLeftTop + new Vector2(i + 1, -i + 1);
            Vector2 sceneMapPoint = CoordinationConvert.TileMapToSceneMapPoint(newMapPoint);
            addSceneTiled(sceneMapPoint, worldSceneDatas);

            //下边缘
            newMapPoint   = mapLeftBottom + new Vector2(i - 1, -i);
            sceneMapPoint = CoordinationConvert.TileMapToSceneMapPoint(newMapPoint);
            addSceneTiled(sceneMapPoint, worldSceneDatas);
        }

        //左边缘
        count = (int)(mapLeftTop.x - mapLeftBottom.x) + 1;
        for (int i = 0; i <= count; i++)
        {
            Vector2 newMapPoint   = mapLeftTop - new Vector2(i, i - 2);
            Vector2 sceneMapPoint = CoordinationConvert.TileMapToSceneMapPoint(newMapPoint);
            addSceneTiled(sceneMapPoint, worldSceneDatas);
        }

        //右边缘
        count = (int)(mapRightTop.x - mapRightBottom.x) + 2;
        for (int i = 0; i <= count; i++)
        {
            Vector2 newMapPoint   = mapRightTop - new Vector2(i - 2, i);
            Vector2 sceneMapPoint = CoordinationConvert.TileMapToSceneMapPoint(newMapPoint);
            addSceneTiled(sceneMapPoint, worldSceneDatas);
        }

        WorldSceneData[] wsdArr = new WorldSceneData[worldSceneDatas.Count];
        worldSceneDatas.Values.CopyTo(wsdArr, 0);

        this.MergeMap(wsdArr);

        //用于测试地图的可视区域
        //debugViewMap(mapLeftTop , mapLeftBottom , mapRightTop , mapRightBottom);
    }