Пример #1
0
        public CCSpriteSheet(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("CocosSharp: 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");
            }
        }