コード例 #1
0
        private void DoInitRenderProperty()
        {
            var minPosX = float.MaxValue;
            var minPosY = float.MaxValue;

            var maxPosX = float.MinValue;
            var maxPosY = float.MinValue;

            var tileWidthInUnit  = (float)mMapMeta.tileWidthInPixel / mRenderSetting.pixelsPreUnit;
            var tileHeightInUnit = (float)mMapMeta.tileHeightInPixel / mRenderSetting.pixelsPreUnit;


            mAllNeedRenderTileList = new List <ITU_RenderTileData>();
            mLayerMeta.chunkList.ForEach(chunk =>
            {
                for (var index = 0; index < chunk.data.Length; index++)
                {
                    var gid = chunk.data[index];
                    //为0的砖块则表示不需要渲染
                    if (gid == 0)
                    {
                        continue;
                    }

                    var renderTileData = new ITU_RenderTileData();
                    renderTileData.x   = chunk.startX + index % chunk.width;
                    renderTileData.y   = chunk.startY + (int)Mathf.Ceil(index / chunk.width);

                    ITU_TsxRootMeta _tilesetMeta;
                    ITU_TsxEachTileMeta _eachTileMeta;
                    ITU_Utils.GetTileMetaByGid(mMapMeta, gid, out _tilesetMeta, out _eachTileMeta);

                    _tilesetMeta.isUesdInRender = true;
                    renderTileData.tileMeta     = _eachTileMeta;
                    mAllNeedRenderTileList.Add(renderTileData);

                    Vector2 nowPos;
                    ITU_MathUtils.TileTopCorner2World(renderTileData.x, renderTileData.y, tileWidthInUnit, tileHeightInUnit, mMapMeta.IsIsoStaggered(), out nowPos);

                    minPosX = Mathf.Min(minPosX, nowPos.x);
                    minPosY = Mathf.Min(minPosY, nowPos.y);
                    maxPosX = Mathf.Max(maxPosX, nowPos.x);
                    maxPosY = Mathf.Max(maxPosY, nowPos.y);
                }
            });

            //左上和右下两个Bound是左边点向两边个扩充2.5个Tile,.5是为了让坐标点在中心. 2个Tile是增大Bound防止周围Tile未渲染
            //因为后续渲染会检测空Tile,所以区间扩充大一些没有关系
            mLeftTopCornerBound     = new Vector2(minPosX - tileWidthInUnit * 2.5f, maxPosY + tileHeightInUnit * mRenderSetting.renderChunkSize * 2.5f);
            mRightBottomCornerBound = new Vector2(maxPosX + tileWidthInUnit * 2.5f, minPosY - tileHeightInUnit * mRenderSetting.renderChunkSize * 2.5f);


            //此值不准确,只是为了大概显示一下进度条,防止界面卡顿导致以为是死机
            var xNum = Mathf.CeilToInt(Math.Abs(mRightBottomCornerBound.x - mLeftTopCornerBound.x) / (mRenderSetting.renderChunkSize * tileWidthInUnit));
            var yNum = Mathf.CeilToInt(Math.Abs(mRightBottomCornerBound.y - mLeftTopCornerBound.y) / (mRenderSetting.renderChunkSize * tileHeightInUnit * 0.5f));

            mMaxMayRenderChunkNum = (xNum + 4) * (yNum + 4);
        }
コード例 #2
0
 private void LinkTilesetObjectMeta()
 {
     objectList.ForEach(x =>
     {
         if (x.gid != 0)
         {
             x.tileMeta = ITU_Utils.GetTileMetaByGid(this, x.gid);
         }
     });
 }
コード例 #3
0
        public void HandleMapPropertyAndObject()
        {
            if (mMapMeta == null)
            {
                Debug.LogError("ITU_Facade not load any map, please call LoadTxmFile function first");
                return;
            }

            //Begin
            mAllExtensionList.ForEach(x =>
            {
                x.SetRenderSetting(mRenderSetting);
                x.SetTmxMapMeta(mMapMeta);
                x.HandleMapPropertyAndObjectBegin();
            });

            //Map
            mAllExtensionList.ForEach(x =>
            {
                if (mMapMeta.property != null)
                {
                    x.HandleMapProperty(mMapMeta.property);
                }
            });

            //Layer
            mAllExtensionList.ForEach(x =>
            {
                mMapMeta.layerList.ForEach(layer =>
                {
                    if (layer.property != null)
                    {
                        x.HandleLayerProperty(layer, layer.property);
                    }
                });
            });

            //Object
            mAllExtensionList.ForEach(x => { mMapMeta.objectList.ForEach(x.HandleMapObject); });

            var pixelsPreUnit    = mRenderSetting != null ? mRenderSetting.pixelsPreUnit : 100;
            var tileWidthInUnit  = (float)mMapMeta.tileWidthInPixel / pixelsPreUnit;
            var tileHeightInUnit = (float)mMapMeta.tileHeightInPixel / pixelsPreUnit;

            //Tile
            mAllExtensionList.ForEach(x =>
            {
                mMapMeta.layerList.ForEach(layer =>
                {
                    layer.chunkList.ForEach(chunk =>
                    {
                        for (var index = 0; index < chunk.data.Length; index++)
                        {
                            var gid = chunk.data[index];
                            //为0的砖块则表示不需要渲染
                            if (gid == 0)
                            {
                                continue;
                            }
                            var tileMeta = ITU_Utils.GetTileMetaByGid(mMapMeta, gid);
                            if (tileMeta != null && !tileMeta.property.IsEmpty())
                            {
                                var tileX = chunk.startX + index % chunk.width;
                                var tileY = chunk.startY + (int)Mathf.Ceil(index / chunk.width);
                                Vector2 topPos;
                                ITU_MathUtils.TileTopCorner2World(tileX, tileY, tileWidthInUnit, tileHeightInUnit, mMapMeta.IsIsoStaggered(), out topPos);
                                x.HandelTileWithProperty(new Vector2Int(tileX, tileY), topPos, tileWidthInUnit, tileHeightInUnit, layer, tileMeta);
                            }
                        }
                    });
                });
            });

            //Finish
            mAllExtensionList.ForEach(x => { x.HandleMapPropertyAndObjectFinish(); });
        }
コード例 #4
0
 public void MakeAllStatic()
 {
     ITU_Utils.MakeAllSubGameObjectStatic(mTxmMapGo);
 }