Skip to content

Commit ca8b520

Browse files
committed
handle objects correctly
1 parent 0664f0f commit ca8b520

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

Editor/SOVariant.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ public void NotifyOverrideChangeInState(string name, bool isOverriden)
9292
var targetFieldInfo = FieldInfoHelper.GetFieldRecursively(_target.GetType(), name);
9393
var parentFieldInfo = FieldInfoHelper.GetFieldRecursively(_SoVariantData.Parent.GetType(), name);
9494
// handle copy of list/arrays
95-
if (typeof(IEnumerable).IsAssignableFrom(targetFieldInfo.FieldType) &&
96-
targetFieldInfo.GetValue(_target) == parentFieldInfo.GetValue(_SoVariantData.Parent))
95+
if ((typeof(IEnumerable).IsAssignableFrom(targetFieldInfo.FieldType) &&
96+
targetFieldInfo.GetValue(_target) == parentFieldInfo.GetValue(_SoVariantData.Parent))
97+
|| targetFieldInfo.FieldType.BaseType == typeof(System.Object)
98+
)
9799
{
98100
object parentObject = parentFieldInfo.GetValue(_SoVariantData.Parent);
99101

Editor/SOVariantAttributeProcessor.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,19 @@ protected override void DrawPropertyLayout(GUIContent label)
145145
GUI.enabled = true;
146146
return;
147147
}
148-
148+
149149
FieldInfo targetFieldInfo = FieldInfoHelper.GetFieldRecursively(Attribute.Target.GetType(), Attribute.Name);
150150
FieldInfo parentFieldInfo = FieldInfoHelper.GetFieldRecursively(Attribute.Parent.GetType(), Attribute.Name);
151-
151+
152152
if (targetFieldInfo is null || parentFieldInfo is null)
153153
{
154154
this.CallNextDrawer(label);
155155
return;
156156
}
157157

158-
159-
GUILayout.BeginHorizontal();
158+
// if (targetFieldInfo.FieldType.Name == "String" || targetFieldInfo.FieldType.IsPrimitive)
159+
if (targetFieldInfo.FieldType.BaseType != typeof(System.Object))
160+
GUILayout.BeginHorizontal();
160161

161162
Rect rect = EditorGUILayout.GetControlRect();
162163
Rect subRect = new Rect(rect);
@@ -177,21 +178,22 @@ protected override void DrawPropertyLayout(GUIContent label)
177178
Object unityObject = value as Object;
178179
string parentFieldName =
179180
(unityObject != null) ? unityObject.name : (value != null ? value.ToString() : "None");
180-
181-
181+
182+
182183
Rect labelRect = new Rect(rect.Split(1, 2));
183-
184+
184185
GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
185186
labelStyle.normal.textColor = new Color(.5f, .5f, .5f);
186187
labelStyle.alignment = TextAnchor.MiddleRight;
187-
188+
188189
EditorGUI.LabelField(labelRect, parentFieldName, labelStyle);
189190
}
190191

191192
GUI.enabled = Attribute.IsOverriden;
192193
this.CallNextDrawer(noLabel);
193194
GUI.enabled = true;
194-
195-
GUILayout.EndHorizontal();
195+
196+
if (targetFieldInfo.FieldType.BaseType != typeof(System.Object))
197+
GUILayout.EndHorizontal();
196198
}
197199
}

0 commit comments

Comments
 (0)