示例#1
0
        /// <summary>
        /// 依赖查loadxmltolistarray 中循环每张图片的需要图片缩放后 宽和高 和处理后偏移竖直,还有就是是否进行旋转的处理
        /// </summary>
        /// <returns></returns>
        public void  dependListarrayMakeUvValue()
        {
            // 最后社会吃uv com
            GetPlistSetUvValues = new plistcom_tomax[] { };
            uv_com.Clear();
            Array getlistarray = loadxmltolistarray();

            foreach (var i in getlistarray)
            {
                plistcom_tomax tem = new plistcom_tomax();
                plistcom       obj = (plistcom)i;
                tem.name      = obj.tagname;
                tem.is_rotate = obj.rotated;

                int imagewidth  = obj.pakesize.X;
                int imageheight = obj.pakesize.Y;

                int image_st_x = obj.frame.X;
                int image_st_y = obj.frame.Y;
                int image_en_x = obj.frame.Width;
                int image_en_y = obj.frame.Height;
                /// 计算的uv 缩小比例
                tem.uv_width  = image_en_x / (float)imagewidth;
                tem.uv_height = image_en_y / (float)imageheight;

                /// 计算的uv 偏移数
                tem.uv_x_offset = image_st_x / (float)imagewidth;
                tem.uv_y_offset = image_st_y / (float)imageheight;

                uv_com.Add(tem);
            }

            /// 不做返回, 处理完成数据给到一点, 后续通过查询的方法和方式处理
            ///
            GetPlistSetUvValues = uv_com.ToArray();
        }// end
示例#2
0
        /// <summary>
        /// 根据传入的plist  返回一个 数组  每个数组是一个plistcom 对象,
        /// 需要说明,这个plistcom 有几个属性, tagname  贴图名称
        /// frame 是一个矩形 告诉合并后贴图的位置
        /// offset 是一个偏于数据,对于UI 有才将的管用,对于场景合并不需要裁剪,那样会有问题
        /// rotaed 是bool 旋转也是在位置去顶了之后进行的旋转操作, 这里如果反项处理uv
        /// sourcesize 处理的图像大小
        /// pakesize 打包图片的大小
        /// </summary>
        /// <returns></returns>
        public Array loadxmltolistarray()
        {
            listarray.Clear();
            XmlDocument xml = new XmlDocument();

            xml.Load(this.plistfile);
            XmlElement rooxml = xml.DocumentElement;

            XmlNode     packesize = rooxml.ChildNodes.Item(0).ChildNodes.Item(3);
            IEnumerator pack_inum = packesize.GetEnumerator();

            while (pack_inum.MoveNext())
            {
                XmlElement ct = (XmlElement)pack_inum.Current;
                if (ct.InnerText == this.usesize)
                {
                    // 移动到下一位
                    pack_inum.MoveNext();
                    ct = (XmlElement)pack_inum.Current;
                    string sr = ct.InnerText;
                    /// 分割字符进行转换并 去掉空的字符
                    string[] get = sr.Split(new char[] { '{', '}', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    int      x   = Convert.ToInt16((get[0]));
                    int      y   = Convert.ToInt16((get[1]));
                    packe_text_size = new Point(x, y);
                }
            }



            XmlNode totodit_kv = rooxml.ChildNodes.Item(0).ChildNodes.Item(1);
            /// 利用迭代器处理
            ///
            IEnumerator ienum = totodit_kv.GetEnumerator();


            /// 运行期间
            while (ienum.MoveNext())
            {
                XmlNode    t  = (XmlNode)ienum.Current;
                XmlElement ct = (XmlElement)t;
                if (ct.Name == this.usekey)
                {
                    newre         = new plistcom();
                    newre.tagname = ct.InnerText.ToString();
                }
                //// 是字典的
                if (ct.Name == this.usedit)
                {
                    /// 内部小迭代 使 元素
                    ///
                    for (int i = 0; i < ct.ChildNodes.Count; i++)
                    {
                        string ss = ct.ChildNodes.Item(i).InnerText;
                        if (ss == useframe)
                        {
                            //i加1  处理边框数据
                            i += 1;
                            string sr = ct.ChildNodes.Item(i).InnerText;
                            /// 分割字符进行转换并 去掉空的字符
                            string[] get    = sr.Split(new char[] { '{', '}', ',' }, StringSplitOptions.RemoveEmptyEntries);
                            int      x      = Convert.ToInt16((get[0]));
                            int      y      = Convert.ToInt16((get[1]));
                            int      width  = Convert.ToInt16((get[2]));
                            int      height = Convert.ToInt16((get[3]));

                            newre.frame = new Rectangle(x, y, width, height);
                        }
                        else if (ss == useoffset)
                        {
                            i += 1;
                            string sr = ct.ChildNodes.Item(i).InnerText;
                            /// 分割字符进行转换并 去掉空的字符
                            string[] get = sr.Split(new char[] { '{', '}', ',' }, StringSplitOptions.RemoveEmptyEntries);
                            int      x   = Convert.ToInt16((get[0]));
                            int      y   = Convert.ToInt16((get[1]));

                            newre.offset = new Point(x, y);
                        }
                        else if (ss == userotaed)
                        {
                            i += 1;
                            string sr = ct.ChildNodes.Item(i).Name;
                            if (sr == usetrue)
                            {
                                newre.rotated = true;
                            }
                            else if (sr == usefalse)
                            {
                                newre.rotated = false;
                            }
                        }
                        else if (ss == usesourcesize)
                        {
                            i += 1;
                            /// 每次等于key 向下移动一位进行取值操作 完成的操作
                            ///
                            string sr = ct.ChildNodes.Item(i).InnerText;
                            /// 分割字符进行转换并 去掉空的字符
                            string[] get = sr.Split(new char[] { '{', '}', ',' }, StringSplitOptions.RemoveEmptyEntries);
                            int      x   = Convert.ToInt16((get[0]));
                            int      y   = Convert.ToInt16((get[1]));
                            newre.sourcesize = new Point(x, y);
                        }

                        // 最后加入 pack tex size
                        newre.pakesize = packe_text_size;
                    }
                    ///  循环完成装入一个对象
                    ///
                    listarray.Add(newre);
                }

                // Console.WriteLine(ct.Name );
            }
            /// 迭代器好事很好处理 还是

            return(listarray.ToArray());
        }