예제 #1
0
        public Dictionary <string, AtlasFrame> GetAtlasFrameList(string atlasFullName, bool bRefresh = false)
        {
            if (!bRefresh)
            {
                if (allAtlasMap.ContainsKey(atlasFullName))
                {
                    return(allAtlasMap[atlasFullName]);
                }
            }
            else if (allAtlasMap.ContainsKey(atlasFullName))
            {
                allAtlasMap.Remove(atlasFullName);
            }

            PList plist = new PList();

            plist.Load(atlasFullName);

            Dictionary <string, AtlasFrame> atlases = new Dictionary <string, AtlasFrame>();

            Dictionary <string, object> frames = plist["frames"] as Dictionary <string, object>;

            string realTextureFileName = plist.GetValue <string>("metadata/realTextureFileName");
            string path = System.IO.Path.GetDirectoryName(atlasFullName);

            foreach (KeyValuePair <string, object> kv in frames)
            {
                string     frameName;
                AtlasFrame _atlas = createAtlas(realTextureFileName, path, kv, out frameName);
                atlases.Add(frameName, _atlas);
            }
            allAtlasMap.Add(atlasFullName, atlases);
            return(atlases);
        }
예제 #2
0
        private AtlasFrame createAtlas(string realTextureFileName, string path, KeyValuePair <string, object> kv,
                                       out string frameName)
        {
            string key = kv.Key;
            Dictionary <string, object> valueMap = kv.Value as Dictionary <string, object>;

            string frameRect = "";
            bool   bRotated  = false;

            if (valueMap.ContainsKey(str_frames))
            {
                frameRect = valueMap[str_frames].ToString();
                bRotated  = (bool)valueMap[str_rotated];
            }
            else if (valueMap.ContainsKey(str_textureRect))
            {
                frameRect = valueMap[str_textureRect].ToString();
                bRotated  = (bool)valueMap[str_textureRotated];
            }

            BitmapFrame bitmapFrame = null;

            if (atlasFrameMap.ContainsKey(realTextureFileName))
            {
                bitmapFrame = atlasFrameMap[realTextureFileName];
            }
            else
            {
                bitmapFrame = BitmapFrame.Create(new Uri(path + "/" + realTextureFileName, UriKind.Absolute));
                atlasFrameMap[realTextureFileName] = bitmapFrame;
            }
            int pointPos = key.LastIndexOf('.');

            frameName = key;
            if (pointPos != -1)
            {
                frameName = key.Substring(0, pointPos);
            }
            AtlasFrame   _atlas    = new AtlasFrame(frameRect, bRotated, frameName);
            BitmapSource imgSource = null;

            if (bRotated)
            {
                _atlas.frame.Width  = _atlas.frame.Width ^ _atlas.frame.Height;
                _atlas.frame.Height = _atlas.frame.Height ^ _atlas.frame.Width;
                _atlas.frame.Width  = _atlas.frame.Width ^ _atlas.frame.Height;
                TransformedBitmap tb = new TransformedBitmap();
                tb.BeginInit();
                imgSource = new CroppedBitmap(bitmapFrame, _atlas.frame);
                tb.Source = imgSource;
                RotateTransform transform = new RotateTransform(-90);
                tb.Transform = transform;
                tb.EndInit();
                _atlas.imageSource = tb;
            }
            else
            {
                _atlas.imageSource = new CroppedBitmap(bitmapFrame, _atlas.frame);
            }
            return(_atlas);
        }