static Type[] GetCachedAssetPostprocessorClasses() { if (m_PostprocessorClasses == null) { m_PostprocessorClasses = TypeCache.GetTypesDerivedFrom <AssetPostprocessor>().ToArray(); } return(m_PostprocessorClasses); }
private static IEnumerable <Type> GetDefaultPaneTypes() { const string k_PaneTypesSectionName = "pane_types"; if (!ModeService.HasSection(ModeService.currentIndex, k_PaneTypesSectionName)) { return(k_PaneTypes); } var modePaneTypes = ModeService.GetModeDataSectionList <string>(ModeService.currentIndex, k_PaneTypesSectionName).ToList(); return(TypeCache.GetTypesDerivedFrom <EditorWindow>().Where(t => modePaneTypes.Any(mpt => t.Name.EndsWith(mpt))).ToArray()); }
private ShowTypeFixupResult ShowTypeFixup() { var originalClassIdentifier = serializedObject.FindProperty("m_EditorClassIdentifier"); if (originalClassIdentifier == null) { return(ShowTypeFixupResult.CantFindCandidate); } var assemblySepartor = originalClassIdentifier.stringValue?.IndexOf("::"); if (assemblySepartor == null || assemblySepartor == -1) { return(ShowTypeFixupResult.CantFindCandidate); } var withoutAssembly = originalClassIdentifier.stringValue.Substring(assemblySepartor.Value + 2); var potentialMatches = TypeCache.GetTypesDerivedFrom <ScriptableObject>().Where(c => c.FullName == withoutAssembly) .Concat(TypeCache.GetTypesDerivedFrom <MonoBehaviour>().Where(c => c.FullName == withoutAssembly)) .Select(c => $"{c.Assembly.GetName().Name}::{c.FullName}") .Where(c => c != originalClassIdentifier.stringValue) .ToList(); if (potentialMatches.Count == 0) { return(ShowTypeFixupResult.CantFindCandidate); } var buttons = new string[potentialMatches.Count + 1]; buttons[0] = "-"; for (int i = 0; i < potentialMatches.Count; i++) { buttons[i + 1] = potentialMatches[i]; } EditorGUILayout.HelpBox("It seems that the underlying type has been moved in a different assembly. Please select the correct object type.", MessageType.Warning); EditorGUI.BeginChangeCheck(); var value = EditorGUILayout.Popup(s_fixupTypeContent, 0, buttons); if (EditorGUI.EndChangeCheck()) { originalClassIdentifier.stringValue = buttons[value]; return(ShowTypeFixupResult.SelectedCandidate); } return(ShowTypeFixupResult.DisplayedCandidates); }
private static IEnumerable <Type> GetCurrentModePaneTypes(string modePaneTypeSectionName) { var modePaneTypes = ModeService.GetModeDataSectionList <string>(ModeService.currentIndex, modePaneTypeSectionName); var editorWindowTypes = TypeCache.GetTypesDerivedFrom <EditorWindow>(); foreach (var paneTypeName in modePaneTypes) { var paneType = editorWindowTypes.FirstOrDefault(t => t.Name.EndsWith(paneTypeName)); if (paneType != null) { yield return(paneType); } else { Debug.LogWarning($"Cannot find editor window pane type {paneTypeName} for editor mode {ModeService.currentId}."); } } }
// Called on demand private static void BuildDrawerTypeForTypeDictionary() { s_DrawerTypeForType = new Dictionary <Type, DrawerKeySet>(); foreach (var type in TypeCache.GetTypesDerivedFrom <GUIDrawer>()) { //Debug.Log("Drawer: " + type); object[] attrs = type.GetCustomAttributes(typeof(CustomPropertyDrawer), true); foreach (CustomPropertyDrawer editor in attrs) { //Debug.Log("Base type: " + editor.type); s_DrawerTypeForType[editor.m_Type] = new DrawerKeySet() { drawer = type, type = editor.m_Type }; if (!editor.m_UseForChildren) { continue; } var candidateTypes = TypeCache.GetTypesDerivedFrom(editor.m_Type); foreach (var candidateType in candidateTypes) { //Debug.Log("Candidate Type: "+ candidateType); if (s_DrawerTypeForType.ContainsKey(candidateType) && (editor.m_Type.IsAssignableFrom(s_DrawerTypeForType[candidateType].type))) { // Debug.Log("skipping"); continue; } //Debug.Log("Setting"); s_DrawerTypeForType[candidateType] = new DrawerKeySet() { drawer = type, type = editor.m_Type }; } } } }
public static void GetPreviewableTypes(out Dictionary <Type, List <Type> > previewableTypes) { // We initialize this list once per InspectorWindow, instead of globally. // This means that if the user is debugging an IPreviewable structure, // the InspectorWindow can be closed and reopened to refresh this list. previewableTypes = new Dictionary <Type, List <Type> >(); foreach (var type in TypeCache.GetTypesDerivedFrom <IPreviewable>()) { // we don't want Editor classes with preview here. if (type.IsSubclassOf(typeof(Editor))) { continue; } if (type.GetConstructor(Type.EmptyTypes) == null) { Debug.LogError($"{type} does not contain a default constructor, it will not be registered as a " + $"preview handler. Use the Initialize function to set up your object instead."); continue; } // Record only the types with a CustomPreviewAttribute. var attrs = type.GetCustomAttributes(typeof(CustomPreviewAttribute), false) as CustomPreviewAttribute[]; foreach (CustomPreviewAttribute previewAttr in attrs) { if (previewAttr.m_Type == null) { continue; } List <Type> types; if (!previewableTypes.TryGetValue(previewAttr.m_Type, out types)) { types = new List <Type>(); previewableTypes.Add(previewAttr.m_Type, types); } types.Add(type); } } }
private static MaterialPropertyDrawer GetShaderPropertyDrawer(string attrib, out bool isDecorator) { isDecorator = false; string className = attrib; string args = string.Empty; Match match = Regex.Match(attrib, @"(\w+)\s*\((.*)\)"); if (match.Success) { className = match.Groups[1].Value; args = match.Groups[2].Value.Trim(); } //Debug.Log ("looking for class " + className + " args '" + args + "'"); foreach (var klass in TypeCache.GetTypesDerivedFrom <MaterialPropertyDrawer>()) { // When you write [Foo] in shader, get Foo, FooDrawer, MaterialFooDrawer, // FooDecorator or MaterialFooDecorator class; // "kind of" similar to how C# does attributes. //@TODO: namespaces? if (klass.Name == className || klass.Name == className + "Drawer" || klass.Name == "Material" + className + "Drawer" || klass.Name == className + "Decorator" || klass.Name == "Material" + className + "Decorator") { try { isDecorator = klass.Name.EndsWith("Decorator"); return(CreatePropertyDrawer(klass, args)); } catch (Exception) { Debug.LogWarningFormat("Failed to create material drawer {0} with arguments '{1}'", className, args); return(null); } } } return(null); }
private static Type ExtractCustomEditorType(string customEditorName) { if (string.IsNullOrEmpty(customEditorName)) { return(null); } // To allow users to implement their own ShaderGUI for the Standard shader we iterate in reverse order // because the UnityEditor assembly is assumed first in the assembly list. // Users can now place a copy of the StandardShaderGUI script in the project and start modifying that copy to make their own version. var unityEditorFullName = $"UnityEditor.{customEditorName}"; // for convenience: adding UnityEditor namespace is not needed in the shader foreach (var type in TypeCache.GetTypesDerivedFrom <ShaderGUI>()) { if (type.FullName.Equals(customEditorName, StringComparison.Ordinal) || type.FullName.Equals(unityEditorFullName, StringComparison.Ordinal)) { return(typeof(ShaderGUI).IsAssignableFrom(type) ? type : null); } } return(null); }
static string[] OnSourceAssetsModified(string[] changedAssets, string[] addedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { var assetMoveInfo = new AssetMoveInfo[movedAssets.Length]; Debug.Assert(movedAssets.Length == movedFromAssetPaths.Length); for (int i = 0; i < movedAssets.Length; i++) { assetMoveInfo[i] = new AssetMoveInfo(movedFromAssetPaths[i], movedAssets[i]); } var assetsReportedChanged = new HashSet <string>(); foreach (Type type in TypeCache.GetTypesDerivedFrom <AssetsModifiedProcessor>()) { var assetPostprocessor = Activator.CreateInstance(type) as AssetsModifiedProcessor; assetPostprocessor.assetsReportedChanged = assetsReportedChanged; assetPostprocessor.Internal_OnAssetsModified(changedAssets, addedAssets, deletedAssets, assetMoveInfo); assetPostprocessor.assetsReportedChanged = null; } return(assetsReportedChanged.ToArray()); }
private ILightingExplorerExtension GetLightExplorerExtension(System.Type currentSRPType) { if (currentSRPType == null) { return(GetDefaultLightingExplorerExtension()); } var extensionTypes = TypeCache.GetTypesDerivedFrom <ILightingExplorerExtension>(); foreach (System.Type extensionType in extensionTypes) { LightingExplorerExtensionAttribute attribute = System.Attribute.GetCustomAttribute(extensionType, typeof(LightingExplorerExtensionAttribute)) as LightingExplorerExtensionAttribute; if (attribute != null && attribute.renderPipelineType == currentSRPType) { ILightingExplorerExtension extension = (ILightingExplorerExtension)System.Activator.CreateInstance(extensionType); return(extension); } } // no light explorer extension found for current srp, return the default one return(GetDefaultLightingExplorerExtension()); }
void FilterSettingsChanged() { var filter = new SearchFilter(); if (m_IsShowingAssets) { filter.searchArea = SearchFilter.SearchArea.AllAssets; } filter.SearchFieldStringToFilter(m_SearchFilter); if (filter.classNames.Length == 0 && m_RequiredTypes.All(type => !string.IsNullOrEmpty(type))) { filter.classNames = m_RequiredTypes; } var hierarchyType = m_IsShowingAssets ? HierarchyType.Assets : HierarchyType.GameObjects; if (hierarchyType == HierarchyType.GameObjects) { if (m_ObjectBeingEdited != null) { var scene = GetSceneFromObject(m_ObjectBeingEdited); if (scene.IsValid()) { // We do not support cross scene references so ensure we only show game objects // from the same scene as the object being edited is part of. // Also don't allow references to other scenes if object being edited // is in a preview scene. if (EditorSceneManager.IsPreviewScene(scene) || EditorSceneManager.preventCrossSceneReferences) { filter.sceneHandles = new[] { scene.handle } } ; } } else { // If we don't know which object is being edited, assume it's one in current stage. PreviewSceneStage previewSceneStage = StageUtility.GetCurrentStage() as PreviewSceneStage; if (previewSceneStage != null) { filter.sceneHandles = new[] { previewSceneStage.scene.handle }; } } } if (hierarchyType == HierarchyType.Assets) { // When AssemblyDefinitionAsset is the required type, don't skip hidden packages foreach (var type in m_RequiredTypes) { if (!string.IsNullOrEmpty(type) && type == typeof(AssemblyDefinitionAsset).Name) { m_SkipHiddenPackages = false; break; } } filter.skipHidden = m_SkipHiddenPackages; } bool hasObject = false; var requiredTypes = new List <Type>(); var objectTypes = TypeCache.GetTypesDerivedFrom <UnityEngine.Object>(); foreach (var type in m_RequiredTypes) { foreach (var objectType in objectTypes) { if (objectType.Name == type) { requiredTypes.Add(objectType); } else if (!hasObject) { requiredTypes.Add(typeof(UnityObject)); hasObject = true; } } } m_ListArea.InitForSearch(listPosition, hierarchyType, filter, true, s => { foreach (var type in requiredTypes) { var asset = AssetDatabase.LoadAssetAtPath(s, type); if (asset != null && asset.GetInstanceID() != 0) { return(asset.GetInstanceID()); } } return(0); }, m_LegacySearchSessionOptions); }
protected Dictionary <Type, string> GetAvailableWindowTypes() { return(m_AvailableWindowTypes ?? (m_AvailableWindowTypes = TypeCache.GetTypesDerivedFrom(typeof(PlayModeView)).OrderBy(GetWindowTitle).ToDictionary(t => t, GetWindowTitle))); }
void SearchAllAssets(SearchFilter.SearchArea area) { if (m_HierarchyType == HierarchyType.Assets) { List <FilterResult> list = new List <FilterResult>(); list.AddRange(m_Results); var maxAddCount = maxSearchAddCount; m_SearchFilter.searchArea = area; var enumerator = AssetDatabase.EnumerateAllAssets(m_SearchFilter); while (enumerator.MoveNext() && --maxAddCount >= 0) { var result = new FilterResult(); CopyPropertyData(ref result, enumerator.Current); list.Add(result); } m_Results = list.ToArray(); } else if (m_HierarchyType == HierarchyType.GameObjects) { HierarchyProperty property = new HierarchyProperty(m_HierarchyType, false); m_SearchSessionHandler.BeginSession(() => { return(new SearchService.HierarchySearchContext { filter = m_SearchFilter, rootProperty = property, requiredTypeNames = m_SearchFilter.classNames, requiredTypes = searchFilter.classNames.Select(name => TypeCache.GetTypesDerivedFrom <Object>().FirstOrDefault(t => name == t.FullName || name == t.Name)) }); }); var searchQuery = m_SearchFilter.originalText; var searchContext = (SearchService.HierarchySearchContext)m_SearchSessionHandler.context; m_SearchSessionHandler.BeginSearch(searchQuery); if (m_SearchFilter.sceneHandles != null && m_SearchFilter.sceneHandles.Length > 0) { property.SetCustomScenes(m_SearchFilter.sceneHandles); } var newResults = new List <FilterResult>(); while (property.Next(null)) { if (!SearchService.Scene.Filter(searchQuery, property, searchContext)) { continue; } FilterResult newResult = new FilterResult(); CopyPropertyData(ref newResult, property); newResults.Add(newResult); } int elements = newResults.Count; elements = Mathf.Min(elements, maxSearchAddCount); int i = m_Results.Length; System.Array.Resize(ref m_Results, m_Results.Length + elements); for (var j = 0; j < elements && i < m_Results.Length; ++j, ++i) { m_Results[i] = newResults[j]; } m_SearchSessionHandler.EndSearch(); } }
protected TypeCache.TypeCollection GetAvailableWindowTypes() { return(TypeCache.GetTypesDerivedFrom(typeof(PreviewEditorWindow))); }
static MonoGizmoMethod[] ExtractGizmos(Assembly assembly) { var commands = new List <MonoGizmoMethod>(); foreach (var mi in EditorAssemblies.GetAllMethodsWithAttribute <DrawGizmo>(BindingFlags.Static).Where(m => m.DeclaringType.Assembly == assembly)) { var attrs = mi.GetCustomAttributes(typeof(DrawGizmo), false).Cast <DrawGizmo>(); foreach (var gizmoAttr in attrs) { var parameters = mi.GetParameters(); if (parameters.Length != 2) { Debug.LogWarningFormat( "Method {0}.{1} is marked with the DrawGizmo attribute but does not take parameters (ComponentType, GizmoType) so will be ignored.", mi.DeclaringType?.FullName, mi.Name ); continue; } if (mi.DeclaringType != null && mi.DeclaringType.IsGenericTypeDefinition) { Debug.LogWarningFormat( "Method {0}.{1} is marked with the DrawGizmo attribute but is defined on a generic type definition, so will be ignored.", mi.DeclaringType.FullName, mi.Name ); continue; } Type targetType; if (gizmoAttr.drawnType == null) { targetType = parameters[0].ParameterType; } else if (parameters[0].ParameterType.IsAssignableFrom(gizmoAttr.drawnType)) { targetType = gizmoAttr.drawnType; } else { Debug.LogWarningFormat( "Method {0}.{1} is marked with the DrawGizmo attribute but the component type it applies to could not be determined.", mi.DeclaringType?.FullName, mi.Name ); continue; } if (parameters[1].ParameterType != typeof(GizmoType) && parameters[1].ParameterType != typeof(int)) { Debug.LogWarningFormat( "Method {0}.{1} is marked with the DrawGizmo attribute but does not take a second parameter of type GizmoType so will be ignored.", mi.DeclaringType?.FullName, mi.Name ); continue; } if (targetType.IsInterface) { var types = TypeCache.GetTypesDerivedFrom(targetType); foreach (var type in types) { //Limit the types to the classes that have the interface and not it's children if (type.BaseType != null && type.BaseType.IsAssignableFrom(targetType)) { continue; } commands.Add(new MonoGizmoMethod { drawnType = type, drawGizmo = mi, options = (int)gizmoAttr.drawOptions, }); } } else { commands.Add(new MonoGizmoMethod { drawnType = targetType, drawGizmo = mi, options = (int)gizmoAttr.drawOptions, }); } } } return(commands.ToArray()); }
protected List <Type> GetAvailableWindowTypes() { return(m_AvailableWindowTypes ?? (m_AvailableWindowTypes = TypeCache.GetTypesDerivedFrom(typeof(PreviewEditorWindow)).OrderBy(type => type.Name).ToList())); }