Skip to content

fix: NetcodeSettingsProvider Exception [MTT-5217] #2345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Additional documentation and release notes are available at [Multiplayer Documen
- Renamed the NetworkTransform.SetState parameter `shouldGhostsInterpolate` to `teleportDisabled` for better clarity of what that parameter does. (#2228)

### Fixed
- Fixed issue where `NetcodeSettingsProvider` would throw an exception in Unity 2020.3.x versions. (#2345)
- Fixed server side issue where, depending upon component ordering, some NetworkBehaviour components might not have their OnNetworkDespawn method invoked if the client side disconnected. (#2323)
- Fixed a case where data corruption could occur when using UnityTransport when reaching a certain level of send throughput. (#2332)

- Fixed an issue in `UnityTransport` where an exception would be thrown if starting a Relay host/server on WebGL. This exception should only be thrown if using direct connections (where WebGL can't act as a host/server). (#2321)

## [1.2.0] - 2022-11-21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,46 @@ public static SettingsProvider CreateNetcodeSettingsProvider()
return provider;
}

internal static NetcodeSettingsLabel NetworkObjectsSectionLabel = new NetcodeSettingsLabel("NetworkObject Helper Settings", 20);
internal static NetcodeSettingsToggle AutoAddNetworkObjectToggle = new NetcodeSettingsToggle("Auto-Add NetworkObjects", "When enabled, NetworkObjects are automatically added to GameObjects when NetworkBehaviours are added first.", 20);
internal static NetcodeSettingsLabel MultiplayerToolsLabel = new NetcodeSettingsLabel("Multiplayer Tools", 20);
internal static NetcodeSettingsToggle MultiplayerToolTipStatusToggle = new NetcodeSettingsToggle("Multiplayer Tools Install Reminder", "When enabled, the NetworkManager will display " +
"the notification to install the multiplayer tools package.", 20);
internal static NetcodeSettingsLabel NetworkObjectsSectionLabel;
internal static NetcodeSettingsToggle AutoAddNetworkObjectToggle;
internal static NetcodeSettingsLabel MultiplayerToolsLabel;
internal static NetcodeSettingsToggle MultiplayerToolTipStatusToggle;

/// <summary>
/// Creates an instance of the settings UI Elements if they don't already exist.
/// </summary>
/// <remarks>
/// We have to construct any NetcodeGUISettings derived classes here because in
/// version 2020.x.x EditorStyles.label does not exist yet (higher versions it does)
/// </remarks>
private static void CheckForInitialize()
{
if (NetworkObjectsSectionLabel == null)
{
NetworkObjectsSectionLabel = new NetcodeSettingsLabel("NetworkObject Helper Settings", 20);
}

if (AutoAddNetworkObjectToggle == null)
{
AutoAddNetworkObjectToggle = new NetcodeSettingsToggle("Auto-Add NetworkObjects", "When enabled, NetworkObjects are automatically added to GameObjects when NetworkBehaviours are added first.", 20);
}

if (MultiplayerToolsLabel == null)
{
MultiplayerToolsLabel = new NetcodeSettingsLabel("Multiplayer Tools", 20);
}

if (MultiplayerToolTipStatusToggle == null)
{
MultiplayerToolTipStatusToggle = new NetcodeSettingsToggle("Multiplayer Tools Install Reminder", "When enabled, the NetworkManager will display the notification to install the multiplayer tools package.", 20);
}
}

private static void OnGuiHandler(string obj)
{
// Make sure all NetcodeGUISettings derived classes are instantiated first
CheckForInitialize();

var autoAddNetworkObjectSetting = NetcodeForGameObjectsSettings.GetAutoAddNetworkObjectSetting();
var multiplayerToolsTipStatus = NetcodeForGameObjectsSettings.GetNetcodeInstallMultiplayerToolTips() == 0;
EditorGUI.BeginChangeCheck();
Expand Down Expand Up @@ -56,7 +88,7 @@ public void DrawLabel()
public NetcodeSettingsLabel(string labelText, float layoutOffset = 0.0f)
{
m_LabelContent = labelText;
AdjustLableSize(labelText, layoutOffset);
AdjustLabelSize(labelText, layoutOffset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

}
}

Expand All @@ -72,7 +104,7 @@ public bool DrawToggle(bool currentSetting)

public NetcodeSettingsToggle(string labelText, string toolTip, float layoutOffset)
{
AdjustLableSize(labelText, layoutOffset);
AdjustLabelSize(labelText, layoutOffset);
m_ToggleContent = new GUIContent(labelText, toolTip);
}
}
Expand All @@ -84,11 +116,10 @@ internal class NetcodeGUISettings

protected GUILayoutOption m_LayoutWidth { get; private set; }

protected void AdjustLableSize(string labelText, float offset = 0.0f)
protected void AdjustLabelSize(string labelText, float offset = 0.0f)
{
m_LabelSize = Mathf.Min(k_MaxLabelWidth, EditorStyles.label.CalcSize(new GUIContent(labelText)).x);
m_LayoutWidth = GUILayout.Width(m_LabelSize + offset);
}
}

}