static void ParseImagePlist(int firstGid, int tileWidth, int tileHeight, string filename, Dictionary<int, string> gidToFiles, NSDictionary tilesetCaches){
string path = filename + "-tp.txt";
NSDictionary plist = null;
if(tilesetCaches!=null)
plist = tilesetCaches.objectForKey<NSDictionary>(path);
if(plist==null)
plist = NSDictionary.DictionaryWithContentsOfFileFromResources(filename + "-tp.txt");
NSDictionary metaDataDict = plist.objectForKey<NSDictionary>("metadata");
NSDictionary framesDict = plist.objectForKey<NSDictionary>("frames");
int format = 0;
if (metaDataDict != null) {
format = metaDataDict.objectForKey<int> ("format");
}
int width = 0;
if (metaDataDict != null) {
Vector2 size = ccUtils.PointFromString ((string)metaDataDict ["size"]);
width = Mathf.RoundToInt(size.x);
} else {
NSDictionary texture = metaDataDict.objectForKey<NSDictionary>("texture");
width = texture.objectForKey<int>("width");
}
var enumerator = framesDict.GetEnumerator();
while (enumerator.MoveNext()) {
KeyValuePair<object, object> frameDictKeyValue = enumerator.Current;
string frameDictKey = (string)frameDictKeyValue.Key;
NSDictionary frameDict = (NSDictionary)frameDictKeyValue.Value;
int x=0, y=0, w=0, h=0;
if(format == 0) {
float ox = frameDict.objectForKey<float>("x");
float oy = frameDict.objectForKey<float>("y");
float ow = frameDict.objectForKey<float>("width");
float oh = frameDict.objectForKey<float>("height");
x = Mathf.RoundToInt(ox);
y = Mathf.RoundToInt(oy);
w = Mathf.RoundToInt(ow);
h = Mathf.RoundToInt(oh);
} else if(format == 1 || format == 2) {
Rect frame = ccUtils.RectFromString(frameDict.objectForKey<string>("frame"));
x = Mathf.RoundToInt(frame.x);
y = Mathf.RoundToInt(frame.y);
w = Mathf.RoundToInt(frame.width);
h = Mathf.RoundToInt(frame.height);
} else if(format == 3) {
Rect frame = ccUtils.RectFromString(frameDict.objectForKey<string>("textureRect"));
x = Mathf.RoundToInt(frame.x);
y = Mathf.RoundToInt(frame.y);
w = Mathf.RoundToInt(frame.width);
h = Mathf.RoundToInt(frame.height);
}else{
NSUtils.Assert(false, "cocos2d:CCTMXMap: Uknown TexturePack format.");
}
NSUtils.Assert(w==tileWidth && h==tileHeight, "cocos2d:CCTMXMap: Frame size of tileset file must be same with tmx tilesize.");
int col = Mathf.RoundToInt(x / tileWidth);
int row = Mathf.RoundToInt(y / tileHeight);
int cols = Mathf.RoundToInt(width / tileWidth);
int gid = firstGid + col + row * cols;
gidToFiles[gid] = frameDictKey;
}
}