示例#1
0
        static int _s_set_DynamicType(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                ProtoBuf.ProtoMemberAttribute gen_to_be_invoked = (ProtoBuf.ProtoMemberAttribute)translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.DynamicType = LuaAPI.lua_toboolean(L, 2);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(0);
        }
示例#2
0
        static int _g_get_Options(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                ProtoBuf.ProtoMemberAttribute gen_to_be_invoked = (ProtoBuf.ProtoMemberAttribute)translator.FastGetCSObj(L, 1);
                translator.Push(L, gen_to_be_invoked.Options);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(1);
        }
示例#3
0
        static int _s_set_Options(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                ProtoBuf.ProtoMemberAttribute       gen_to_be_invoked = (ProtoBuf.ProtoMemberAttribute)translator.FastGetCSObj(L, 1);
                ProtoBuf.MemberSerializationOptions gen_value; translator.Get(L, 2, out gen_value);
                gen_to_be_invoked.Options = gen_value;
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(0);
        }
示例#4
0
        static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
                {
                    int _tag = LuaAPI.xlua_tointeger(L, 2);

                    ProtoBuf.ProtoMemberAttribute gen_ret = new ProtoBuf.ProtoMemberAttribute(_tag);
                    translator.Push(L, gen_ret);

                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to ProtoBuf.ProtoMemberAttribute constructor!"));
        }
示例#5
0
        static int _m_CompareTo(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                ProtoBuf.ProtoMemberAttribute gen_to_be_invoked = (ProtoBuf.ProtoMemberAttribute)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 2 && translator.Assignable <object>(L, 2))
                {
                    object _other = translator.GetObject(L, 2, typeof(object));

                    int gen_ret = gen_to_be_invoked.CompareTo(
                        _other);
                    LuaAPI.xlua_pushinteger(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 2 && translator.Assignable <ProtoBuf.ProtoMemberAttribute>(L, 2))
                {
                    ProtoBuf.ProtoMemberAttribute _other = (ProtoBuf.ProtoMemberAttribute)translator.GetObject(L, 2, typeof(ProtoBuf.ProtoMemberAttribute));

                    int gen_ret = gen_to_be_invoked.CompareTo(
                        _other);
                    LuaAPI.xlua_pushinteger(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to ProtoBuf.ProtoMemberAttribute.CompareTo!"));
        }
        private static void SerializeXmlSheet(string[] xmlPaths, string[] typeNames, IList <SheetDataIndex> indices,
                                              Stream stream, Dictionary <string, int> allTypes, out bool strKey)
        {
            strKey = false;
            List <Type>         itemTypes   = new List <Type>();
            List <int>          typeIndices = new List <int>();;
            List <PropertyInfo> propIds     = new List <PropertyInfo>();
            SortedList <uint, List <TypeAndObj> >   objsInt = null;
            SortedList <string, List <TypeAndObj> > objsStr = null;

            for (int i = 0, imax = typeNames.Length; i < imax; i++)
            {
                string typeName = typeNames[i];
                Type   itemType = Type.GetType(string.Format("{0},Assembly-CSharp", typeName));
                if (itemType == null)
                {
                    itemType = Type.GetType(string.Format("{0},Assembly-CSharp-Editor", typeName));
                    if (itemType == null)
                    {
                        throw new Exception(string.Format("Cannot find type '{0}' !", typeName));
                    }
                }
                int typeIndex;
                if (!allTypes.TryGetValue(typeName, out typeIndex))
                {
                    ProtoBufInheritSupport.AddType(itemType);
                    //UnityEngine.Debug.LogError(typeName);
                    typeIndex = allTypes.Count;
                    allTypes.Add(typeName, typeIndex);
                }

                PropertyInfo[] props  = itemType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                PropertyInfo   propId = null;

                Type protoMember = typeof(ProtoBuf.ProtoMemberAttribute);
                for (int j = 0, jmax = props.Length; j < jmax; j++)
                {
                    PropertyInfo prop = props[j];
                    ProtoBuf.ProtoMemberAttribute attr = Attribute.GetCustomAttribute(prop, protoMember) as ProtoBuf.ProtoMemberAttribute;
                    if (attr == null || attr.Tag != 1)
                    {
                        continue;
                    }
                    propId = prop;
                    break;
                }
                if (propId == null)
                {
                    throw new Exception("'ProtoMember 1' is required as Id or Key property !");
                }
                if (propId.PropertyType.Equals(typeof(uint)) || propId.PropertyType.Equals(typeof(int)))
                {
                    if (objsStr != null)
                    {
                        throw new Exception("Id or Key should only be the same type in one sheet !: " + propId.Name + "  " + typeName);
                    }
                    strKey = false;
                    if (objsInt == null)
                    {
                        objsInt = new SortedList <uint, List <TypeAndObj> >();
                    }
                }
                else if (propId.PropertyType.Equals(typeof(string)))
                {
                    if (objsInt != null)
                    {
                        throw new Exception("Id or Key should only be the same type in one sheet !: " + propId.Name + "  " + typeName);
                    }
                    strKey = true;
                    if (objsStr == null)
                    {
                        objsStr = new SortedList <string, List <TypeAndObj> >();
                    }
                }
                else
                {
                    throw new Exception("Id or Key with 'ProtoMember=1' should only be int or string type !");
                }
                itemTypes.Add(itemType);
                propIds.Add(propId);
                typeIndices.Add(typeIndex);
            }

            Exception ex = null;

            for (int i = 0, imax = xmlPaths.Length; i < imax; i++)
            {
                if (ex != null)
                {
                    break;
                }
                string       xmlPath   = xmlPaths[i];
                Type         itemType  = itemTypes[i];
                byte[]       typeIndex = BitConverter.GetBytes((ushort)typeIndices[i]);
                FileStream   fs        = File.OpenRead(xmlPath);
                XmlReader    reader    = XmlReader.Create(fs);
                XSerializer  x         = new XSerializer(itemType);
                PropertyInfo propId    = propIds[i];
                try
                {
                    while (reader.Read())
                    {
                        if (reader.Name == "Root" || reader.Name == "ConfLangs" || reader.Name == "ConfMsgCodeList")
                        {
                            continue;
                        }
                        else if (reader.Depth < 1 && reader.NodeType != XmlNodeType.Element)
                        {
                            continue;
                        }


                        object obj;
                        try
                        {
                            obj = x.Deserialize(reader);
                        }
                        catch (Exception e)
                        {
                            string err = xmlPath + " (" + itemType + ") : Failed to parse \"" + reader.Name + "\"";
                            System.Xml.XmlTextReader xr = reader as System.Xml.XmlTextReader;
                            if (xr != null)
                            {
                                err += "  [" + xr.LineNumber + " row, " + xr.LinePosition + " column]";
                            }
                            UnityEngine.Debug.LogError(err + "\n" + e.ToString());
                            continue;
                        }

                        //UnityEngine.Debug.LogWarning(obj);
                        List <TypeAndObj> list;
                        if (objsInt != null)
                        {
                            uint ik = 0;
                            if (propId.PropertyType.Equals(typeof(uint)))
                            {
                                ik = (uint)propId.GetValue(obj, null);
                            }
                            else if (propId.PropertyType.Equals(typeof(int)))
                            {
                                int temp = (int)propId.GetValue(obj, null);
                                ik = (uint)temp;
                            }

                            if (objsInt.TryGetValue(ik, out list))
                            {
                                list.Add(new TypeAndObj(itemType, obj, typeIndex));
                            }
                            else
                            {
                                list = new List <TypeAndObj>();
                                list.Add(new TypeAndObj(itemType, obj, typeIndex));
                                objsInt.Add(ik, list);
                            }
                        }
                        if (objsStr != null)
                        {
                            string sk = (string)propId.GetValue(obj, null);
                            if (objsStr.TryGetValue(sk, out list))
                            {
                                list.Add(new TypeAndObj(itemType, obj, typeIndex));
                            }
                            else
                            {
                                list = new List <TypeAndObj>();
                                list.Add(new TypeAndObj(itemType, obj, typeIndex));
                                objsStr.Add(sk, list);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    objsInt = null;
                    objsStr = null;
                    ex      = e;
                    if (reader is XmlTextReader)
                    {
                        XmlTextReader xr  = reader as XmlTextReader;
                        string        err = string.Format("Parse Xml Failed at '{0}':{1},{2}", xmlPath, xr.LineNumber, xr.LinePosition);
                        ex = new Exception(string.Concat(err, "\n\n", e.Message), e);
                    }
                }
                reader.Close();
                fs.Close();
                FunPlus.Util.CheckXML.GetInstance().Check(itemType, xmlPath, true, true);
                if (ex != null)
                {
                    break;
                }
            }
            if (objsInt != null)
            {
                foreach (KeyValuePair <uint, List <TypeAndObj> > kv in objsInt)
                {
                    foreach (TypeAndObj to in kv.Value)
                    {
                        object obj = to.obj;
                        if (OnIdPreSerialize != null)
                        {
                            OnIdPreSerialize(kv.Key, to.type, ref obj);
                        }
                        SheetDataIntIndex index = new SheetDataIntIndex(kv.Key, (int)stream.Position);
                        stream.Write(to.typeIndex, 0, to.typeIndex.Length);
                        RuntimeTypeModel.Default.SerializeWithLengthPrefix(stream, obj, to.type, ProtoBuf.PrefixStyle.Fixed32, 0);
                        indices.Add(index);
                    }
                }
            }
            if (objsStr != null)
            {
                foreach (KeyValuePair <string, List <TypeAndObj> > kv in objsStr)
                {
                    foreach (TypeAndObj to in kv.Value)
                    {
                        object obj = to.obj;
                        if (OnKeyPreSerialize != null)
                        {
                            OnKeyPreSerialize(kv.Key, to.type, ref obj);
                        }
                        SheetDataStringIndex index = new SheetDataStringIndex(kv.Key, (int)stream.Position);
                        stream.Write(to.typeIndex, 0, to.typeIndex.Length);
                        RuntimeTypeModel.Default.SerializeWithLengthPrefix(stream, obj, to.type, ProtoBuf.PrefixStyle.Fixed32, 0);
                        indices.Add(index);
                    }
                }
            }
            if (ex != null)
            {
                throw ex;
            }
        }