public void InitWithFile(string fileName) { PlistDocument document = CCContentManager.SharedContentManager.Load <PlistDocument>(fileName); var dict = document.Root.AsDictionary; var texturePath = string.Empty; plistFilePath = string.Empty; plistType = GetPlistType(dict); if (plistType == PlistType.SpriteKit) { var images = dict.ContainsKey("images") ? dict ["images"].AsArray : null; var imageDict = images [0].AsDictionary; if (imageDict != null) { // try to read texture file name from meta data if (imageDict.ContainsKey("path")) { texturePath = imageDict ["path"].AsString; } } } else { var metadataDict = dict.ContainsKey("metadata") ? dict ["metadata"].AsDictionary : null; if (metadataDict != null) { // try to read texture file name from meta data if (metadataDict.ContainsKey("textureFileName")) { texturePath = metadataDict ["textureFileName"].AsString; } } } if (!string.IsNullOrEmpty(texturePath)) { // build texture path relative to plist file texturePath = CCFileUtils.FullPathFromRelativeFile(texturePath, fileName); } else { // build texture path by replacing file extension texturePath = fileName; // remove .xxx texturePath = CCFileUtils.RemoveExtension(texturePath); CCLog.Log("cocos2d: CCSpriteFrameCache: Trying to use file {0} as texture", texturePath); } plistFilePath = Path.GetDirectoryName(texturePath); CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(texturePath); if (pTexture != null) { InitWithDictionary(dict, pTexture); } else { CCLog.Log("CCSpriteSheet: Couldn't load texture"); } }
/// <summary> /// /// </summary> /// <param name="pszPlist"></param> /// <returns>The scope parameter derived from the pszPlist parameter.</returns> public string AddSpriteFramesWithFile(string pszPlist) { string path = CCFileUtils.FullPathFromRelativePath(pszPlist); //Dictionary<string, Object> dict = CCFileUtils.dictionaryWithContentsOfFile(pszPath); PlistDocument document = null; try { document = CCApplication.SharedApplication.Content.Load <PlistDocument>(path); } catch (System.Exception) { string xml = Cocos2D.Framework.CCContent.LoadContentFile(path); if (xml != null) { document = new PlistDocument(xml); } } if (document == null) { throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the particle definition file from " + path)); } PlistDictionary dict = document.Root.AsDictionary; string texturePath = ""; PlistDictionary metadataDict = dict.ContainsKey("metadata") ? dict["metadata"].AsDictionary : null; string framePrefix = string.Empty; if (metadataDict != null) { // try to read texture file name from meta data if (metadataDict.ContainsKey("textureFileName")) { texturePath = metadataDict["textureFileName"].AsString; framePrefix = ExtractPrefix(texturePath); } } if (!string.IsNullOrEmpty(texturePath)) { // build texture path relative to plist file texturePath = CCFileUtils.FullPathFromRelativeFile(texturePath, path); } else { // build texture path by replacing file extension texturePath = path; // remove .xxx texturePath = CCFileUtils.RemoveExtension(texturePath); CCLog.Log("cocos2d: CCSpriteFrameCache: Trying to use file {0} as texture", texturePath); } CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(texturePath); if (pTexture != null) { AddSpriteFramesWithDictionary(dict, pTexture, framePrefix); } else { CCLog.Log("cocos2d: CCSpriteFrameCache: Couldn't load texture"); } return(framePrefix); }