Esempio n. 1
0
    public static MagicCube CreateFromSerializedData(SaveGameSystem.SerializableCubeData data, int individualCubeSizeInWorldUnits, IndividualCubeController individualCubePrefab)
    {
        //Generate cube from data
        var newCube = new MagicCube(data.gameSize, individualCubeSizeInWorldUnits, individualCubePrefab);

        foreach (var cube in data.cubeData)
        {
            var cubego = newCube.CreateSubCube(cube.currentCoordinates.x, cube.currentCoordinates.y, cube.currentCoordinates.z, cube.goalCoordinates);
            cubego.transform.localRotation = cube.rotation;
        }

        return(newCube);
    }
Esempio n. 2
0
    //Creates the entire Rubik cube out of smaller cubes that make up a "shell"
    public static MagicCube CreateFromNewGame(int gameSize, float individualCubeSizeInWorldUnits, IndividualCubeController individualCubePrefab)
    {
        Debug.Assert(gameSize > 1);
        var newCube = new MagicCube(gameSize, individualCubeSizeInWorldUnits, individualCubePrefab);

        //Possibly this could be refactored into a helper method that creates planes of cubes of a certain side

        //X plates (full size)
        for (int j = 0; j < gameSize; j++)
        {
            for (int k = 0; k < gameSize; k++)
            {
                newCube.CreateSubCube(0, j, k);
            }
        }

        for (int j = 0; j < gameSize; j++)
        {
            for (int k = 0; k < gameSize; k++)
            {
                newCube.CreateSubCube(gameSize - 1, j, k);
            }
        }

        //Second plates (smaller)

        //y plates
        for (int i = 1; i < gameSize - 1; i++)
        {
            for (int k = 0; k < gameSize; k++)
            {
                newCube.CreateSubCube(i, 0, k);
            }
        }

        for (int i = 1; i < gameSize - 1; i++)
        {
            for (int k = 0; k < gameSize; k++)
            {
                newCube.CreateSubCube(i, gameSize - 1, k);
            }
        }

        //Z plates
        for (int i = 1; i < gameSize - 1; i++)
        {
            for (int j = 1; j < gameSize - 1; j++)
            {
                newCube.CreateSubCube(i, j, 0);
            }
        }

        for (int i = 1; i < gameSize - 1; i++)
        {
            for (int j = 1; j < gameSize - 1; j++)
            {
                newCube.CreateSubCube(i, j, gameSize - 1);
            }
        }

        // Code for a full cube
        //for (int i = 0; i<gameSize ; i++) {
        //    for (int j = 0; j<gameSize ; j++) {
        //        for (int k = 0; k<gameSize ; k++) {
        //            var newCube = GameObject.Instantiate(this.individualCubePrefab, cubesParent);

        //            newCube.transform.position =
        //                CubeCoordinatesToWorld(i,j,k);

        //            //Cube was placed, now let's do housekeeping
        //            newCube.goalCoordinates = new Vector3Int(i,j,k);
        //            newCube.currentCoordinates = newCube.goalCoordinates;
        //            allCubes.Add(newCube);
        //        }
        //    }
        //}
        return(newCube);
    }