public LoadText ( string text, bool skipZero = true ) : void | ||
text | string | |
skipZero | bool | |
return | void |
public void LoadText(string text, bool skipZero=true)
{
int zeroCount = 0;
// remember for later
_skipZero = skipZero;
string[] lines = text.Split('\n');
int i = 0;
int j = 0;
// set width/height
string[] firstLine = lines[0].Split(',');
_tilesWide = firstLine.GetLength(0);
if (firstLine[firstLine.GetLength(0)-1] == "") {
_tilesWide -= 1;
}
_tilesHigh = lines.GetLength(0);
// set array
_tileArray = new int[_tilesWide * _tilesHigh];
foreach (string line in lines) {
if (line != "") { // skip empty rows
// split into individual numbers
string[] frames = line.Split(',');
i = 0;
foreach (string frame in frames) {
if (frame != "") {
// keep track of all frames
int frameNum = int.Parse(frame);
_tileArray[i+(j*_tilesWide)] = frameNum;
if (frameNum == 0) {
zeroCount++;
}
i++;
}
}
j++;
}
}
// get tile width/height
FAtlasElement element = Futile.atlasManager.GetElementWithName(_baseName+"_1");
_tileWidth = element.sourceSize.x;
_tileHeight = element.sourceSize.y;
// warning if skipZero would give better results
if (_clipWidth > 0 && _clipHeight > 0 && _clipNode != null) {
int clipTilesWide = Mathf.CeilToInt(_clipWidth / _tileWidth) + 2;
int clipTilesHigh = Mathf.CeilToInt(_clipHeight / _tileHeight) + 2;
if (zeroCount > clipTilesWide * clipTilesHigh) {
Debug.Log ("FTilemap would use less memory if _skipZero was true.");
_skipZero = true;
clipToScreen = false;
}
}
buildTiles();
}
virtual protected FNode createTilemap(XMLNode node) { XMLNode csvData = new XMLNode(); XMLNode properties = new XMLNode(); foreach (XMLNode child in node.children) { if (child.tagName == "data") { csvData = child; } else if (child.tagName == "properties") { properties = child; } } // make sure encoding is set to csv if (csvData.attributes["encoding"] != "csv") { Debug.Log("FTiledScene: Could not render layer data, encoding set to: " + csvData.attributes["encoding"]); return(null); } // remember name _layerNames.Add(node.attributes["name"]); // skipZero, if this is true all filled tiles will be drawn without clipping bool skipZero = false; // do stuff with properties foreach (XMLNode property in properties.children) { // check each property if (property.attributes["name"] == "skipZero") { skipZero = bool.Parse(property.attributes["value"]); } } // get text for csv data string csvText = csvData.value; string firstFrame = csvText.Substring(0, csvText.IndexOf(',')); int firstID = RemoveFrameFlags(uint.Parse(firstFrame)); // find name of tileset being used, assumes all tiles are from the same tileset string baseName = this.getTilesetNameForID(firstID); // create tilemap FTilemap tilemap = new FTilemap(baseName); if (!skipZero) { tilemap.clipToScreen = true; tilemap.clipNode = _clipNode; } tilemap.LoadText(csvText, skipZero); return(tilemap); }