-
Notifications
You must be signed in to change notification settings - Fork 461
fix: NetworkVariables of enum types breaking the inspector [MTT-6212] #2529
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,25 @@ private void RenderNetworkVariable(int index) | |
| EditorGUILayout.BeginHorizontal(); | ||
| if (genericType.IsValueType) | ||
| { | ||
| var method = typeof(NetworkBehaviourEditor).GetMethod("RenderNetworkContainerValueType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic); | ||
| var isEquatable = false; | ||
| foreach (var iface in genericType.GetInterfaces()) | ||
| { | ||
| if (iface.IsGenericType && iface.GetGenericTypeDefinition() == typeof(IEquatable<>)) | ||
| { | ||
| isEquatable = true; | ||
| } | ||
| } | ||
|
|
||
| MethodInfo method; | ||
| if (isEquatable) | ||
| { | ||
| method = typeof(NetworkBehaviourEditor).GetMethod("RenderNetworkContainerValueTypeIEquatable", BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| } | ||
| else | ||
| { | ||
| method = typeof(NetworkBehaviourEditor).GetMethod("RenderNetworkContainerValueType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ same for "RenderNetworkContainerValueType"
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| } | ||
|
|
||
| var genericMethod = method.MakeGenericMethod(genericType); | ||
| genericMethod.Invoke(this, new[] { (object)index }); | ||
| } | ||
|
|
@@ -94,7 +112,23 @@ private void RenderNetworkVariable(int index) | |
| } | ||
| } | ||
|
|
||
| private void RenderNetworkContainerValueType<T>(int index) where T : unmanaged, IEquatable<T> | ||
| private void RenderNetworkContainerValueType<T>(int index) where T : unmanaged | ||
| { | ||
| try | ||
| { | ||
| var networkVariable = (NetworkVariable<T>)m_NetworkVariableFields[m_NetworkVariableNames[index]].GetValue(target); | ||
| RenderNetworkVariableValueType(index, networkVariable); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Debug.Log(e); | ||
| throw; | ||
| } | ||
|
|
||
| EditorGUILayout.EndHorizontal(); | ||
| } | ||
|
|
||
| private void RenderNetworkContainerValueTypeIEquatable<T>(int index) where T : unmanaged, IEquatable<T> | ||
| { | ||
| try | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we now render enum values in the inspector properly or do we just suppress/hide it? (didn't check the code yet :P but having it written in the changelog line would also be nice too, so I'm commenting this inline)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're rendered correctly. It's a fix to a regression, they're the way they were before the bug.