コード例 #1
0
        public void SetFlag(float fX, float fZ, bool flag)
        {
            if (!m_obj.activeSelf)
            {
                Debug.LogError("操作失败 layertype:" + m_layerType);
                return;
            }
            int nX = (int)(fX / TerrainBlock.GRID_LEN);
            int nZ = (int)(fZ / TerrainBlock.GRID_LEN);

            if (nX < 0 || nX > m_layerData.GridX)
            {
                return;
            }
            if (nZ < 0 || nZ > m_layerData.GridZ)
            {
                return;
            }

            GridInfo grid = m_layerData.GetGrid(nX, nZ);

            grid.IsMask = flag;

            /* Debug.Log("set flag x" + nX + " z" + nZ);*/

            SetNodeNeedUpdate(nX, nZ);
        }
コード例 #2
0
        //     public override void LoadData(ref BinaryReader br)
        //     {
        //         for (int nIndex = 0; nIndex < m_layerData.VertexCountX * m_layerData.VertexCountZ; nIndex++)
        //         {
        //             ushort uValue = br.ReadUInt16();
        //             if (uValue == (ushort)AreaType.eBlock)
        //             {
        //                 m_layerData.SetFlag(nIndex, true);
        //             }
        //             else
        //             {
        //                 m_layerData.SetFlag(nIndex, false);
        //             }
        //         }
        //   }

        public override void SaveData(ref string path)
        {
            // mps 阻挡数据
            LayerData layerData   = m_layerData;
            uint      MAP_VERSION = 6;
            uint      MAP_MAGIC   = BitConverter.ToUInt32(Encoding.ASCII.GetBytes("SPMX"), 0);

            int          nOffset = 0;
            FileStream   fs      = new FileStream(path, FileMode.Create);
            BinaryWriter bw      = new BinaryWriter(fs);

            bw.Write(BitConverter.GetBytes(MAP_MAGIC), nOffset, 4);
            bw.Write(BitConverter.GetBytes(MAP_VERSION), nOffset, 4);
            bw.Write(BitConverter.GetBytes(layerData.GridX), nOffset, 4);
            bw.Write(BitConverter.GetBytes(layerData.GridZ), nOffset, 4);

            for (int z = 0; z < layerData.GridZ; z++)
            {
                for (int x = 0; x < layerData.GridX; x++)
                {
                    GridInfo pTemp = layerData.GetGrid(x, z);

                    bw.Write(BitConverter.GetBytes(pTemp.IsMask ? (ushort)Layer : (ushort)0), nOffset, 2);
                }
            }
            bw.Close();
            fs.Close();
        }
コード例 #3
0
ファイル: SafeLayer.cs プロジェクト: sjb8100/src
        //     public override void LoadData(ref BinaryReader br)
        //     {
        //         for (int nIndex = 0; nIndex < m_layerData.VertexCountX * m_layerData.VertexCountZ; nIndex++)
        //         {
        //             ushort uValue = br.ReadUInt16();
        //             if (uValue == (ushort)AreaType.eSafe)
        //             {
        //                 m_layerData.SetFlag(nIndex, true);
        //             }
        //             else
        //             {
        //                 m_layerData.SetFlag(nIndex, false);
        //             }
        //         }
        //  }

        public override void SaveData(ref string path)
        {
            // mps 阻挡数据
            LayerData    blockData = m_layerData;
            int          nOffset   = 0;
            FileStream   fs        = new FileStream(path, FileMode.Create);
            BinaryWriter bw        = new BinaryWriter(fs);

            for (int z = 0; z < blockData.GridZ; z++)
            {
                for (int x = 0; x < blockData.GridZ; x++)
                {
                    GridInfo pTemp = blockData.GetGrid(x, z);

                    bw.Write(BitConverter.GetBytes(pTemp.IsMask ? (ushort)Layer : (ushort)0), nOffset, 2);
                }
            }
            bw.Close();
            fs.Close();
        }
コード例 #4
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;
        }