I want to show the values of a struct contained in an IComponentData struct which I have defined. But the struct to show is a predefined struct from a Unity package which cannot be changed therefore. The entity inspector looks like this.
The endpoint is already expanded but empty. The code of the component shown:
[Serializable]
public struct GameSessionDefinition : IComponentData
{
public NetworkingMode NetworkingMode;
public Unity.Networking.Transport.NetworkEndpoint Endpoint;
public bool IsRenderingSuppressed;
}
As mentioned the NetworkEndpoint struct cannot be modified. It has neither a serialized attribute nor public fields. Looks like this (stripped):
namespace Unity.Networking.Transport
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct NetworkEndpoint : IEquatable<NetworkEndpoint>
{
enum AddressType { Any = 0, Loopback = 1 }
/* ... */
internal Binding.Baselib_NetworkAddress rawNetworkAddress;
/* ... */
public ushort Port
{
get => (ushort)(rawNetworkAddress.port1 | (rawNetworkAddress.port0 << 8));
set
{
rawNetworkAddress.port0 = (byte)((value >> 8) & 0xff);
rawNetworkAddress.port1 = (byte)(value & 0xff);
}
}
/* ... */
public NetworkFamily Family
{
get => FromBaselibFamily((Binding.Baselib_NetworkAddress_Family)rawNetworkAddress.family);
set => rawNetworkAddress.family = (byte)ToBaselibFamily(value);
}
/* ... */
public string Address => ToString();
/* ... */
public override string ToString()
{
return ToFixedString().ToString();
}
/* ... */
public FixedString128Bytes ToFixedString()
{
return AddressToString(ref rawNetworkAddress);
}
/* ... */
}
}
I used a method mentioned in a differnt thread relying on Inspector<> and PropertyInspector<> from the Unity package “com.unity.properties.ui” but with no success. The code is not even called.
public class NetworkEndpointPropertyInspector : Unity.Properties.UI.PropertyInspector<Unity.Networking.Transport.NetworkEndpoint>
{
private TextField field;
public override VisualElement Build()
{
this.field = new TextField(this.DisplayName) { value = this.Target.ToString() };
return this.field;
}
public override void Update()
{
this.field.SetValueWithoutNotify(this.Target.ToString());
}
}
public class NetworkEndpointInspector : Unity.Properties.UI.Inspector<Unity.Networking.Transport.NetworkEndpoint>
{
private TextField field;
public override VisualElement Build()
{
this.field = new TextField(DisplayName) { value = this.Target.ToString() };
return this.field;
}
public override void Update()
{
this.field.SetValueWithoutNotify(this.Target.ToString());
}
}
Any ideas to get it work?