|
17 | 17 | using UnityEngineInternal; |
18 | 18 | using UnityEditor.StyleSheets; |
19 | 19 | using UnityEditor.Experimental; |
| 20 | +using UnityEditor.SceneManagement; |
20 | 21 | using UnityEngine.UIElements; |
21 | 22 | using UnityObject = UnityEngine.Object; |
22 | 23 |
|
@@ -118,6 +119,9 @@ internal static Material GUITextureBlitSceneGUIMaterial |
118 | 119 | private static readonly GUIContent s_Image = new GUIContent(); |
119 | 120 | private static readonly GUIContent s_TextImage = new GUIContent(); |
120 | 121 |
|
| 122 | + private static GUIContent s_SceneMismatch = TrTextContent("Scene mismatch (cross scene references not supported)"); |
| 123 | + private static GUIContent s_TypeMismatch = TrTextContent("Type mismatch"); |
| 124 | + |
121 | 125 | internal static readonly SVC<Color> kViewBackgroundColor = new SVC<Color>("view", StyleCatalogKeyword.backgroundColor, GetDefaultBackgroundColor); |
122 | 126 |
|
123 | 127 | /// The current UI scaling factor for high-DPI displays. For instance, 2.0 on a retina display |
@@ -976,6 +980,54 @@ internal static GUIContent ObjectContent(UnityObject obj, Type type, int instanc |
976 | 980 | return s_ObjectContent; |
977 | 981 | } |
978 | 982 |
|
| 983 | + internal static GUIContent ObjectContent(UnityObject obj, Type type, SerializedProperty property, EditorGUI.ObjectFieldValidator validator = null) |
| 984 | + { |
| 985 | + if (validator == null) |
| 986 | + validator = EditorGUI.ValidateObjectFieldAssignment; |
| 987 | + |
| 988 | + GUIContent temp; |
| 989 | + |
| 990 | + // If obj or objType are both null, we have to rely on |
| 991 | + // property.objectReferenceStringValue to display None/Missing and the |
| 992 | + // correct type. But if not, EditorGUIUtility.ObjectContent is more reliable. |
| 993 | + // It can take a more specific object type specified as argument into account, |
| 994 | + // and it gets the icon at the same time. |
| 995 | + if (obj == null && type == null && property != null) |
| 996 | + { |
| 997 | + temp = TempContent(property.objectReferenceStringValue); |
| 998 | + } |
| 999 | + else |
| 1000 | + { |
| 1001 | + // In order for ObjectContext to be able to distinguish between None/Missing, |
| 1002 | + // we need to supply an instanceID. For some reason, getting the instanceID |
| 1003 | + // from property.objectReferenceValue is not reliable, so we have to |
| 1004 | + // explicitly check property.objectReferenceInstanceIDValue if a property exists. |
| 1005 | + if (property != null) |
| 1006 | + temp = ObjectContent(obj, type, property.objectReferenceInstanceIDValue); |
| 1007 | + else |
| 1008 | + temp = ObjectContent(obj, type); |
| 1009 | + } |
| 1010 | + |
| 1011 | + if (property != null) |
| 1012 | + { |
| 1013 | + if (obj != null) |
| 1014 | + { |
| 1015 | + UnityObject[] references = { obj }; |
| 1016 | + if (EditorSceneManager.preventCrossSceneReferences && EditorGUI.CheckForCrossSceneReferencing(obj, property.serializedObject.targetObject)) |
| 1017 | + { |
| 1018 | + if (!EditorApplication.isPlaying) |
| 1019 | + temp = s_SceneMismatch; |
| 1020 | + else |
| 1021 | + temp.text = temp.text + string.Format(" ({0})", EditorGUI.GetGameObjectFromObject(obj).scene.name); |
| 1022 | + } |
| 1023 | + else if (validator(references, type, property, EditorGUI.ObjectFieldValidatorOptions.ExactObjectTypeValidation) == null) |
| 1024 | + temp = s_TypeMismatch; |
| 1025 | + } |
| 1026 | + } |
| 1027 | + |
| 1028 | + return temp; |
| 1029 | + } |
| 1030 | + |
979 | 1031 | internal static GUIContent TempContent(string t) |
980 | 1032 | { |
981 | 1033 | s_Text.image = null; |
|
0 commit comments