11using System ;
22using System . Collections . Generic ;
3-
43using UnityEditor ;
54using UnityEngine ;
65
@@ -14,7 +13,6 @@ public class TypeField
1413 private TypeConstraintContext constraintContext ;
1514 private TypeAppearanceContext appearanceContext ;
1615
17-
1816 public TypeField ( ) : this ( null , null )
1917 { }
2018
@@ -27,7 +25,6 @@ public TypeField(TypeConstraintContext constraintContext, TypeAppearanceContext
2725 this . appearanceContext = appearanceContext ?? new TypeAppearanceContext ( this . constraintContext , TypeGrouping . None , true ) ;
2826 }
2927
30-
3128 private Type RetriveSelectedType ( IReadOnlyList < Type > types , int selectedIndex , bool includeEmptyValue )
3229 {
3330 if ( includeEmptyValue )
@@ -38,6 +35,18 @@ private Type RetriveSelectedType(IReadOnlyList<Type> types, int selectedIndex, b
3835 return selectedIndex >= 0 ? types [ selectedIndex ] : null ;
3936 }
4037
38+ private void DrawTypeConflictWarning ( Rect position )
39+ {
40+ const float warningSpace = 18.0f ;
41+
42+ var warningPosition = position ;
43+ warningPosition . xMax = position . xMin ;
44+ warningPosition . xMin -= warningSpace ;
45+ var warningIcon = EditorGuiUtility . GetHelpIcon ( MessageType . Warning ) ;
46+ var warningLabel = new GUIContent ( warningIcon , "Currently active type is not available from the selection. " +
47+ "It may be caused by a conflict between the type filter and cached data." ) ;
48+ GUI . Label ( warningPosition , warningLabel ) ;
49+ }
4150
4251 public void OnGui ( Rect position , bool addSearchField , Action < Type > onSelect )
4352 {
@@ -46,12 +55,19 @@ public void OnGui(Rect position, bool addSearchField, Action<Type> onSelect)
4655
4756 public void OnGui ( Rect position , bool addSearchField , Action < Type > onSelect , Type activeType )
4857 {
58+ var addEmptyValue = AppearanceContext . AddEmptyValue ;
59+
4960 var collection = TypeUtilities . GetCollection ( AppearanceContext ) ;
5061 var values = collection . Values ;
5162 var labels = collection . Labels ;
5263 var index = collection . IndexOf ( activeType ) ;
5364
54- var addEmptyValue = AppearanceContext . AddEmptyValue ;
65+ var selectedType = RetriveSelectedType ( values , index , addEmptyValue ) ;
66+ if ( activeType != selectedType )
67+ {
68+ DrawTypeConflictWarning ( position ) ;
69+ }
70+
5571 if ( addSearchField )
5672 {
5773 var buttonLabel = new GUIContent ( labels [ index ] ) ;
@@ -82,7 +98,6 @@ public void OnGui(Rect position, bool addSearchField, Action<Type> onSelect, Typ
8298 OnGui ( position , addSearchField , onSelect , activeType ) ;
8399 }
84100
85-
86101 public TypeConstraintContext ConstraintContext
87102 {
88103 get => constraintContext ;
0 commit comments