示例#1
0
文件: MapChunk.cs 项目: Hengle/Maze-1
    /// <summary>
    /// Activate the chunk at this coordinate - this comes before initializing
    /// </summary>
    /// <param name="width">
    ///The width of this chunk in blocks
    /// </param>
    /// <param name="height">
    ///The height of this chunk in blocks
    /// </param>
    /// <param name="parentMap">
    ///The map to which this chunk should be bound
    /// </param>
    public void Editor_Activate(int width, int height, int x, int y, int depth, BlockMap parentMap, bool positionAbsolute)
    {
        this.parentMap = parentMap;
        this.width     = width;
        this.height    = height;

        this.x     = x;
        this.y     = y;
        this.depth = depth;

        if (!positionAbsolute)
        {
            for (int x1 = this.x - 1; x1 <= this.x + 1; x1++)
            {
                for (int y1 = this.y - 1; y1 <= this.y + 1; y1++)
                {
                    if (x1 == x && y1 == y)
                    {
                        continue;
                    }

                    if (parentMap.HasChunkAt(x1, y1, depth))
                    {
                        MapChunk chunk = parentMap.GetChunkAt(x1, y1, depth, false);

                        int difference_x = x1 - this.x;
                        int difference_y = y1 - this.y;

                        Vector3 pos = Vector3.zero;

                        transform.parent = parentMap.transform;

                        transform.localPosition = pos;

                        float diff_dist_x = difference_x * (parentMap.tileScale.x * width);
                        float diff_dist_y = -(difference_y * (parentMap.tileScale.y * height));

                        if (parentMap.growthAxis == BlockMap.GrowthAxis.Up)
                        {
                            pos = new Vector3(
                                chunk.transform.localPosition.x + diff_dist_x,
                                chunk.transform.localPosition.y - diff_dist_y,
                                (depth * parentMap.tileScale.z)
                                );

                            transform.localRotation = Quaternion.identity;
                        }
                        else if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward)
                        {
                            pos = new Vector3(
                                chunk.transform.localPosition.x + diff_dist_x,
                                (depth * parentMap.tileScale.z),
                                chunk.transform.localPosition.z - diff_dist_y
                                );

                            transform.localRotation = Quaternion.Euler(
                                new Vector3(
                                    90.0f,
                                    0.0f,
                                    0.0f
                                    ));
                        }

                        transform.localPosition = pos;

                        transform.localScale = new Vector3(
                            parentMap.tileScale.x * width,
                            parentMap.tileScale.y * height,
                            parentMap.tileScale.z
                            );

                        return;
                    }
                }
            }
        }

        Vector3 localPos = Vector3.zero;

        if (positionAbsolute)
        {
            if (parentMap.growthAxis == BlockMap.GrowthAxis.Up)
            {
                localPos = new Vector3(-x * width, -y * height, 0.0f);
            }
            else
            {
                //if(parentMap.growthAxis == BlockMap.GrowthAxis.Up){
                localPos = new Vector3(-x * width, 0.0f, -y * height);
                //}
            }
        }

        transform.parent     = parentMap.transform;
        transform.localScale = new Vector3(
            parentMap.tileScale.x * width,
            parentMap.tileScale.y * height,
            parentMap.tileScale.z
            );

        transform.localPosition = localPos;

        if (parentMap.growthAxis == BlockMap.GrowthAxis.Up)
        {
            transform.localRotation = Quaternion.identity;
        }
        else if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward)
        {
            transform.localRotation = Quaternion.Euler(
                new Vector3(
                    90.0f,
                    0.0f,
                    0.0f
                    ));
        }
    }
示例#2
0
    /// <summary>
    /// Activate the chunk at this coordinate - this comes before initializing
    /// </summary>
    /// <param name="width">
    ///The width of this chunk in blocks
    /// </param>
    /// <param name="height">
    ///The height of this chunk in blocks
    /// </param>
    /// <param name="parentMap">
    ///The map to which this chunk should be bound
    /// </param>
    public void Editor_Activate(int width, int height, int x, int y, int depth, BlockMap parentMap, bool positionAbsolute)
    {
        this.parentMap = parentMap;
        this.width = width;
        this.height = height;

        this.x = x;
        this.y = y;
        this.depth = depth;

        if(!positionAbsolute){

            for(int x1 = this.x-1; x1 <= this.x+1; x1++){
                for(int y1 = this.y-1; y1 <= this.y+1; y1++){

                    if(x1 == x && y1 == y){
                        continue;
                    }

                    if(parentMap.HasChunkAt(x1,y1,depth)){

                        MapChunk chunk = parentMap.GetChunkAt(x1,y1,depth,false);

                        int difference_x = x1 - this.x;
                        int difference_y = y1 - this.y;

                        Vector3 pos = Vector3.zero;

                        transform.parent = parentMap.transform;

                        transform.localPosition = pos;

                        float diff_dist_x = difference_x * (parentMap.tileScale.x * width);
                        float diff_dist_y = -(difference_y * (parentMap.tileScale.y * height));

                        if(parentMap.growthAxis == BlockMap.GrowthAxis.Up){

                            pos = new Vector3(
                                                      chunk.transform.localPosition.x + diff_dist_x,
                                                      chunk.transform.localPosition.y - diff_dist_y,
                                                      (depth * parentMap.tileScale.z)
                                                      );

                            transform.localRotation = Quaternion.identity;

                        }
                        else if(parentMap.growthAxis == BlockMap.GrowthAxis.Forward ){

                            pos = new Vector3(
                                                      chunk.transform.localPosition.x + diff_dist_x,
                                              		  (depth * parentMap.tileScale.z),
                                                      chunk.transform.localPosition.z - diff_dist_y
                                                      );

                            transform.localRotation = Quaternion.Euler(
                                                                       new Vector3(
                                                                                   90.0f,
                                                                                   0.0f,
                                                                                   0.0f
                                                                                   ));

                        }

                        transform.localPosition = pos;

                        transform.localScale = new Vector3(
                                                           parentMap.tileScale.x * width,
                                                           parentMap.tileScale.y * height,
                                                           parentMap.tileScale.z
                                                           );

                        return;
                    }

                }
            }
        }

        Vector3 localPos = Vector3.zero;

        if(positionAbsolute){

            if(parentMap.growthAxis == BlockMap.GrowthAxis.Up){
                localPos = new Vector3(-x * width,-y*height,0.0f);
            }
            else{
                //if(parentMap.growthAxis == BlockMap.GrowthAxis.Up){
                localPos = new Vector3(-x * width,0.0f,-y*height);
                //}
            }
        }

        transform.parent = parentMap.transform;
        transform.localScale = new Vector3(
                                           parentMap.tileScale.x * width,
                                           parentMap.tileScale.y * height,
                                           parentMap.tileScale.z
                                           );

        transform.localPosition = localPos;

        if(parentMap.growthAxis == BlockMap.GrowthAxis.Up){

            transform.localRotation = Quaternion.identity;

        }
        else if(parentMap.growthAxis == BlockMap.GrowthAxis.Forward ){

            transform.localRotation = Quaternion.Euler(
                                                       new Vector3(
                                                                   90.0f,
                                                                   0.0f,
                                                                   0.0f
                                                                   ));

        }
    }