示例#1
0
    /// <summary>
    /// 屏幕坐标转化为场景地图坐标
    /// </summary>
    /// <param name="screenPoint"></param>
    /// <returns></returns>
    public static Vector2 SceneCamToSceneMapPoint(Vector2 screenPoint)
    {
        //真实3D世界坐标
        Vector3 worldPoint = MapCamera.ScreenToWorldPoint(screenPoint);

        //相对的场景地图坐标
        return(SceneWorldToMapPoint(worldPoint - Vector3.right * SceneTiled.halfSceneWidth));
    }
    public static Vector3 GetWorldCoordinate(Vector3 mousePos)
    {
        Vector3 worldMouse = mousePos;

        worldMouse.z = MapObject.transform.localPosition.z;
        worldMouse   = MapCamera.ScreenToWorldPoint(worldMouse);

        ////Debug.Log("Mouse position in world  [" + worldMouse.x + "," + worldMouse.y + "," + worldMouse.z + "]");

        return(worldMouse);
    }
示例#3
0
    /// <summary>
    /// 屏幕坐标转化为世界地图的位置
    /// </summary>
    public static Vector2 SceneCamToWorldMapPoint(Vector2 screenPoint)
    {
        //真实3D世界坐标
        Vector3 worldPoint = MapCamera.ScreenToWorldPoint(screenPoint);

        //相对的场景地图坐标
        Vector2 scenePoint = SceneWorldToMapPoint(worldPoint - Vector3.right * SceneTiled.halfSceneWidth);
        //相对场景地图的世界坐标
        Vector3 sceneWorldPoint = SceneMapToWorld3D(scenePoint);

        //具体地块Tiled的地图坐标
        return(TiledWorldToMapPoint(worldPoint, sceneWorldPoint));
    }
    public static Vector3 GetGridCoordinate(Vector3 mousePos)
    {
        Vector3 worldMouse = mousePos;

        //worldMouse.z = -MapCamera.transform.localPosition.z;
        worldMouse.z = 0;
        worldMouse   = MapCamera.ScreenToWorldPoint(worldMouse);
        ////Debug.Log("Mouse position in world  [" + worldMouse.x + "," + worldMouse.y + "," + worldMouse.z + "]");

        Vector3 gridPosition = new Vector3();

        gridPosition.x = Mathf.Floor(worldMouse.x - MapObject.transform.position.x);
        gridPosition.y = Mathf.Floor(World.Instance.Height + MapObject.transform.position.y - worldMouse.y);
        // Warning, the next line will spam the output when uncommented, printing
        // at least once every frame.
        ////Debug.Log("Corresponding grid       [" + gridPosition.x + "," + gridPosition.y + "]");

        return(gridPosition);
    }