Beispiel #1
0
    public GameObject Spawn(string level)
    {
        var pieces = new Dictionary <MapPiece, GameObject>
        {
            { MapPiece.Floor, floor },
            { MapPiece.FailsafeFloor, failsafeFloor },
            { MapPiece.Root, root },
            { MapPiece.RootKey, rootKey },
            { MapPiece.DataCube, dataCube },
            { MapPiece.Routine, subroutine },
            { MapPiece.DoubleRoutine, doubleSubroutine },
            { MapPiece.JumpingRoutine, jumpingSubroutine }
        };

        var map      = TokenizedLevelMap.FromString(level);
        var iterator = new TwoDimensionalIterator(map.Width, map.Height);
        var obj      = new GameObject();

        iterator.Select(p => new TilePoint(p.Item1, p.Item2)).ForEach(t =>
        {
            Instantiate(pieces[map.FloorLayer[t.X, t.Y]], new Vector3(t.X, t.Y, 0), Quaternion.identity, obj.transform);
            Instantiate(pieces[map.ObjectLayer[t.X, t.Y]], new Vector3(t.X, t.Y, 0), Quaternion.identity, obj.transform);
        });

        return(obj);
    }
    public void ExportToFile()
    {
        var path        = Path.Combine(Application.dataPath, $"{Guid.NewGuid().ToString()}");
        var levelString = new TokenizedLevelMap(_builder.Build()).ToString();

        File.WriteAllBytes(path, Encoding.UTF8.GetBytes(levelString));
        Debug.Log($"Wrote Level to {path}");
    }