コード例 #1
0
ファイル: TAManager.cs プロジェクト: lonelyXzq/LE_Entities
        protected TAManager()
        {
            Type baseType = typeof(T);

            TemplateIdManager.RegiserBase <T>();
            var types = LEType.GetTypes(t => t.BaseType == baseType);

            actions = new T[types.Length];
            for (int i = 0; i < types.Length; i++)
            {
                actions[i] = LEType.CreateInstance <T>(types[i]);
                TemplateIdManager.Register <T>(types[i]);
            }
        }
コード例 #2
0
        static TemplateManager()
        {
            Type baseType = typeof(T);
            var  types    = LEType.GetTypes(t => t.BaseType == baseType);

            datas = new T[types.Length];
            for (int i = 0; i < types.Length; i++)
            {
                datas[i] = LEType.CreateInstance <T>(types[i]);
                int id = IdManager.IdDeliverer <T> .GetNextId();

                var _id = types[i].GetField("id", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                if (_id == null)
                {
                    //TODO: Exception
                    LE_Log.Log.Exception(new Exception(), "Template register fail", "template type:{0}", types[i].FullName);
                }
                _id.SetValue(datas[i], id);
                Console.WriteLine("{0}:{1}", types[i].Name, datas[i].Id);
            }
        }
コード例 #3
0
        private static void Add(Type type, int id)
        {
            EntityType entityType = LEType.CreateInstance <EntityType>(type);

            entityTypes.Add(entityType);
            idchanges.Add(type.FullName, id);
            var  infos    = type.GetFields();
            Type dataTyep = typeof(DataInfo <>);
            var  eType    = (BitArray)typeof(EntityType).GetField("dataInfo", BindingFlags.NonPublic | BindingFlags.Instance)
                            .GetValue(entityType);

            eType.Set(DataInfo <EntityData> .DataId, true);
            for (int i = 0; i < infos.Length; i++)
            {
                Type t = infos[i].FieldType;
                if (t.GetInterfaces().Contains(typeof(IData)))
                {
                    int index = (int)dataTyep.MakeGenericType(t).GetField("dataId", BindingFlags.NonPublic | BindingFlags.Static)
                                .GetValue(null);
                    eType.Set(index, true);
                }
            }
        }