void loadInDirs(string filePath) // recursively loops all dirs and loads their spritesheet { string[] subDirectories = System.IO.Directory.GetDirectories(filePath); if (subDirectories.Length > 0) { for (int i = 0; i < subDirectories.Length; i++) { loadInDirs(subDirectories[i]); } } else { string[] fileNames = System.IO.Directory.GetFiles(filePath); for (int i = 0; i < fileNames.Length; i++) { if (fileNames[i].Contains(".png")) // we only want to load .png files // NOTE this will load any file that contains .png, not just ones that have it at the end { if (!fileNames[i].Contains(".meta")) // only call if its NOT a meta file { sheetIndex index = getIndexData(fileNames[i]); this.spriteSheets.Add(index.sheetName, loadSpriteSheet(fileNames[i])); } } } } }
sheetIndex getIndexData(string filePath) // gets data from <index> { string baseSpritePath = System.IO.Path.GetFileNameWithoutExtension(filePath); string xmlPath = System.IO.Path.Combine(System.IO.Directory.GetParent(filePath).FullName, baseSpritePath + ".xml"); // NOTE the xml extension must be in LOWER CASE XmlTextReader reader = new XmlTextReader(xmlPath); if (!reader.ReadToDescendant("index")) { Debug.LogError("spriteManager::getIndexData: No <index> in " + xmlPath); return(null); } string name = null; string author = null; string pivot = null; int pixelsPer = 0; Vector2 point = new Vector2(); name = xmlHelperManager.getStringRequired("sheetName", reader); author = xmlHelperManager.getStringRequired("author", reader); pivot = xmlHelperManager.getStringDefault("pivot", "BL", reader); pixelsPer = xmlHelperManager.getIntRequired("PPU", reader); if (pivot == "C") // TODO support more pivots { point = new Vector2(0.5f, 0.5f); } else { point = new Vector2(0.0f, 0.0f); } sheetIndex tmpIndex = new sheetIndex(); tmpIndex.sheetName = name; tmpIndex.author = author; tmpIndex.pivotPoint = point; tmpIndex.PPU = pixelsPer; return(tmpIndex); }