Exemple #1
0
        public void UpdateTerrainBlock()
        {
            if (bUpdate == false)
            {
                return;
            }

            if (m_layerData == null)
            {
                return;
            }
            int index = m_x + m_z * (int)m_layerData.BlockNumX;

            float offsetx = GetOffsetX(m_x);
            float offsetz = -GetOffsetX(m_z);
            int   nStartX = 0;
            int   nEndX   = 0;
            int   nStartZ = 0;
            int   nEndZ   = 0;

            GetNodeBound(m_layerData, m_x, m_z, ref nStartX, ref nEndX, ref nStartZ, ref nEndZ);

            Clear();
            Begin();

            //  Debug.Log("UpdateBlock set flag x" + m_x + " z" + m_z);

            List <Vector3> vertices = new List <Vector3>();

            List <Vector2> uv        = new List <Vector2>();
            List <int>     triangles = new List <int>();

            int verCount = 0;
            int triCount = 0;
            int uvCount  = 0;

            float m_uGridLenX = TerrainBlock.GRID_LEN;
            float m_uGridLenZ = TerrainBlock.GRID_LEN;

            for (int z = nStartZ; z < nEndZ; z++)
            {
                for (int x = nStartX; x < nEndX; x++)
                {
                    GridInfo grid = m_layerData.GetGrid(x, z);
                    if (grid.IsMask == false)
                    {
                        continue;
                    }
                    float fHeight1 = m_layerData.GetHeight(x, z);
                    float fHeight2 = m_layerData.GetHeight(x, z + 1);
                    float fHeight3 = m_layerData.GetHeight(x + 1, z + 1);
                    float fHeight4 = m_layerData.GetHeight(x + 1, z);

                    // 上面去一点地形不容易搓出来
                    fHeight1 += m_TerrainBlockHeight;
                    fHeight2 += m_TerrainBlockHeight;
                    fHeight3 += m_TerrainBlockHeight;
                    fHeight4 += m_TerrainBlockHeight;

                    /*
                     * 0------1
                     |      |
                     |      |
                     | 3------2
                     */
                    // 一象限变四象限
                    Vector3 pos1 = new Vector3(x * m_uGridLenX - offsetx, fHeight1, (-z) * m_uGridLenZ - offsetz);

                    Vector3 pos2 = new Vector3((x + 1) * m_uGridLenX - offsetx, fHeight4, (-z) * m_uGridLenZ - offsetz);
                    Vector3 pos3 = new Vector3((x + 1) * m_uGridLenX - offsetx, fHeight3, -(z + 1) * m_uGridLenZ - offsetz);
                    Vector3 pos4 = new Vector3(x * m_uGridLenX - offsetx, fHeight2, -(z + 1) * m_uGridLenZ - offsetz);


                    vertices.Add(pos1);
                    vertices.Add(pos2);
                    vertices.Add(pos3);
                    vertices.Add(pos4);

                    Vector2 uv1 = new Vector2(0, 0);
                    Vector2 uv2 = new Vector2(0, 1 / GridDef.GridSize);
                    Vector2 uv3 = new Vector2(1 / GridDef.GridSize, 1 / GridDef.GridSize);
                    Vector2 uv4 = new Vector2(1 / GridDef.GridSize, 0);
                    uv.Add(uv1);
                    uv.Add(uv2);
                    uv.Add(uv3);
                    uv.Add(uv4);


                    // 一象限变四象限

                    triangles.Add(verCount + 2);
                    triangles.Add(verCount);
                    triangles.Add(verCount + 1);
                    triangles.Add(verCount + 3);
                    triangles.Add(verCount);
                    triangles.Add(verCount + 2);


                    verCount += 4;
                    uvCount  += 4;
                    triCount += 6;
                }
            }
            Color color = Color.white;

            if (m_layerData.layerType == BaseLayer.LayerType.eLayerBlock)
            {
                color = Color.red;
            }
            else if (m_layerData.layerType == BaseLayer.LayerType.eLayerPK)
            {
                color = Color.blue;
            }
            else if (m_layerData.layerType == BaseLayer.LayerType.eLayerBoss)
            {
                color = Color.yellow;
            }
            else if (m_layerData.layerType == BaseLayer.LayerType.eLayerSafe)
            {
                color = Color.green;
            }
            else if (m_layerData.layerType == BaseLayer.LayerType.eLayerBattle)
            {
                color = Color.cyan;
            }
            else if (m_layerData.layerType == BaseLayer.LayerType.eLayer9Grid)
            {
                if (m_x % 2 == 0)
                {
                    if (m_z % 2 == 0)
                    {
                        color = Color.green;
                    }
                    else
                    {
                        color = Color.red;
                    }
                }
                else
                {
                    if (m_z % 2 == 0)
                    {
                        color = Color.red;
                    }
                    else
                    {
                        color = Color.green;
                    }
                }
            }
            color.a = 0.5f;

            SetColor(color);
            Position(ref vertices);
            Triangles(ref triangles);
            End();
            bUpdate = false;
        }