Пример #1
0
        private TypeReflectionInfo GetTypeReflectionInfo(Type type)
        {
            TypeReflectionInfo typeReflectionInfo;

            if (!_typeReflectionInfos.TryGetValue(type, out typeReflectionInfo))
            {
                typeReflectionInfo = new TypeReflectionInfo(type);
                _typeReflectionInfos.Add(type, typeReflectionInfo);
            }
            return(typeReflectionInfo);
        }
Пример #2
0
            public static TypeReflectionInfo GetReflectionInfo(Type type)
            {
                TypeReflectionInfo info;

                if (!_typeReflectionData.TryGetValue(type, out info))
                {
                    PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                    FieldInfo[]    fields     = type.GetFields(BindingFlags.Instance | BindingFlags.Public);

                    info = new TypeReflectionInfo(properties, fields);
                    _typeReflectionData.Add(type, info);
                }

                return(info);
            }
Пример #3
0
        public object CreateInstance(Type type, object[] constructorArgs = null)
        {
            // If we have args to pass, just let Activator.CreateInstance figure out
            // what constructor fits best
            if (constructorArgs != null && constructorArgs.Length > 0)
            {
                var obj2 = Activator.CreateInstance(type, constructorArgs);
                Inject(obj2);
                return(obj2);
            }

            // Otherwise, find the public constructor that has the most arguments,
            // and then try to resolve these arguments
            TypeReflectionInfo reflectionInfo = GetTypeReflectionInfo(type);

            var maxParameters = reflectionInfo.PublicConstructors[0].Parameters;

            for (int i = 0; i < reflectionInfo.PublicConstructors.Length; i++)
            {
                var c          = reflectionInfo.PublicConstructors[i];
                var parameters = c.Parameters;
                if (parameters.Length > maxParameters.Length)
                {
                    maxParameters = parameters;
                }
            }
            var args = new object[maxParameters.Length];

            for (int i = 0; i < maxParameters.Length; i++)
            {
                ParameterInfo parameterInfo = maxParameters[i];
                if (parameterInfo.ParameterType.IsArray)
                {
                    args[i] = ResolveAll(parameterInfo.ParameterType);
                }
                else
                {
                    args[i] =
                        Resolve(parameterInfo.ParameterType) ??
                        Resolve(parameterInfo.ParameterType, parameterInfo.Name);
                }
            }

            var obj = Activator.CreateInstance(type, args);

            Inject(obj);
            return(obj);
        }
Пример #4
0
 private static T GetObjectValueFast <T>(string key, object subject, TypeReflectionInfo info)
 {
     if (subject == null)
     {
         return(default(T));
     }
     if (info.Info.ContainsKey(key))
     {
         try
         {
             return((T)info.Info[key].GetValue(subject));
         }
         catch (Exception e)
         {
             Debug.LogWarning(String.Format("F: GetObjectValue: key = {0} exception: {1}", key, e));
         }
     }
     return(default(T));
 }
Пример #5
0
        public void GetEntityReflectionInfo(Int64 EntityID, out List <TypeReflectionInfo> output)
        {
            output = new List <TypeReflectionInfo>();

            BaseEntity entity;

            if (entities.TryGetValue(EntityID, out entity))
            {
                // First we'll get the Entity info
                TypeReflectionInfo entityInfo = QSUtils.GetReflectionInfo(entity, entity.GetType());
                output.Add(entityInfo);

                // Now we'll get the Components' info
                foreach (KeyValuePair <ComponentType, BaseComponent> entry in entity.Components)
                {
                    TypeReflectionInfo compInfo = QSUtils.GetReflectionInfo(entry.Value, entry.Value.GetType());
                    output.Add(compInfo);
                }
            }
        }
Пример #6
0
 private static void SetObjectValueFast(string key, object value, object subject, TypeReflectionInfo info)
 {
     if (subject == null)
     {
         return;
     }
     if (info.Info.ContainsKey(key))
     {
         try
         {
             info.Info[key].SetValue(subject, value);
         }
         catch (Exception e)
         {
             Debug.LogWarning(String.Format("F: SetObjectValue: key = {0} exception: {1}", key, e));
         }
     }
     else
     {
         Debug.LogWarning("F: SetObjectValue: nonexistent key: " + key);
     }
 }
Пример #7
0
        public void RayCastForEntityReport()
        {
            // First we determine the line segment between the camera's position and the cursor
            // as if it were at the far plane.
            var msgGetSegment = ObjectPool.Aquire <MsgGetLineSegmentToCursor>();

            this.game.SendInterfaceMessage(msgGetSegment, InterfaceType.Camera);

            // Now we use that line segment to check for physics collisions
            PhysicsInterface physics = this.game.SceneManager.GetInterface(InterfaceType.Physics) as PhysicsInterface;

            if (null == physics)
            {
                throw new Exception("Cannot perform a physics ray cast without a registered PhysicsInterface");
            }

            SegmentIntersectInfo info = physics.PerformSegmentIntersectQuery(msgGetSegment.lineSegment);

            // Check if the ray hit anything
            if (QSGame.UniqueIDEmpty == info.entityID)
            {
                return;
            }

            List <TypeReflectionInfo> entityInfo;

            this.game.SceneManager.GetEntityReflectionInfo(info.entityID, out entityInfo);

            if (null == this.infoWindows)
            {
                this.infoWindows = new Dictionary <Int64, EntityInfoWindow>();
            }

            EntityInfoWindow window;

            if (!this.infoWindows.TryGetValue(info.entityID, out window))
            {
                // If a window doesn't yet exist for this entity, then we create one
                window = new EntityInfoWindow(100, 100, info.entityID, this.game);

                this.infoWindows.Add(info.entityID, window);

                this.game.Gui.Screen.Desktop.Children.Add(window);
            }
            else
            {
                if (!window.IsOpen)
                {
                    this.game.Gui.Screen.Desktop.Children.Add(window);
                }

                window.Label.Items.Clear();
            }

            for (int i = 0; i < entityInfo.Count; ++i)
            {
                TypeReflectionInfo rInfo = entityInfo[i];

                window.Label.Items.Add(rInfo.typeName);

                List <string> details = QSUtils.ConvertTypeReflectionInfoToString(rInfo.properties);

                for (int j = 0; j < details.Count; ++j)
                {
                    window.Label.Items.Add(details[j]);
                }
            }
        }