fix: Draw SyncVar label for Unity objects inline (#1291)

* SyncVar label for Unity objects is now drawn inline instead of on the next line

* Made syncVarIndicatorContent static

Did it since there's no need to have that allocation per editor instance.
This commit is contained in:
Tor Esa Vestergaard 2019-12-07 14:29:14 +01:00 committed by vis2k
parent c8aabd246a
commit a0425e4e84

View File

@ -17,7 +17,7 @@ public class NetworkBehaviourInspector : Editor
bool syncsAnything;
bool[] showSyncLists;
readonly GUIContent syncVarIndicatorContent = new GUIContent("SyncVar", "This variable has been marked with the [SyncVar] attribute.");
static readonly GUIContent syncVarIndicatorContent = new GUIContent("SyncVar", "This variable has been marked with the [SyncVar] attribute.");
internal virtual bool HideScriptField => false;
@ -106,43 +106,37 @@ public override void OnInspectorGUI()
while (property.NextVisible(expanded))
{
bool isSyncVar = syncVarNames.Contains(property.name);
if (property.propertyType == SerializedPropertyType.ObjectReference)
if (property.name == "m_Script")
{
if (property.name == "m_Script")
if (HideScriptField)
{
if (HideScriptField)
{
continue;
}
EditorGUI.BeginDisabledGroup(true);
continue;
}
EditorGUILayout.PropertyField(property, true);
if (isSyncVar)
{
GUILayout.Label(syncVarIndicatorContent, EditorStyles.miniLabel, GUILayout.Width(EditorStyles.miniLabel.CalcSize(syncVarIndicatorContent).x));
}
if (property.name == "m_Script")
{
EditorGUI.EndDisabledGroup();
}
EditorGUI.BeginDisabledGroup(true);
}
else
if (isSyncVar)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.BeginVertical();
}
EditorGUILayout.PropertyField(property, true);
if (isSyncVar)
{
GUILayout.Label(syncVarIndicatorContent, EditorStyles.miniLabel, GUILayout.Width(EditorStyles.miniLabel.CalcSize(syncVarIndicatorContent).x));
}
EditorGUILayout.PropertyField(property, true);
if (isSyncVar)
{
EditorGUILayout.EndVertical();
GUILayout.Label(syncVarIndicatorContent, EditorStyles.miniLabel, GUILayout.Width(EditorStyles.miniLabel.CalcSize(syncVarIndicatorContent).x));
EditorGUILayout.EndHorizontal();
}
if (property.name == "m_Script")
{
EditorGUI.EndDisabledGroup();
}
expanded = false;
}
serializedObject.ApplyModifiedProperties();