private static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : UnityEngine.Object, new() { GenericMenu genericMenu = new GenericMenu(); int num = (!(serializedProperty.objectReferenceValue != null)) ? 0 : serializedProperty.objectReferenceValue.GetInstanceID(); genericMenu.AddItem(new GUIContent(defaultFieldName), num == 0, new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback), new object[] { 0, serializedProperty }); HierarchyProperty hierarchyProperty = new HierarchyProperty(HierarchyType.Assets); SearchFilter searchFilter = new SearchFilter { classNames = new string[] { typeName } }; hierarchyProperty.SetSearchFilter(searchFilter); hierarchyProperty.Reset(); while (hierarchyProperty.Next(null)) { genericMenu.AddItem(new GUIContent(hierarchyProperty.name), hierarchyProperty.instanceID == num, new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback), new object[] { hierarchyProperty.instanceID, serializedProperty }); } int num2 = BaseObjectTools.StringToClassID(typeName); if (num2 > 0) { BuiltinResource[] builtinResourceList = EditorGUIUtility.GetBuiltinResourceList(num2); BuiltinResource[] array = builtinResourceList; for (int i = 0; i < array.Length; i++) { BuiltinResource builtinResource = array[i]; genericMenu.AddItem(new GUIContent(builtinResource.m_Name), builtinResource.m_InstanceID == num, new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback), new object[] { builtinResource.m_InstanceID, serializedProperty }); } } genericMenu.AddSeparator(string.Empty); genericMenu.AddItem(new GUIContent("Create New..."), false, delegate { T t = Activator.CreateInstance <T>(); ProjectWindowUtil.CreateAsset(t, "New " + typeName + "." + fileExtension); serializedProperty.objectReferenceValue = t; serializedProperty.m_SerializedObject.ApplyModifiedProperties(); }); genericMenu.DropDown(buttonRect); }
static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : Object, new() { GenericMenu gm = new GenericMenu(); int selectedInstanceID = serializedProperty.objectReferenceValue != null?serializedProperty.objectReferenceValue.GetInstanceID() : 0; bool foundDefaultAsset = false; var type = UnityEditor.UnityType.FindTypeByName(typeName); int classID = type != null ? type.persistentTypeID : 0; BuiltinResource[] resourceList = null; // Check the assets for one that matches the default name. if (classID > 0) { resourceList = EditorGUIUtility.GetBuiltinResourceList(classID); foreach (var resource in resourceList) { if (resource.m_Name == defaultFieldName) { gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty }); resourceList = resourceList.Where(x => x != resource).ToArray(); foundDefaultAsset = true; break; } } } // If no defalut asset was found, add defualt null value. if (!foundDefaultAsset) { gm.AddItem(new GUIContent(defaultFieldName), selectedInstanceID == 0, AssetPopupMenuCallback, new object[] { 0, serializedProperty }); } // Add items from asset database foreach (var property in AssetDatabase.FindAllAssets(new SearchFilter() { classNames = new[] { typeName } })) { gm.AddItem(new GUIContent(property.name), property.instanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { property.instanceID, serializedProperty }); } // Add builtin items, except for the already added default item. if (classID > 0 && resourceList != null) { foreach (var resource in resourceList) { gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty }); } } var target = serializedProperty.serializedObject.targetObject; bool isPreset = target is Component ? ((int)(target as Component).gameObject.hideFlags == 93) : !AssetDatabase.Contains(target); // the preset object is destroyed with the inspector, and nothing new can be created that needs this link. Fix for case 1208437 if (!isPreset) { // Create item gm.AddSeparator(""); gm.AddItem(EditorGUIUtility.TrTextContent("Create New..."), false, delegate { var newAsset = Activator.CreateInstance <T>(); var doCreate = ScriptableObject.CreateInstance <DoCreateNewAsset>(); doCreate.SetProperty(serializedProperty); ProjectWindowUtil.StartNameEditingIfProjectWindowExists(newAsset.GetInstanceID(), doCreate, "New " + typeName + "." + fileExtension, AssetPreview.GetMiniThumbnail(newAsset), null); }); } gm.DropDown(buttonRect); }
// private static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : Object, new() { GenericMenu gm = new GenericMenu(); int selectedInstanceID = serializedProperty.objectReferenceValue != null?serializedProperty.objectReferenceValue.GetInstanceID() : 0; bool foundDefaultAsset = false; var type = UnityEditor.UnityType.FindTypeByName(typeName); int classID = type != null ? type.persistentTypeID : 0; BuiltinResource[] resourceList = null; // Check the assets for one that matches the default name. if (classID > 0) { resourceList = EditorGUIUtility.GetBuiltinResourceList(classID); foreach (var resource in resourceList) { if (resource.m_Name == defaultFieldName) { gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty }); resourceList = resourceList.Where(x => x != resource).ToArray(); foundDefaultAsset = true; break; } } } // If no defalut asset was found, add defualt null value. if (!foundDefaultAsset) { gm.AddItem(new GUIContent(defaultFieldName), selectedInstanceID == 0, AssetPopupMenuCallback, new object[] { 0, serializedProperty }); } // Add items from asset database foreach (var property in AssetDatabase.FindAllAssets(new SearchFilter() { classNames = new[] { typeName } })) { gm.AddItem(new GUIContent(property.name), property.instanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { property.instanceID, serializedProperty }); } // Add builtin items, except for the already added default item. if (classID > 0 && resourceList != null) { foreach (var resource in resourceList) { gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty }); } } // Create item gm.AddSeparator(""); gm.AddItem(EditorGUIUtility.TrTextContent("Create New..."), false, delegate { var newAsset = Activator.CreateInstance <T>(); ProjectWindowUtil.CreateAsset(newAsset, "New " + typeName + "." + fileExtension); serializedProperty.objectReferenceValue = newAsset; serializedProperty.m_SerializedObject.ApplyModifiedProperties(); }); gm.DropDown(buttonRect); }
private static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : UnityEngine.Object, new() { GenericMenu genericMenu = new GenericMenu(); int num = (!(serializedProperty.objectReferenceValue != null)) ? 0 : serializedProperty.objectReferenceValue.GetInstanceID(); bool flag = false; UnityType unityType = UnityType.FindTypeByName(typeName); int num2 = (unityType == null) ? 0 : unityType.persistentTypeID; BuiltinResource[] array = null; if (num2 > 0) { array = EditorGUIUtility.GetBuiltinResourceList(num2); BuiltinResource[] array2 = array; for (int i = 0; i < array2.Length; i++) { BuiltinResource resource = array2[i]; if (resource.m_Name == defaultFieldName) { GenericMenu arg_124_0 = genericMenu; GUIContent arg_124_1 = new GUIContent(resource.m_Name); bool arg_124_2 = resource.m_InstanceID == num; if (AssetPopupBackend.< > f__mg$cache0 == null) { AssetPopupBackend.< > f__mg$cache0 = new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback); } arg_124_0.AddItem(arg_124_1, arg_124_2, AssetPopupBackend.< > f__mg$cache0, new object[] { resource.m_InstanceID, serializedProperty }); array = (from x in array where x != resource select x).ToArray <BuiltinResource>(); flag = true; break; } } } if (!flag) { GenericMenu arg_1A6_0 = genericMenu; GUIContent arg_1A6_1 = new GUIContent(defaultFieldName); bool arg_1A6_2 = num == 0; if (AssetPopupBackend.< > f__mg$cache1 == null) { AssetPopupBackend.< > f__mg$cache1 = new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback); } arg_1A6_0.AddItem(arg_1A6_1, arg_1A6_2, AssetPopupBackend.< > f__mg$cache1, new object[] { 0, serializedProperty }); } HierarchyProperty hierarchyProperty = new HierarchyProperty(HierarchyType.Assets); SearchFilter searchFilter = new SearchFilter { classNames = new string[] { typeName } }; hierarchyProperty.SetSearchFilter(searchFilter); hierarchyProperty.Reset(); while (hierarchyProperty.Next(null)) { GenericMenu arg_23D_0 = genericMenu; GUIContent arg_23D_1 = new GUIContent(hierarchyProperty.name); bool arg_23D_2 = hierarchyProperty.instanceID == num; if (AssetPopupBackend.< > f__mg$cache2 == null) { AssetPopupBackend.< > f__mg$cache2 = new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback); } arg_23D_0.AddItem(arg_23D_1, arg_23D_2, AssetPopupBackend.< > f__mg$cache2, new object[] { hierarchyProperty.instanceID, serializedProperty }); } if (num2 > 0 && array != null) { BuiltinResource[] array3 = array; for (int j = 0; j < array3.Length; j++) { BuiltinResource builtinResource = array3[j]; GenericMenu arg_2C7_0 = genericMenu; GUIContent arg_2C7_1 = new GUIContent(builtinResource.m_Name); bool arg_2C7_2 = builtinResource.m_InstanceID == num; if (AssetPopupBackend.< > f__mg$cache3 == null) { AssetPopupBackend.< > f__mg$cache3 = new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback); } arg_2C7_0.AddItem(arg_2C7_1, arg_2C7_2, AssetPopupBackend.< > f__mg$cache3, new object[] { builtinResource.m_InstanceID, serializedProperty }); } } genericMenu.AddSeparator(""); genericMenu.AddItem(new GUIContent("Create New..."), false, delegate { T t = Activator.CreateInstance <T>(); ProjectWindowUtil.CreateAsset(t, "New " + typeName + "." + fileExtension); serializedProperty.objectReferenceValue = t; serializedProperty.m_SerializedObject.ApplyModifiedProperties(); }); genericMenu.DropDown(buttonRect); }
private static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension) where T : Object, new() { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type AssetPopupBackend.\u003CShowAssetsPopupMenu\u003Ec__AnonStorey76 <T> menuCAnonStorey76 = new AssetPopupBackend.\u003CShowAssetsPopupMenu\u003Ec__AnonStorey76 <T>(); // ISSUE: reference to a compiler-generated field menuCAnonStorey76.typeName = typeName; // ISSUE: reference to a compiler-generated field menuCAnonStorey76.fileExtension = fileExtension; // ISSUE: reference to a compiler-generated field menuCAnonStorey76.serializedProperty = serializedProperty; GenericMenu genericMenu = new GenericMenu(); // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field int num = !(menuCAnonStorey76.serializedProperty.objectReferenceValue != (Object)null) ? 0 : menuCAnonStorey76.serializedProperty.objectReferenceValue.GetInstanceID(); // ISSUE: reference to a compiler-generated field genericMenu.AddItem(new GUIContent("Default"), (num == 0 ? 1 : 0) != 0, new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback), (object)new object[2] { (object)0, (object)menuCAnonStorey76.serializedProperty }); HierarchyProperty hierarchyProperty = new HierarchyProperty(HierarchyType.Assets); // ISSUE: reference to a compiler-generated field SearchFilter filter = new SearchFilter() { classNames = new string[1] { menuCAnonStorey76.typeName } }; hierarchyProperty.SetSearchFilter(filter); hierarchyProperty.Reset(); while (hierarchyProperty.Next((int[])null)) { // ISSUE: reference to a compiler-generated field genericMenu.AddItem(new GUIContent(hierarchyProperty.name), (hierarchyProperty.instanceID == num ? 1 : 0) != 0, new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback), (object)new object[2] { (object)hierarchyProperty.instanceID, (object)menuCAnonStorey76.serializedProperty }); } // ISSUE: reference to a compiler-generated field int classId = BaseObjectTools.StringToClassID(menuCAnonStorey76.typeName); if (classId > 0) { foreach (BuiltinResource builtinResource in EditorGUIUtility.GetBuiltinResourceList(classId)) { // ISSUE: reference to a compiler-generated field genericMenu.AddItem(new GUIContent(builtinResource.m_Name), (builtinResource.m_InstanceID == num ? 1 : 0) != 0, new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback), (object)new object[2] { (object)builtinResource.m_InstanceID, (object)menuCAnonStorey76.serializedProperty }); } } genericMenu.AddSeparator(string.Empty); // ISSUE: reference to a compiler-generated method genericMenu.AddItem(new GUIContent("Create New..."), false, new GenericMenu.MenuFunction(menuCAnonStorey76.\u003C\u003Em__10A)); genericMenu.DropDown(buttonRect); }