Exemplo n.º 1
0
    protected UIAtlas getBackTileAtlas(MapTileAdvance tile)
    {
        UIAtlas bngAtlas = null;

        if (tile.mBngAtlasIndex != 0xFF)
        {
            if (!mBngAtlasIndexMap.ContainsKey(tile.mBngAtlasIndex))
            {
                bngAtlas = mResourceManager.loadResource <UIAtlas>(mBackTilePath + tile.mBngAtlasIndex, true);
                mBngAtlasIndexMap.Add(tile.mBngAtlasIndex, bngAtlas);
            }
            else
            {
                bngAtlas = mBngAtlasIndexMap[tile.mBngAtlasIndex];
            }
        }
        return(bngAtlas);
    }
Exemplo n.º 2
0
    public void readFile(string fileName)
    {
        byte[] fileBuffer = null;
        openFile(fileName, ref fileBuffer);
        if (fileBuffer == null)
        {
            return;
        }
        int offset = 0;

        mHeader.parseHeader(fileBuffer, ref offset);
        int tileCount = mHeader.mWidth * mHeader.mHeight;

        mTileList = new MapTileAdvance[tileCount];
        for (int i = 0; i < tileCount; ++i)
        {
            mTileList[i] = new MapTileAdvance(i);
            // 读文件时只是保存数据,暂时不解析所有地砖
            mTileList[i].preParseTile(fileBuffer, ref offset);
        }
    }
Exemplo n.º 3
0
    protected UIAtlas getObjTileAtlas(MapTileAdvance tile)
    {
        UIAtlas atlas = null;

        if (!mObjAtlasIndexMap.ContainsKey(tile.mObjFileIdx + 1))
        {
            mObjAtlasIndexMap.Add(tile.mObjFileIdx + 1, new Dictionary <int, UIAtlas>());
        }
        if (tile.mObjAtlasIndex != 0xFF)
        {
            if (!mObjAtlasIndexMap[tile.mObjFileIdx + 1].ContainsKey(tile.mObjAtlasIndex))
            {
                atlas = mResourceManager.loadResource <UIAtlas>(mObjectImagePreString + (tile.mObjFileIdx + 1) + "/" + tile.mObjAtlasIndex, true);
                mObjAtlasIndexMap[tile.mObjFileIdx + 1].Add(tile.mObjAtlasIndex, atlas);
            }
            else
            {
                atlas = mObjAtlasIndexMap[tile.mObjFileIdx + 1][tile.mObjAtlasIndex];
            }
        }
        return(atlas);
    }
Exemplo n.º 4
0
    protected UIAtlas getEffectAtlas(MapTileAdvance tile)
    {
        UIAtlas atlas     = null;
        int     fileIndex = tile.mObjFileIdx + 1;

        if (!mEffectAtlasIndexMap.ContainsKey(fileIndex))
        {
            mEffectAtlasIndexMap.Add(fileIndex, new Dictionary <int, UIAtlas>());
        }
        if (tile.mHasAni)
        {
            int objImageIndex = tile.mObjImgIdx - 1;
            if (!mEffectAtlasIndexMap[fileIndex].ContainsKey(objImageIndex))
            {
                atlas = mResourceManager.loadResource <UIAtlas>(mEffectPath + fileIndex + "/" + objImageIndex, true);
                mEffectAtlasIndexMap[fileIndex].Add(objImageIndex, atlas);
            }
            else
            {
                atlas = mEffectAtlasIndexMap[fileIndex][objImageIndex];
            }
        }
        return(atlas);
    }
Exemplo n.º 5
0
    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);
                }
            }
        }
    }