Skip to main content

TileMap的格子坐标转FUI的世界坐标



FairyGUI.GComponent com = null;
Vector3Int cell_pos = new Vector3Int(mapBuildDataBase.position_x, mapBuildDataBase.position_y, -4);

Debug.Log("执行了这里"+ mapBuildDataBase.id);
if(!BuildingComList.ContainsKey(mapBuildDataBase.id))
{
Debug.Log("没执行了这里" + mapBuildDataBase.id);
com = FairyGUI.UIPackage.CreateObject("Res_Compontent", "CountDownBuild").asCom;
//com.displayObject.layer = LayerMask.NameToLayer("CtiyTime");
BuildingComList.Add(mapBuildDataBase.id, com);
GameZootoPia._Instance.MainCom.AddChild(com);
Vector3 worldPos = GoodsLayer.CellToWorld(cell_pos); // 格子的世界坐标
Vector3 screenPos = FairyGUI.StageCamera.main.WorldToScreenPoint(worldPos); // 格子的屏幕坐标
screenPos.y = Screen.height - screenPos.y; //原点位置转换
Vector2 pt = FairyGUI.GRoot.inst.GlobalToLocal(screenPos); //转换世界空间的坐标到UI里的坐标
pt.x = pt.x - 120f;
pt.y = pt.y - 250f;
com.position = pt;//com.TransformPoint(new Vector2(10, 10), GameZootoPia._Instance.MainCom); //pt;
countDown(com, mapBuildDataBase);
}