private void OnDrawGizmos() { pos_w = this.gameObject.transform.position; topLeft = Vector3.zero + pos_w; topRight = new Vector3(WidthInScaled(), 0) + pos_w; bottomRight = new Vector3(WidthInScaled(), -HeightInScaled()) + pos_w; bottomLeft = new Vector3(0, -HeightInScaled()) + pos_w; // To make gizmo visible, even when using depth-shader shaders, we decrease the z depth by the number of layers float depth_z = -1.0f * 3;//this.NumLayers pos_w.z += depth_z; topLeft.z += depth_z; topRight.z += depth_z; bottomRight.z += depth_z; bottomLeft.z += depth_z; Vector2 mapPos = CoordinationConvert.SceneWorldToMapPoint(this.transform.position); Vector2 worldPos = CoordinationConvert.SceneMapToWorld3D(mapPos); GUI.color = Color.red; float x = (topLeft + (topRight - topLeft) * 0.25f).x; float y = (topLeft + (bottomLeft - topLeft) * 0.25f).y; Handles.Label(new Vector3(x, y), string.Format("({0},{1})/({2},{3})", mapPos.x, mapPos.y, worldPos.x, worldPos.y)); }
/// <summary> /// 初始化SceneTiled模块地图 /// </summary> /// <param name="gObj">主GameObject</param> /// <param name="worldMapIndex">世界地图中的索引</param> public void Initlizate(GameObject gObj) { mainObj = gObj; mainObj.name += "_" + WorldMapIndex; #if UNITY_EDITOR if (MapDebug.DebugSceneTiled) { gObj.AddComponent <SceneTiledGizmo>(); } #endif gObj.transform.localScale = Vector3.one; gObj.transform.position = WorldPosition; mapPoint = CoordinationConvert.SceneWorldToMapPoint(WorldPosition); //构造场景内的地块信息 landTileds.Clear(); int halfWidth = LandTiled.halfTiledWidth; int halfHeight = LandTiled.halfTiledHeight; // Vector3 orginPos = WorldPosition + new Vector3(halfSceneWidth - halfWidth,0); Vector3 orginPos = WorldPosition + new Vector3(halfSceneWidth, 0); for (int i = 0; i < SceneRow; i++) { int tiledRowIndex = i * SceneRow; for (int j = 0; j < SceneColumn; j++) { int tiledIndex = tiledRowIndex + j; //计算世界坐标中的位置 float tiledX = halfWidth * j - halfWidth * i; float tiledY = -halfHeight * j - halfHeight * i; Vector3 position = new Vector3(tiledX, tiledY); position += orginPos; //构造记录映射 TiledData td = new TiledData(); //td.TiledId = ; td.SceneIndex = (byte)WorldMapIndex; td.Index = tiledIndex; //实例土地 LandTiled landTiled = new LandTiled(td); landTiled.WorldPosition = position; landTileds.Add(landTiled); MapCreater.Instance.LoadDel("Assets/Prefabs/LandSprite.prefab", obj => { landTiled.Initlizate(obj, this); }); } } }