Esempio n. 1
0
    void OnSceneGUI()
    {
        MeshCombine mc = target as MeshCombine;

        if (Handles.Button(mc.transform.position + Vector3.up * 5, Quaternion.LookRotation(Vector3.up), 1, 1, Handles.CylinderHandleCap))
        {
            mc.CombineMeshes();
        }
    }
        static Mesh CreateSlopeMesh(Sprite sprite, Sprite sideSprite, Sprite backSprite, float height)
        {
            //
            Mesh main = SpriteTileGenerator.CreateMeshFromSprite(sprite);

            Vector3[] verts = main.vertices;
            for (int i = 0; i <= 1; i++)
            {
                verts[i] += Vector3.up * height;
            }
            main.SetVertices(verts);
            main.RecalculateNormals();
            main.RecalculateTangents();

            if (sideSprite)
            {
                Mesh[] partials = new Mesh[4]; // two quads, two tris
                partials[0] = main;
                partials[1] = CreatePartialQuad(backSprite ?? sideSprite, height);
                TransformMesh(partials[1],
                              Quaternion.Euler(270f, 90f, 90f),
                              new Vector3(0f, 0.5f, 0.5f));

                partials[2] = CreatePartialTris(sideSprite, height);
                TransformMesh(partials[2],
                              Quaternion.Euler(90f, 90f, 0f),
                              new Vector3(0.5f, 0.5f, 0f));

                partials[3] = CreatePartialTris(sideSprite, height);
                TransformMesh(partials[3],
                              Quaternion.Euler(90f, 90f, 0f),
                              new Vector3(-0.5f, 0.5f, 0f));

                partials[3].triangles = new int[] { partials[3].triangles[2], partials[3].triangles[1], partials[3].triangles[0] };

                return(MeshCombine.CombineMeshes(partials));
            }
            else
            {
                return(main);
            }
            //return CreatePartialQuad(sprite, height);
        }
 static Mesh CreateBlockMesh(Sprite sprite, Sprite topSprite)
 {
     Mesh[] partials = new Mesh[5];
     for (int i = 0; i <= 3; i++)
     {
         partials[i] = SpriteTileGenerator.CreateMeshFromSprite(sprite);
         TransformMesh(partials[i],
                       Quaternion.Euler(270f, 90f + 90f * i, 90f),
                       Vector3.up * 0.5f
                       + Quaternion.Euler(0f, 90f * i, 0f).normalized *Vector3.forward * 0.5f);
     }
     if (topSprite)
     {
         partials[4] = SpriteTileGenerator.CreateMeshFromSprite(topSprite);
         TransformMesh(partials[4],
                       Quaternion.Euler(0f, 0f, 0f),
                       Vector3.up * 1f);
     }
     return(MeshCombine.CombineMeshes(partials));
 }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        var rocksObjects = GameObject.FindGameObjectsWithTag("BedRock");

        for (int f = 0; f < rocksObjects.Length; f++)
        {
            rocksObjects[f].transform.parent = underGroundRock_Object.gameObject.transform;
        }


        //spawn cell
        if (!cellSpawned)
        {
            for (i = 0; (i < maxBlocksPerCell) && (currentRow != maxRows); i++)
            {
                if (SelectNewBiome)
                {
                    float y = Random.Range(0.0f, 10.0f);

                    currentRandomNumber = y;
                    {
                        if (y < 3.0f)
                        {
                            Grassland      = true;
                            MudLand        = false;
                            Forest         = false;
                            SelectNewBiome = false;
                        }

                        else if (y > 5.0f && y < 7.0f)
                        {
                            MudLand        = true;
                            Grassland      = false;
                            Forest         = false;
                            SelectNewBiome = false;
                        }

                        else if (y > 7.0f)
                        {
                            MudLand        = false;
                            Grassland      = false;
                            Forest         = true;
                            SelectNewBiome = false;
                        }
                    }
                }


                float x = Random.Range(0.0f, 10.0f);
                {
                    if (Grassland)
                    {
                        if (x < 1)
                        {
                            CurrentBlock[i] = Grassland_block1;
                        }

                        else if (x < 2)
                        {
                            CurrentBlock[i] = Grassland_block3;
                        }

                        else if (x < 3)
                        {
                            CurrentBlock[i] = Grassland_block4;
                        }

                        else if (x < 4)
                        {
                            CurrentBlock[i] = Grassland_block5;
                        }

                        else
                        {
                            CurrentBlock[i] = Grassland_block2;
                        }
                    }

                    else if (MudLand)
                    {
                        if (x < 1)
                        {
                            CurrentBlock[i] = MudLand_block1;
                        }

                        else if (x < 2)
                        {
                            CurrentBlock[i] = MudLand_block2;
                        }

                        else if (x < 3)
                        {
                            CurrentBlock[i] = MudLand_block3;
                        }

                        else if (x < 4)
                        {
                            CurrentBlock[i] = MudLand_block4;
                        }

                        else
                        {
                            CurrentBlock[i] = MudLand_block5;
                        }
                    }

                    else if (Forest)
                    {
                        if (x < 1)
                        {
                            CurrentBlock[i] = Forest_block1;
                        }

                        else if (x < 2)
                        {
                            CurrentBlock[i] = Forest_block2;
                        }

                        else if (x < 3)
                        {
                            CurrentBlock[i] = Forest_block3;
                        }

                        else if (x < 4)
                        {
                            CurrentBlock[i] = Forest_block4;
                        }

                        else
                        {
                            CurrentBlock[i] = Forest_block5;
                        }
                    }
                }

                currentBlockproperties = CurrentBlock[i].gameObject.GetComponent <BlockProperties>();
                currentBlockproperties.blockCellLocation = BlockCell;

                if (i % 10 == 0)
                {
                    depthPos++;
                    widthPos = defaultWidthPos;
                }

                float heightToUse = Random.Range(0, maxHeightOffset);

                GameObject test = Instantiate(CurrentBlock[i], new Vector3(widthPos + (currentRow * 10), heightToUse, depthPos), Quaternion.identity);
                currentHeight = -1;

                test.transform.parent = Cell.transform;

                //Saving.blocksToSave[i] = CurrentBlock[i];

                meshFilters = CurrentBlock[i].gameObject.GetComponentsInChildren <MeshFilter>();



                for (int y = 0; y < MaxHeight; y++)
                {
                    float j = Random.Range(0.0f, 10.0f);
                    {
                        if (j < 1)
                        {
                            CurrentBlock[i] = UnderGround_Rock_block1;
                        }

                        else if (j < 2)
                        {
                            CurrentBlock[i] = UnderGround_Rock_block2;
                        }

                        else if (j < 3)
                        {
                            CurrentBlock[i] = UnderGround_Rock_block3;
                        }

                        else
                        {
                            CurrentBlock[i] = UnderGround_Rock_block4;
                            CurrentBlock[i].gameObject.tag = "BedRock";
                        }
                    }


                    test = Instantiate(CurrentBlock[i], new Vector3(widthPos + (currentRow * 10), heightToUse + currentHeight--, depthPos), Quaternion.identity);
                    test.transform.parent = Cell.transform;

                    y++;
                }

                test.name = total.ToString();
                total++;
                widthPos++;
            }


            if (currentRow == maxRows)
            {
                cellSpawned = true;
                underGroundRock_Combine.CombineMeshes(Cell);
            }

            if (i == maxBlocksPerCell)
            {
                BlockCell++;
                currentCell++;
                SelectNewBiome = true;
                i = 0;
                //total = 10 * currentCell;

                if (currentCell == maxCells)
                {
                    widthPos    = defaultWidthPos;
                    depthPos    = defaultDepthPos;
                    currentCell = 0;
                    currentRow++;
                    i = -1;
                }

                Cell      = new GameObject();
                Cell.name = "Cell Number :";
            }
        }
    }