public override void OnEnter()
        {
            var  go   = Fsm.GetOwnerDefaultTarget(gameObject);
            Tile tile = null;

            if (UpdateCache(go))
            {
                STETilemap tilemap = cachedComponent as STETilemap;
                if ((ePositionType)positionType.Value == ePositionType.LocalPosition)
                {
                    tile = tilemap.GetTile(position.Value);
                }
                else// if ((ePositionType)positionType.Value == ePositionType.GridPosition)
                {
                    tile = tilemap.GetTile((int)position.Value.x, (int)position.Value.y);
                }
                if (tile == null)
                {
                    parameterValue.Value = defaultValue.Value;
                }
                else
                {
                    parameterValue.Value = tile.paramContainer.GetObjectParam(parameterName.Value, defaultValue.Value);
                }
            }

            Finish();
        }
Пример #2
0
    public void ExportRoom(bool conflict)
    {
        roomDataList = new List <TileDataCustom>();

        //Create a directory path based on the selected theme and room type, and append any identifiers to the filename
        directory = GetPath() + roomTheme.ToString() + "/" + roomType.ToString();
        Directory.CreateDirectory(directory);
        directory += "/" + filename + "_" + roomTheme.ToString() + "_" + roomType.ToString() + "_" + roomIdentifier;

        //Conflict handling - if automatically handled (shouldn't have got to this point otherwise, but best to be safe), add an index to the filename that is free/unique.
        if (!conflict)
        {
            directory += ".csv";
        }
        else if (conflict && autoNameConflictResolution)
        {
            bool indexFree = false;
            int  counter   = 1;

            while (!indexFree)
            {
                if (!CheckForExistingRooms(directory + "_" + counter.ToString() + ".csv"))
                {
                    Debug.Log("Room name (" + directory + ") already taken, appending index to distinguish between room identities.");

                    directory += "_" + counter.ToString() + ".csv";
                    indexFree  = true;
                }
                else
                {
                    counter++;
                }
            }
        }

        //If the file already exists, delete it and overwrite it.
        if (File.Exists(directory))
        {
            System.IO.File.Delete(directory);
            Debug.Log("Deleting existing room file to overwrite");
        }

        //Create and configure the CSV/text writers
        textWriter = File.CreateText(directory);
        csvWriter  = new CsvWriter(textWriter);
        csvWriter.Configuration.RegisterClassMap <RoomTileDataMap>();
        csvWriter.WriteHeader <RoomData>();
        csvWriter.NextRecord();

        //For every tile on the tilemap, loop through and create a TileDataCustom object based on all of its data and parameters
        for (int x = tileMap.MinGridX; x < tileMap.GridWidth; x++)
        {
            for (int y = tileMap.MinGridY; y < tileMap.GridHeight; y++)
            {
                uint     tileDataRaw = tileMap.GetTileData(x, y);
                Tile     tile        = tileMap.GetTile(x, y);
                TileData tileData    = new TileData(tileDataRaw);

                bool isMutateable    = false;
                bool isChunkTemplate = false;
                if (tile != null)
                {
                    isMutateable    = tile.paramContainer.GetBoolParam("mutateable");
                    isChunkTemplate = tile.paramContainer.GetBoolParam("isChunkTemplate");
                    if (isChunkTemplate)
                    {
                        Debug.Log(new Vector2(x, y));
                    }
                }
                data = new TileDataCustom(tileData.tileId, new Vector2(x, y), isMutateable, isChunkTemplate);
                roomDataList.Add(data);
            }
        }

        //Pass data to writing function that actually handles the file writing
        WriteDataToCSV();
    }