示例#1
0
                public void DeSerializate(XmlElement root)
                {
                    if (root.SelectSingleNode("background") != null)
                    {
                        byte[] bytes = new byte[0];
                        DeSerializeField(root, "background", ref bytes);
                        state.background = new Texture2D(1, 1);
                        state.background.LoadImage(bytes);
                        state.background.hideFlags = HideFlags.DontSave;
                    }
                    Color color = Color.white;

                    DeSerializeField(root, "textColor", ref color);
                    state.textColor = color;
#if UNITY_EDITOR
                    XmlElement ele = root.SelectSingleNode("scaledBackgrounds") as XmlElement;
                    state.scaledBackgrounds = new Texture2D[ele.ChildNodes.Count];
                    List <Texture2D> txs = new List <Texture2D>();
                    for (int i = 0; i < ele.ChildNodes.Count; i++)
                    {
                        byte[] bs = new byte[0];
                        StringConvert.TryConvert(ele.ChildNodes[i].InnerText, out bs);

                        Texture2D txx = new Texture2D(1, 1);
                        txx.hideFlags = HideFlags.DontSaveInEditor;
                        txx.LoadImage(bs);
                        txs.Add(txx);
                    }
                    state.scaledBackgrounds = txs.ToArray();
#endif
                }
示例#2
0
        /// <summary>
        /// 对象与字符串的相互转换
        /// </summary>
        public void String()
        {
            Log.L("");
            Log.L("开始对象与字符串的相互转换:");
            Log.L("生成一个字典对象,并转换成字符串");
            HuMan hu = new HuMan()
            {
                age = 6, Name = "abc", sex = "sex", heigth = 16, width = 20
            };
            Dictionary <int, HuMan> hus = new Dictionary <int, HuMan>()
            {
                { 1, hu },
                { 2, hu }
            };

            var str = StringConvert.ConvertToString(hus);

            Log.L("转换出来的字符串是:");
            Console.WriteLine(str + "\n");
            Log.L("将字符串转换回去:");
            Dictionary <int, HuMan> hus2;

            Log.L("转换" + (StringConvert.TryConvert(str, out hus2) ? "成功" : "失败"));
            Console.WriteLine($"由字符串转换回来的对象:{hus2}\n");
        }
        private void ListenNet(Type publishType, int code, IEventArgs args, object[] param)
        {
            if (param[0] is PanResponse)
            {
                PanResponse res = param[0] as PanResponse;

                var cs = res.colums;

                int cnt = cs.Count;
                int w   = MapSize;
                int h   = cnt / w;

                Color[] cols = new Color[cnt];
                for (int i = 0; i < cs.Count; i++)
                {
                    var   c = cs[i];
                    Color color;
                    bool  bo = StringConvert.TryConvert(c.color, out color);
                    cols[i] = color;
                }

                tx.SetPixels(0, cs[0].posX, w, h, cols);

                tx.Apply();
                //  tx.filterMode = FilterMode.Point;
            }
        }
示例#4
0
        /// <summary>
        /// 根据格子反序列化一个实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cols"></param>
        /// <param name="membersDic">需要反序列化的成员</param>
        /// <returns></returns>
        public T CreatInstance <T>(List <DataColumn> cols, Dictionary <MemberInfo, string> membersDic)
        {
            object t = CreatInstance(typeof(T));

            foreach (var pair in membersDic)
            {
                MemberInfo m       = pair.Key;
                string     csvName = pair.Value;
                DataColumn column;
                if (m.IsDefined(typeof(DataReadColumnIndexAttribute), false))
                {
                    DataReadColumnIndexAttribute attr = m.GetCustomAttributes(typeof(DataReadColumnIndexAttribute), false)[0] as DataReadColumnIndexAttribute;
                    if (attr.index >= cols.Count)
                    {
                        throw new Exception(string.Format("index {0} is too Large Then colums  {1}", attr.index, cols.Count));
                    }
                    column = cols[attr.index];
                }
                else
                {
                    column = cols.Find((c) => { return(c.headNameForRead == csvName); });
                }
                string str = FitterCsv_CreatInstance(column.value);
                if (m is PropertyInfo)
                {
                    PropertyInfo info = m as PropertyInfo;
                    object       obj  = default(object);
                    if (StringConvert.TryConvert(str, info.PropertyType, ref obj))
                    {
                        info.SetValue(t, obj, null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Convert Err Type {0} Name {1} Value {2}", typeof(T), csvName, column.value));
                    }
                }
                else
                {
                    FieldInfo info = m as FieldInfo;
                    object    obj  = default(object);
                    if (StringConvert.TryConvert(str, info.FieldType, ref obj))
                    {
                        info.SetValue(t, obj);
                    }
                    else
                    {
                        throw new Exception(string.Format("Convert Err Type {0} Name {1} Value {2}", typeof(T), csvName, column.value));
                    }
                }
            }
            return((T)t);
        }
示例#5
0
        protected static void DeSerializeField <T>(XmlElement root, string name, ref T obj)
        {
            T       obj1;
            XmlNode node = root.SelectSingleNode(name);

            if (node != null)
            {
                StringConvert.TryConvert(node.InnerText, out obj1);
                obj = obj1;
            }
            //else
            //    Log.W("GUICanvas:   Not Find Field   " + name);
        }
示例#6
0
        public override void DeSerialize(XmlElement root)
        {
            base.DeSerialize(root);
            XmlElement texsE = root.SelectSingleNode("texs") as XmlElement;

            texs = new Texture2D[texsE.ChildNodes.Count];
            for (int i = 0; i < texs.Length; i++)
            {
                byte[] bs = new byte[0];
                texs[i] = new Texture2D(100, 100);
                StringConvert.TryConvert(texsE.ChildNodes[i].InnerText, out bs);
                texs[i].LoadImage(bs);
                texs[i].hideFlags = HideFlags.DontSaveInEditor;
            }
        }
        public void String()
        {
            HuMan hu = new HuMan()
            {
                age = 6, Name = "xxl", sex = "sex", heigth = 16, width = 20
            };
            Dictionary <int, HuMan> hus = new Dictionary <int, HuMan>()
            {
                { 1, hu },
                { 2, hu }
            };

            var str = StringConvert.ConvertToString(hus);

            Console.WriteLine(str);
            Dictionary <int, HuMan> hus2;

            Console.WriteLine(StringConvert.TryConvert(str, out hus2));
            Console.WriteLine(hus2);
        }
示例#8
0
 private static void DeSerializeField <T>(XmlElement root, string name, ref T obj)
 {
     try
     {
         T       obj1;
         XmlNode node = root.SelectSingleNode(name);
         if (node != null)
         {
             StringConvert.TryConvert(node.InnerText, out obj1);
             obj = obj1;
         }
         else if (name != "UserData")
         {
             Log.W("SubWin    " + name + "   NotFind");
         }
     }
     catch
     {
         throw new Exception(name);
     }
 }
        /// <summary>
        /// 根据格子反序列化一个实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cols"></param>
        /// <param name="membersDic">需要反序列化的成员</param>
        /// <returns></returns>
        public T CreatInstance <T>(List <DataColumn> cols, Dictionary <MemberInfo, string> membersDic)
        {
            T t = CreatInstance <T>();

            membersDic.ForEach((pair) => {
                MemberInfo m      = pair.Key;
                string csvName    = pair.Value;
                DataColumn column = cols.Find((c) => { return(c.HeadLineName == csvName); });
                string str        = FitterCsv_CreatInstance(column.StrValue);
                if (m is PropertyInfo)
                {
                    PropertyInfo info = m as PropertyInfo;
                    object obj        = default(object);
                    if (StringConvert.TryConvert(str, info.PropertyType, ref obj))
                    {
                        info.SetValue(t, obj, null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Convert Err Type {0} Name {1} Value {2}", typeof(T), csvName, column.StrValue));
                    }
                }
                else
                {
                    FieldInfo info = m as FieldInfo;
                    object obj     = default(object);
                    if (StringConvert.TryConvert(str, info.FieldType, ref obj))
                    {
                        info.SetValue(t, obj);
                    }
                    else
                    {
                        throw new Exception(string.Format("Convert Err Type {0} Name {1} Value {2}", typeof(T), csvName, column.StrValue));
                    }
                }
            });
            return(t);
        }
示例#10
0
 public void DeSerializate(XmlElement ele)
 {
     StringConvert.TryConvert(ele.InnerText, out offset);
 }