private static void InitializeEvetnsInterfaceCacheIfNeeded() { if (s_EventSystemInterfaces != null) { return; } s_EventSystemInterfaces = new List <Type>(); s_PossibleEvents = new List <GUIContent>(); s_InterfaceEventSystemEvents = new Dictionary <Type, List <int> >(); TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom <IEventSystemHandler>(); foreach (var type in types) { if (!type.IsInterface) { continue; } s_EventSystemInterfaces.Add(type); List <int> eventIndexList = new List <int>(); MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int mi = 0; mi < methodInfos.Length; mi++) { MethodInfo methodInfo = methodInfos[mi]; eventIndexList.Add(s_PossibleEvents.Count); s_PossibleEvents.Add(new GUIContent(methodInfo.Name)); } s_InterfaceEventSystemEvents.Add(type, eventIndexList); } }
public void InterceptedEventsPreviewCacheUsingTypeCacheReturnsSameTypes() { var typeCacheEventInterfaces = new List <Type>(); TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom <IEventSystemHandler>(); foreach (var type in types) { if (!type.IsInterface) { continue; } typeCacheEventInterfaces.Add(type); } var appDomainEventInterfaces = new List <Type>(); foreach (var type in GetAccessibleTypesInLoadedAssemblies()) { if (!type.IsInterface) { continue; } appDomainEventInterfaces.Add(type); } Assert.AreNotEqual(typeCacheEventInterfaces.Count, appDomainEventInterfaces.Count, "Did not find the same number of EventInterface types"); for (int i = 0; i < typeCacheEventInterfaces.Count; ++i) { Assert.Contains(typeCacheEventInterfaces[i], appDomainEventInterfaces); } }
void InitIfNeeded() { if (m_CoreConvertersList.Any()) { return; } m_CoreConvertersList = new List <RenderPipelineConverter>(); // This is the drop down choices. m_ConverterContainers = TypeCache.GetTypesDerivedFrom <RenderPipelineConverterContainer>(); foreach (var continerType in m_ConverterContainers) { var container = (RenderPipelineConverterContainer)Activator.CreateInstance(continerType); m_Containers.Add(container); m_ContainerChoices.Add(container.name); } if (m_ConverterContainers.Any()) { GetConverters(); } else { ClearConverterStates(); } }
void OnEnable() { m_CoreConvertersList = new List <RenderPipelineConverter>(); // This is the drop down choices. m_ConverterContainers = TypeCache.GetTypesDerivedFrom <RenderPipelineConverterContainer>(); var converters = TypeCache.GetTypesDerivedFrom <RenderPipelineConverter>(); for (int i = 0; i < converters.Count; ++i) { // Iterate over the converters RenderPipelineConverter conv = (RenderPipelineConverter)Activator.CreateInstance(converters[i]); m_CoreConvertersList.Add(conv); // Create a new ConvertState which holds the active state of the converter var converterState = new ConverterState { isEnabled = conv.IsEnabled, isActive = true, isInitialized = false, items = new List <ConverterItemState>(), index = i, }; m_ConverterStates.Add(converterState); // This just creates empty entries in the m_ItemsToConvert. // This list need to have the same amount of entries as the converters List <ConverterItemDescriptor> converterItemInfos = new List <ConverterItemDescriptor>(); m_ItemsToConvert.Add(converterItemInfos); } }
private void AddFeatureMenu() { var menu = new GenericMenu(); TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom <BuildPipelineFeature>(); foreach (Type type in types) { string path = GetMenuNameFromType(type); menu.AddItem(new GUIContent(path), false, AddFeature, type.Name); } menu.ShowAsContext(); }
private void AddPassMenu() { GenericMenu menu = new GenericMenu(); TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom <ScriptableRendererFeature>(); foreach (Type type in types) { string path = GetMenuNameFromType(type); menu.AddItem(new GUIContent(path), false, AddComponent, type.Name); } menu.ShowAsContext(); }
IMotionSynthesizerProvider FindMotionSynthesizerObject() { TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom <IMotionSynthesizerProvider>(); foreach (var type in types) { if (FindObjectOfType(type) is IMotionSynthesizerProvider candidateProvider) { return(candidateProvider); } } return(null); }
internal static List <T> InstantiateAllTypesDerivingFrom <T>() { List <T> instances = new List <T>(); TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom <T>(); foreach (Type type in types) { T instance = (T)Activator.CreateInstance(type); instances.Add(instance); } return(instances); }
static TypeInfo GetDerivedTypes(Type baseType) { #if UNITY_2019_2_OR_NEWER TypeCache.TypeCollection allTypes = TypeCache.GetTypesDerivedFrom(baseType); #else var allTypes = (from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where !type.IsAbstract && baseType.IsAssignableFrom(type) select type); #endif var types = allTypes.Where(t => !t.IsAbstract).ToArray(); return(new TypeInfo { Names = types.Select(t => t.Name).ToArray(), FullNames = types.Select(t => t.FullName).ToArray() }); }
private void AddPassMenu() { GenericMenu menu = new GenericMenu(); TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom <ScriptableRendererFeature>(); foreach (Type type in types) { var data = target as ScriptableRendererData; if (data.DuplicateFeatureCheck(type)) { continue; } string path = GetMenuNameFromType(type); menu.AddItem(new GUIContent(path), false, AddComponent, type.Name); } menu.ShowAsContext(); }
public static ILPostProcessor[] FindAllPostProcessors() { TypeCache.TypeCollection typesDerivedFrom = TypeCache.GetTypesDerivedFrom <ILPostProcessor>(); ILPostProcessor[] localILPostProcessors = new ILPostProcessor[typesDerivedFrom.Count]; for (int i = 0; i < typesDerivedFrom.Count; i++) { try { localILPostProcessors[i] = (ILPostProcessor)Activator.CreateInstance(typesDerivedFrom[i]); } catch (Exception exception) { Console.WriteLine($"Could not create ILPostProcessor ({typesDerivedFrom[i].FullName}):{Environment.NewLine}{exception.StackTrace}"); } } return(localILPostProcessors); }
public static void RetrieveFromScriptTypes(TypeCache.TypeCollection types) { if (transparent == null) { transparent = new Texture2D(1, 1); transparent.SetPixel(1, 1, new Color(1, 1, 1, 0)); transparent.Apply(); } if (monoScripts == null) { monoScripts = new Dictionary <Type, MonoScript>(); FindAllMonoScripts(); } foreach (var type in types) { if (icons.ContainsKey(type.FullName)) { continue; } monoScripts.TryGetValue(type, out var script); var icon = EditorGUIUtility.ObjectContent(script, type).image; if (icon == defaultAsset) { icon = scriptableObject; } if (!icon) { icon = transparent; } icons.Add(type.FullName, icon); } }
private static void OnInitialize() { componentTypes = TypeCache.GetTypesDerivedFrom <Component>(); }
static EntityRepresentationMappingEditor() { entityRepresentationTypes = TypeCache.GetTypesDerivedFrom <IEntityRepresentationResolver>(); }
static StateSwitcherEditor() { m_switchActionTypes = TypeCache.GetTypesDerivedFrom <ISwitcherAction>(); }
public void Initialize(TypeCache.TypeCollection types, Action <Type> onSelect) { this.types = new List <Type>(types); this.onSelect = onSelect; }
/// <summary> /// 获取带继承关系的所有类的类型 /// </summary> public static List <Type> GetAssignableTypes(System.Type parentType) { TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(parentType); return(collection.ToList()); }
/// Purpose. /// This is generic selection menu. /// Filtering. /// You can add substring filter here to filter by search string. /// As well ass type or interface restrictions. /// As well as any custom restriction that is based on input type. /// And it will be performed on each Appropriate type found by TypeCache. public static void ShowContextMenuForManagedReference(this SerializedProperty property, IEnumerable <Func <Type, bool> > filters = null) { var context = new GenericMenu(); FillContextMenu(); context.ShowAsContext(); void FillContextMenu() { context.AddItem(new GUIContent("Null"), false, MakeNull); Type realPropertyType = SerializeReferenceTypeNameUtility.GetRealTypeFromTypename(property.managedReferenceFieldTypename); if (realPropertyType == null) { Debug.LogError("Can not get type from"); return; } TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom(realPropertyType); foreach (Type type in types) { // Skips unity engine Objects (because they are not serialized by SerializeReference) if (type.IsSubclassOf(typeof(UnityEngine.Object))) { continue; } // Skip abstract classes because they should not be instantiated if (type.IsAbstract) { continue; } if (FilterTypeByFilters(filters, type) == false) { continue; } AddContextMenu(type, context); } void MakeNull() { property.serializedObject.Update(); property.managedReferenceValue = null; property.serializedObject.ApplyModifiedPropertiesWithoutUndo(); // undo is bugged for now } void AddContextMenu(Type type, GenericMenu genericMenuContext) { string assemblyName = type.Assembly.ToString().Split('(', ',')[0]; string entryName = type + " ( " + assemblyName + " )"; genericMenuContext.AddItem(new GUIContent(entryName), false, AssignNewInstanceOfType, type); } void AssignNewInstanceOfType(object typeAsObject) { var type = (Type)typeAsObject; object instance = Activator.CreateInstance(type); property.serializedObject.Update(); property.managedReferenceValue = instance; property.serializedObject.ApplyModifiedPropertiesWithoutUndo(); // undo is bugged for now } bool FilterTypeByFilters(IEnumerable <Func <Type, bool> > filters_, Type type) => filters_.All(f => f.Invoke(type)); } }