/// <summary> /// Re-scanns all the media queries on demand /// </summary> /// <exception cref="Exception"></exception> public void Rescan() { _methodInfos = new Dictionary <string, MethodInfo>(); _queries = new Dictionary <string, MediaQuery>(); /*foreach (Type type in GlobalTypeDictionary.Instance.Values) * { * if (typeof(MediaQueryBase).IsAssignableFrom(type) && typeof(MediaQueryBase) != type) * { * MediaQueryBase query = (MediaQueryBase)Activator.CreateInstance(type); * _queries[query.Id] = query; * } * }*/ var queries = GuiReflector.GetMethodsInAllLoadedTypesDecoratedWith(typeof(MediaQueryAttribute)); #if DEBUG if (DebugMode) { Debug.Log(string.Format(@"Found {0} media queries", queries.Count)); } #endif foreach (var methodInfo in queries) { if (null == methodInfo.ReturnParameter || methodInfo.ReturnType != typeof(bool)) { throw new Exception(@"Method decorated with MediaQuery attribute should return a boolean value: " + methodInfo); } var p = methodInfo.GetParameters(); var parameters = new List <Type>(); foreach (var parameterInfo in p) { parameters.Add(parameterInfo.ParameterType); } // get attribute var attributes = CoreReflector.GetMethodAttributes <MediaQueryAttribute>(methodInfo); if (attributes.Count == 0) { throw new Exception(@"Cannot find MediaQuery attribute: " + methodInfo); } var attribute = attributes[0]; /** * If there is already an existing query with a same ID, allow overriding * only if this is an editor override. This way we'll get all the editor overrides * override the Play mode media queries. * */ if (_methodInfos.ContainsKey(attribute.Id) && !attribute.EditorOverride) { continue; } _methodInfos[attribute.Id] = methodInfo; MediaQuery query; if (parameters.Count > 0) { var type = parameters[0]; query = (MediaQuery)NameValueBase.CreateProperty <MediaQuery>(attribute.Id, type); //query.Value = type. } else { query = new MediaQuery { Name = attribute.Id, Parameters = parameters.ToArray() }; } _queries[attribute.Id] = query; } #if DEBUG if (DebugMode) { Debug.Log(string.Format(@"Number of queries after overrides: {0}", _queries.Keys.Count)); } #endif #if DEBUG if (DebugMode) { Debug.Log(string.Format(@"Retrieved {0} media queries: {1}", _queries.Count, DictionaryUtil <string, MediaQuery> .Format(_queries))); } #endif }