Skip to content

Commit

Permalink
Null选项防止第一位
Browse files Browse the repository at this point in the history
  • Loading branch information
KumoKyaku committed Feb 12, 2024
1 parent 3a62dac commit 7c6aafb
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ protected void DrawReference(SerializedProperty property, GUIContent label, Rect
}
}
}
else
{
index = 0;
SelectedIndex[indexCacheKey] = 0;
}
}

var oldSelectedIndex = index;
Expand Down Expand Up @@ -581,8 +586,7 @@ public void CacheSupportType(SerializedProperty property)

if (property.propertyType == SerializedPropertyType.ManagedReference)
{
//一般类型,因为没办法设置为null,在下拉菜单中最后加入null类型,用于清空当前值
int index = 0;

SupportNames = new string[allTypes.Count + 1];
SupportTypes = new Type[allTypes.Count + 1];

Expand All @@ -591,6 +595,12 @@ public void CacheSupportType(SerializedProperty property)
var indexCacheKey = (property.serializedObject.targetObject, property.propertyPath, property.managedReferenceValue);
SelectedIndex[indexCacheKey] = allTypes.Count;

//一般类型,因为没办法设置为null,在下拉菜单中第一项加入null类型,用于清空当前值
int index = 0;
SupportNames[index] = "Null";
SupportTypes[index] = null;
index++;

foreach (var item in allTypes)
{
SupportNames[index] = item.Name;
Expand All @@ -602,9 +612,6 @@ public void CacheSupportType(SerializedProperty property)
}
index++;
}

SupportNames[allTypes.Count] = "Null";
SupportTypes[allTypes.Count] = null;
}
else
{
Expand Down

0 comments on commit 7c6aafb

Please sign in to comment.