public void createTile(TileTextureWindow tileWindow, MapTile tile) { // 只有真正要使用该地砖时才解析 if (!tile.mParsed) { tile.parseTile(); } int x = tileIndexToTileX(tile.mIndex); int y = tileIndexToTileY(tile.mIndex); string tileSuffix = x + "_" + y; // 偶数行偶数列才渲染大地砖 if (tileWindow.mBackTile == null && x % 2 == 0 && y % 2 == 0) { // 大地砖图片窗口 string backTexName = mBackTilePath + (tile.mBngImgIdx - 1); Texture backTex = mResourceManager.loadResource <Texture>(backTexName, false); if (backTex != null) { // 一个panel满时,就应该放入新的panel中 int panelIndex = tile.mIndex / MAX_WINDOW_PER_PANEL; if (!mBackPanelList.ContainsKey(panelIndex)) { mBackPanelList.Add(panelIndex, createObject <txNGUIPanel>(mBackRoot, "BackPanel" + panelIndex)); } tileWindow.mBackTile = mWindowPool.createWindow <txNGUITexture>("back_" + tileSuffix, mBackPanelList[panelIndex]); tileWindow.mBackTile.setTexture(backTex, true); tileWindow.mBackTile.setMaterial("NGUIDefault", false); Vector2 posOffset = tileWindow.mBackTile.getTextureSize() / 2.0f; posOffset += new Vector2(48 * x - mHalfMap.x, mHalfMap.y - 32 * y - 32); tileWindow.mBackTile.setLocalPosition(posOffset); tileWindow.mBackTile.setDepth(1); if (tile.mHasBng) { tileWindow.mBackTile.setColor(new Color(0.5f, 0.0f, 0.0f)); } else { tileWindow.mBackTile.setColor(Color.white); } tileWindow.mBackTile.getUITexture().mUserData = charArrayToHexString(tile.mTileBuffer, tile.mTileBuffer.Length); } } if (tileWindow.mMidTile == null) { // 小地砖图片窗口 string midTexName = mMidTilePath + (tile.mMidImgIdx - 1); Texture midTex = mResourceManager.loadResource <Texture>(midTexName, false); if (midTex != null) { tileWindow.mMidTile = mWindowPool.createWindow <txNGUITexture>("mid_" + tileSuffix, mMiddleRoot); tileWindow.mMidTile.setTexture(midTex, true); tileWindow.mMidTile.setMaterial("NGUIDefault", false); Vector2 posOffset = tileWindow.mMidTile.getTextureSize() / 2.0f; posOffset += new Vector2(48 * x - mHalfMap.x, mHalfMap.y - 32 * y); tileWindow.mMidTile.setLocalPosition(posOffset); tileWindow.mMidTile.setColor(Color.white); } } if (tileWindow.mObjectTile == null) { // 普通物体 if (!tile.mHasAni) { string objTexName = mObjectImagePreString + (tile.mObjFileIdx + 1) + "/" + (tile.mObjImgIdx - 1); Texture objTex = mResourceManager.loadResource <Texture>(objTexName, false); if (objTex != null) { tileWindow.mObjectTile = mWindowPool.createWindow <txNGUITexture>("obj_" + tileSuffix, mObjRoot); tileWindow.mObjectTile.setTexture(objTex, true); tileWindow.mObjectTile.setMaterial("NGUIDefault", false); Vector2 posOffset = tileWindow.mObjectTile.getTextureSize() / 2.0f; posOffset += new Vector2(48 * x - mHalfMap.x, mHalfMap.y - 32 * y); tileWindow.mObjectTile.setLocalPosition(posOffset); tileWindow.mObjectTile.setDepth(3); if (tile.mHasObj) { tileWindow.mObjectTile.setColor(new Color(0.5f, 0.0f, 0.0f)); } else { tileWindow.mObjectTile.setColor(Color.white); } tileWindow.mObjectTile.getUITexture().mUserData = charArrayToHexString(tile.mTileBuffer, tile.mTileBuffer.Length); } } // 带序列帧的物体 else { string objTexName = mObjectImagePreString + (tile.mObjFileIdx + 1) + "/" + (tile.mObjImgIdx - 1); Texture objTex = mResourceManager.loadResource <Texture>(objTexName, false); if (objTex != null) { tileWindow.mObjectTile = mWindowPool.createWindow <txNGUITexture>("obj_" + tileSuffix, mObjRoot); tileWindow.mObjectTile.setTexture(objTex, true); tileWindow.mObjectTile.setMaterial("Multiple", false); Vector2 posOffset = new Vector2(0.0f, tileWindow.mObjectTile.getTextureSize().y * 1.5f); posOffset += new Vector2(48 * x - mHalfMap.x, mHalfMap.y - 32 * y); tileWindow.mObjectTile.setLocalPosition(posOffset); tileWindow.mObjectTile.setDepth(3); } } } }
public void createTile(TileWindow tileWindow, MapTileAdvance tile) { // 只有真正要使用该地砖时才解析 if (!tile.mParsed) { tile.parseTile(); } int x = tileIndexToTileX(tile.mIndex); int y = tileIndexToTileY(tile.mIndex); string tileSuffix = x + "_" + y; // 偶数行偶数列才渲染大地砖 if (tileWindow.mBackTile == null && x % 2 == 0 && y % 2 == 0) { // 大地砖图集 UIAtlas bngAtlas = getBackTileAtlas(tile); // 大地砖图片窗口 string bngSpriteName = "" + (tile.mBngImgIdx - 1); if (bngAtlas != null && bngAtlas.GetSprite(bngSpriteName) != null) { if (!mBackAtlasList.ContainsKey(tile.mBngAtlasIndex)) { mBackAtlasList.Add(tile.mBngAtlasIndex, new List <int>()); } // 一个panel中只允许有一个Drawcall // 一个panel满时,就应该放入新的panel中 // 查找该图集存放在哪些panel中 int panelIndex = -1; List <int> panelIndexList = mBackAtlasList[tile.mBngAtlasIndex]; int panelCount = panelIndexList.Count; for (int j = 0; j < panelCount; ++j) { // 找到一个包含该图集,且数量未达上限的panel if (mBackPanelList[panelIndexList[j]].mObjectCount < MAX_WINDOW_PER_PANEL) { panelIndex = panelIndexList[j]; break; } } // 没有找到合适的panel,则创建新的panel if (panelIndex == -1) { panelIndex = GameUtility.makeID(); PanelInfo panelInfo = new PanelInfo(); panelInfo.mPanel = createObject <txNGUIPanel>(mBackRoot, "BackPanel" + panelIndex); panelInfo.mObjectCount = 0; panelInfo.mAtlasIndex = tile.mBngAtlasIndex; mBackPanelList.Add(panelIndex, panelInfo); mBackAtlasList[tile.mBngAtlasIndex].Add(panelIndex); } // panel中的窗口计数+1 mBackPanelList[panelIndex].mObjectCount += 1; tileWindow.mBackTile = mWindowPool.createWindow <txNGUISprite>("back_" + tileSuffix, mBackPanelList[panelIndex].mPanel); tileWindow.mBackTile.setAtlas(bngAtlas); tileWindow.mBackTile.setSpriteName(bngSpriteName, true); Vector2 posOffset = tileWindow.mBackTile.getSpriteSize() / 2.0f; posOffset += new Vector2(48 * x - mHalfMap.x, mHalfMap.y - 32 * y - 32); tileWindow.mBackTile.setLocalPosition(posOffset); tileWindow.mBackTile.setDepth(1); if (tile.mHasBng) { tileWindow.mBackTile.getSprite().color = new Color(0.5f, 0.0f, 0.0f); } else { tileWindow.mBackTile.getSprite().color = Color.white; } } } if (tileWindow.mMidTile == null) { // 小地砖图片窗口 string midSpriteName = "" + (tile.mMidImgIdx - 1); if (midAtlas.GetSprite(midSpriteName) != null) { tileWindow.mMidTile = mWindowPool.createWindow <txNGUISprite>("mid_" + tileSuffix, mMiddleRoot); tileWindow.mMidTile.setAtlas(midAtlas); tileWindow.mMidTile.setSpriteName(midSpriteName, true); Vector2 posOffset = tileWindow.mMidTile.getSpriteSize() / 2.0f; posOffset += new Vector2(48 * x - mHalfMap.x, mHalfMap.y - 32 * y); tileWindow.mMidTile.setLocalPosition(posOffset); } } if (tileWindow.mObjectTile == null) { if (!tile.mHasAni) { // 加载对象图集 UIAtlas atlas = getObjTileAtlas(tile); // 创建对象图片窗口 string spriteName = "" + (tile.mObjImgIdx - 1); if (atlas != null && atlas.GetSprite(spriteName) != null) { tileWindow.mObjectTile = mWindowPool.createWindow <txNGUISprite>("obj_" + tileSuffix, mObjRoot); txNGUISprite objTile = tileWindow.mObjectTile; objTile.setAtlas(atlas); objTile.setSpriteName(spriteName, true); Vector2 posOffset = objTile.getSpriteSize() / 2.0f; posOffset += new Vector2(48 * x - mHalfMap.x, mHalfMap.y - 32 * y); objTile.setLocalPosition(posOffset); objTile.setDepth(y); if (!tile.mCanWalk) { BoxCollider collider = objTile.getBoxCollider(true); collider.size = objTile.getSpriteSize(); } objTile.setHandleInput(!tile.mCanWalk); if (tile.mHasObj) { objTile.getSprite().color = new Color(0.5f, 0.0f, 0.0f); } else { objTile.getSprite().color = Color.white; } } } } if (tileWindow.mEffect == null) { if (tile.mHasAni) { // 加载对象图集 UIAtlas atlas = getEffectAtlas(tile); // 创建对象图片窗口 if (atlas != null) { tileWindow.mEffect = mWindowPool.createWindow <txNGUISpriteAnim>("effect_" + tileSuffix, mObjRoot); tileWindow.mEffect.setAtlas(atlas); tileWindow.mEffect.setTextureSet(intToString(tile.mObjImgIdx - 1)); tileWindow.mEffect.play(); tileWindow.mEffect.setLoop(LOOP_MODE.LM_LOOP); tileWindow.mEffect.setSpeed(0.5f); Vector2 posOffset = new Vector2(0.0f, tileWindow.mEffect.getSpriteSize().y * 1.5f); posOffset += new Vector2(48 * x - mHalfMap.x, mHalfMap.y - 32 * y); tileWindow.mEffect.setLocalPosition(posOffset); tileWindow.mEffect.setDepth(y); } } } }