当前位置: 首页>>代码示例>>C#>>正文


C# Chunk.GetColliderBuffer方法代码示例

本文整理汇总了C#中Chunk.GetColliderBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Chunk.GetColliderBuffer方法的具体用法?C# Chunk.GetColliderBuffer怎么用?C# Chunk.GetColliderBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chunk的用法示例。


在下文中一共展示了Chunk.GetColliderBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildBoxColliders

    /// <summary>
    /// Builds the collider data for the given chunk
    /// 
    /// Uses an expansion algorithm similar to buildMeshCombined, however since we are not building faces (6 sides)
    /// It is slightly simpler
    /// </summary>
    private void BuildBoxColliders(Chunk chunk)
    {
        ColliderBuffer buffer = chunk.GetColliderBuffer();

        // Request the lock, and block until it is obtained.
          	Monitor.Enter(buffer);

        buffer.Clear();

        UnityEngine.Debug.Log ("Begin building Colliders");

        //create a 3d array to keep track if each block has been contained by a collider, default is false
        bool[][][] contained = new bool[chunk.width][][];
        for (int x=0; x<chunk.width; x++)
        {
            contained[x] = new bool[chunk.height][];
            for (int y=0; y<chunk.height; y++)
            {
                contained[x][y] = new bool[chunk.length];
            }
        }

        for (int x=0; x<chunk.width; x++)
        {
            for (int z=0; z<chunk.length; z++)
            {
                for (int y=0; y<chunk.height; y++)
                {
                    //don't put colliders over already contained blocks or blocks that should not have collision
                    if (contained[x][y][z] || !Block.IsSolid(chunk[x,y,z]))
                        continue;

                    int width   = 1;
                    int height  = 1;
                    int length  = 1;

                    bool expandHeight = !(y == chunk.height-1);
                    bool expandWidth  = !(x == chunk.width-1);
                    bool expandLength = !(z == chunk.length-1);

                    do
                    {
                        if (expandWidth)
                        {
                            for (int iy = 0; iy<height; iy++)
                            {
                                for (int iz = 0; iz<length; iz++)
                                {
                                    if (!Block.IsSolid(chunk[x+width,y+iy,z+iz]) || contained[x+width][y+iy][z+iz])
                                    {
                                        expandWidth = false;
                                        break;
                                    }
                                }
                            }

                            if (expandWidth)
                            {
                                for (int iy = 0; iy<height; iy++)
                                {
                                    for (int iz = 0; iz<length; iz++)
                                    {
                                        contained[x+width][y+iy][z+iz] = true;
                                    }
                                }

                                width++;
                                if (x + width >= chunk.width)
                                    expandWidth = false;
                            }
                        }

                        if (expandHeight)
                        {
                            for (int ix=0; ix < width; ix++)
                            {
                                for (int iz=0; iz<length; iz++)
                                {
                                    if (!Block.IsSolid(chunk[x+ix,y+height,z+iz]) || contained[x+ix][y+height][z+iz])
                                    {
                                        expandHeight = false;
                                        break;
                                    }
                                }
                            }

                            if (expandHeight)
                            {
                                for (int ix=0; ix < width; ix++)
                                {
                                    for (int iz=0; iz<length; iz++)
                                    {
                                        contained[x+ix][y+height][z+iz] = true;
                                    }
//.........这里部分代码省略.........
开发者ID:silantzis,项目名称:swarm,代码行数:101,代码来源:ColliderProcessor.cs

示例2: BuildMeshCollider

    /// <summary>
    /// Builds an mesh optimizing triangles and vertices where possible
    ///
    /// This function must first pass over the chunk and build a facelist, byte[][][] array containing the faces that should be rendered for each block
    /// The function will then loop over the chunk again to expand each face as much as possible, reducing the overall number of verices and triangles.
    /// </summary>
    private void BuildMeshCollider(Chunk chunk)
    {
        //get this chunks water buffer
        ColliderBuffer buffer = chunk.GetColliderBuffer();

        // Request the lock, and block until it is obtained.
          	Monitor.Enter(buffer);

        //clear this buffer for the new rebuild
        buffer.Clear();

        // NOTE: BuildFaceList must pass over the entire chunk once
        byte[][][] faces = BuildFaceList(chunk);

        for (int x=0; x<chunk.width; x++)
        {
            for (int y=0; y<chunk.height; y++)
            {
                for (int z=0; z<chunk.length; z++)
                {
                    // bitmask containing the faces to cover for this block
                    byte face = faces[x][y][z];

                    if (face != 0)
                    {
                        if ((face & (byte)FACEMASK.BACK) != 0)
                        {
                            #region EXPAND FACE
                            int width   = 1;
                            int height  = 1;

                            bool expandWidth  = !(x == chunk.width-1);
                            bool expandHeight = !(y == chunk.height-1);

                            do
                            {
                                if (expandWidth)
                                {
                                    for (int iy=0; iy < height; iy++)
                                    {
                                        //does it NOT contain this face
                                        if ((faces[x+width][y+iy][z] & (byte)FACEMASK.BACK) == 0)
                                        {
                                            expandWidth = false;
                                        }
                                    }
                                }

                                if (expandWidth)
                                {
                                    for (int iy=0; iy < height; iy++)
                                    {
                                        faces[x+width][y+iy][z] ^= (byte)FACEMASK.BACK;
                                    }

                                    width++;
                                    if (x + width >= chunk.width)
                                        expandWidth = false;
                                }

                                if (expandHeight)
                                {
                                    for (int ix=0; ix < width; ix++)
                                    {
                                        //does it NOT contain this face
                                        if ((faces[x+ix][y+height][z] & (byte)FACEMASK.BACK) == 0)
                                        {
                                            expandHeight = false;
                                        }
                                    }
                                }

                                if (expandHeight)
                                {
                                    for (int ix=0; ix < width; ix++)
                                    {
                                        faces[x+ix][y+height][z] ^= (byte)FACEMASK.BACK;
                                    }

                                    height++;
                                    if (y + height >= chunk.height)
                                        expandHeight = false;
                                }
                            } while (expandWidth || expandHeight);
                            #endregion
                            buffer.AddFace(FACE.BACK, x,y,z, new Vector3(width, height, 1));
                        }

                        if ((face & (byte)FACEMASK.TOP) != 0)
                        {
                            #region EXPAND FACE
                            int width   = 1;
                            int length  = 1;

//.........这里部分代码省略.........
开发者ID:silantzis,项目名称:swarm,代码行数:101,代码来源:ColliderProcessor.cs


注:本文中的Chunk.GetColliderBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。