private IEnumerator loadTextureFromPath(DTileSet ts) { string res_path = ts.res_path; String filePath = Application.persistentDataPath + res_path; if (!File.Exists(filePath)) { filePath = Application.streamingAssetsPath + res_path; } bool ok = false; if (File.Exists(filePath)) { WWW www = new WWW("file:///" + filePath); yield return(www); if (www.error == null) { tilesetTextureMap.Add(ts, www.texture); ok = true; } } if (!ok) { WWW www = new WWW(filePath); yield return(www); tilesetTextureMap.Add(ts, www.texture); } }
private IEnumerator loadTextureFromName(DTileSet ts) { string res_name = ts.res_name; String filePath = Application.persistentDataPath + "/textures/" + res_name + ".png"; if (!File.Exists(filePath)) { filePath = Application.persistentDataPath + "/textures/" + res_name + ".jpg"; } if (!File.Exists(filePath)) { filePath = Application.streamingAssetsPath + "/textures/" + res_name + ".png"; } if (!File.Exists(filePath)) { filePath = Application.streamingAssetsPath + "/textures/" + res_name + ".jpg"; } bool ok = false; if (File.Exists(filePath)) { WWW www = new WWW("file:///" + filePath); yield return(www); if (www.error != null) { tilesetTextureMap.Add(ts, www.texture); ok = true; } } if (!ok) { WWW www = new WWW(filePath); yield return(www); if (www.error == null) { tilesetTextureMap.Add(ts, Resources.Load("textures/" + res_name) as Texture2D); } tilesetTextureMap.Add(ts, www.texture); } }
void LoadTileset(DTileSet ts) { if (_lastgid == 0) { Color[] emptytile = new Color[textureResolution * textureResolution]; for (int x = 0; x < (textureResolution * textureResolution); x++) { emptytile[x] = new Color(0, 0, 0); } tiles.Add(0, emptytile); } Texture2D tex = _maploader.tilesetTextureMap[ts]; if (textureResolution != (tex.width / ts.columns)) { Debug.LogWarning("tileset resolution not equal to map resolution"); } if (_lastgid > ts.firstgid) { Debug.LogWarning("Tileset First GID " + ts.firstgid + " is smaller than the last used GID " + _lastgid); } _lastgid = ts.firstgid; int numRows = tex.height / textureResolution; for (int id = 1; id <= ts.count; id++, _lastgid++) { int row = (id - 1) / ts.columns; int idOfRow = (id - 1) - (ts.columns * row); int invertedRow = numRows - row - 1; tiles.Add(_lastgid, tex.GetPixels(idOfRow * textureResolution, invertedRow * textureResolution, textureResolution, textureResolution)); } }