diff --git a/Netick/Editor/Netick.CodeGen.dll b/Netick/Editor/Netick.CodeGen.dll index 8619a39..8c7819f 100644 Binary files a/Netick/Editor/Netick.CodeGen.dll and b/Netick/Editor/Netick.CodeGen.dll differ diff --git a/Netick/Editor/Netick.Unity.Editor.dll b/Netick/Editor/Netick.Unity.Editor.dll index 8f84486..3f2a461 100644 Binary files a/Netick/Editor/Netick.Unity.Editor.dll and b/Netick/Editor/Netick.Unity.Editor.dll differ diff --git a/Netick/Editor/Netick.Unity.Pro.Editor.dll b/Netick/Editor/Netick.Unity.Pro.Editor.dll index 7f25f45..d103935 100644 Binary files a/Netick/Editor/Netick.Unity.Pro.Editor.dll and b/Netick/Editor/Netick.Unity.Pro.Editor.dll differ diff --git a/Netick/Editor/Unity.Netick.CodeGen.dll b/Netick/Editor/Unity.Netick.CodeGen.dll index 385ca8c..b587ac2 100644 Binary files a/Netick/Editor/Unity.Netick.CodeGen.dll and b/Netick/Editor/Unity.Netick.CodeGen.dll differ diff --git a/Netick/Runtime/Netick.Pro.dll b/Netick/Runtime/Netick.Pro.dll index a98d949..d143b62 100644 Binary files a/Netick/Runtime/Netick.Pro.dll and b/Netick/Runtime/Netick.Pro.dll differ diff --git a/Netick/Runtime/Netick.Unity.Pro.dll b/Netick/Runtime/Netick.Unity.Pro.dll index 96e1a47..97fa881 100644 Binary files a/Netick/Runtime/Netick.Unity.Pro.dll and b/Netick/Runtime/Netick.Unity.Pro.dll differ diff --git a/Netick/Runtime/Netick.Unity.dll b/Netick/Runtime/Netick.Unity.dll index 12de862..ab6ef8a 100644 Binary files a/Netick/Runtime/Netick.Unity.dll and b/Netick/Runtime/Netick.Unity.dll differ diff --git a/Netick/Runtime/Netick.dll b/Netick/Runtime/Netick.dll index 28ac414..c172ef3 100644 Binary files a/Netick/Runtime/Netick.dll and b/Netick/Runtime/Netick.dll differ diff --git a/Resources/Network Icons.meta b/Resources/Network Icons.meta new file mode 100644 index 0000000..bc8028d --- /dev/null +++ b/Resources/Network Icons.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 782dd34b520f8284cb0814cda8b110c9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Network Icons/Latency.png b/Resources/Network Icons/Latency.png new file mode 100644 index 0000000..b9f3c60 Binary files /dev/null and b/Resources/Network Icons/Latency.png differ diff --git a/Resources/Network Icons/Latency.png.meta b/Resources/Network Icons/Latency.png.meta new file mode 100644 index 0000000..1b92ffc --- /dev/null +++ b/Resources/Network Icons/Latency.png.meta @@ -0,0 +1,153 @@ +fileFormatVersion: 2 +guid: eb6fa20d7adc7b24bbf6fd42a8c1c849 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Network Icons/PacketLoss.png b/Resources/Network Icons/PacketLoss.png new file mode 100644 index 0000000..264a908 Binary files /dev/null and b/Resources/Network Icons/PacketLoss.png differ diff --git a/Resources/Network Icons/PacketLoss.png.meta b/Resources/Network Icons/PacketLoss.png.meta new file mode 100644 index 0000000..2c0019d --- /dev/null +++ b/Resources/Network Icons/PacketLoss.png.meta @@ -0,0 +1,153 @@ +fileFormatVersion: 2 +guid: 112899f4f25b21643b5b16572a335708 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Network Icons/ServerLag.png b/Resources/Network Icons/ServerLag.png new file mode 100644 index 0000000..bb94e85 Binary files /dev/null and b/Resources/Network Icons/ServerLag.png differ diff --git a/Resources/Network Icons/ServerLag.png.meta b/Resources/Network Icons/ServerLag.png.meta new file mode 100644 index 0000000..d161ddd --- /dev/null +++ b/Resources/Network Icons/ServerLag.png.meta @@ -0,0 +1,153 @@ +fileFormatVersion: 2 +guid: fe073c3e22414a449a3f4edbd22eb225 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GameStarter.cs b/Scripts/GameStarter.cs index 85cee03..7128cfb 100644 --- a/Scripts/GameStarter.cs +++ b/Scripts/GameStarter.cs @@ -17,14 +17,21 @@ namespace Netick.Samples public bool AutoStart; public bool AutoConnect; - public bool ShowDisconnectButton = true; - public bool ShowConnectButton = true; - + [Header("Network")] [Range(0, 65535)] public int Port; public string ServerIPAddress = "127.0.0.1"; + [Header("Headless Server FPS")] + public bool Cap = true; + public int FPS = 450; + + [Header("UI")] + public bool ShowDisconnectButton = true; + public bool ShowConnectButton = true; + public Vector2 Offset = new Vector2(36, 0); + private void Reset() { if (Port == 0) @@ -35,6 +42,7 @@ namespace Netick.Samples { if (Application.isBatchMode) { + Application.targetFrameRate = FPS; Network.StartAsServer(Transport, Port, SandboxPrefab); } @@ -72,24 +80,27 @@ namespace Netick.Samples { if (Sandbox != null && Sandbox.IsClient) { + if (!Sandbox.IsVisible) + return; + if (Sandbox.IsConnected) { if (ShowDisconnectButton) { - GUI.Label(new Rect(10, 130, 200, 50), $"Connected to {Sandbox.ServerEndPoint}"); + GUI.Label(new Rect(Offset.x, Offset.y + 170, 200, 50), $"Connected to {Sandbox.ServerEndPoint}"); - if (GUI.Button(new Rect(10, 220, 200, 50), "Disconnect")) + if (GUI.Button(new Rect(Offset.x, Offset.y + 220, 200, 50), "Disconnect")) Sandbox.DisconnectFromServer(); } } else if (ShowConnectButton) { - if (GUI.Button(new Rect(10, 10, 200, 50), "Connect")) + if (GUI.Button(new Rect(Offset.x, Offset.y + 40, 200, 50), "Connect")) Sandbox.Connect(Port, ServerIPAddress); - ServerIPAddress = GUI.TextField(new Rect(10, 70, 200, 50), ServerIPAddress); - Port = int.Parse(GUI.TextField(new Rect(10, 130, 200, 50), Port.ToString())); + ServerIPAddress = GUI.TextField(new Rect(Offset.x, Offset.y + 100, 200, 50), ServerIPAddress); + Port = int.Parse(GUI.TextField(new Rect(Offset.x, Offset.y+ 160, 200, 50), Port.ToString())); } } @@ -97,23 +108,23 @@ namespace Netick.Samples return; } - if (GUI.Button(new Rect(10, 10, 200, 50), "Run Host")) + if (GUI.Button(new Rect(Offset.x, Offset.y + 40, 200, 50), "Run Host")) { Network.StartAsHost(Transport, Port, SandboxPrefab); } - if (GUI.Button(new Rect(10, 70, 200, 50), "Run Client")) + if (GUI.Button(new Rect(Offset.x, Offset.y + 100, 200, 50), "Run Client")) { var sandbox = Network.StartAsClient(Transport, Port, SandboxPrefab); sandbox.Connect(Port, ServerIPAddress); } - if (GUI.Button(new Rect(10, 130, 200, 50), "Run Server")) + if (GUI.Button(new Rect(Offset.x, Offset.y + 160, 200, 50), "Run Server")) { Network.StartAsServer(Transport, Port, SandboxPrefab); } - if (GUI.Button(new Rect(10, 190, 200, 50), "Run Host + Client")) + if (GUI.Button(new Rect(Offset.x, Offset.y + 220, 200, 50), "Run Host + Client")) { var sandboxes = Network.StartAsMultiplePeers(Transport, Port, SandboxPrefab, StartServerInMultiplePeersMode, true, Clients); @@ -124,7 +135,7 @@ namespace Netick.Samples } } - ServerIPAddress = GUI.TextField(new Rect(10, 250, 200, 50), ServerIPAddress); + ServerIPAddress = GUI.TextField(new Rect(Offset.x, Offset.y + 280, 200, 50), ServerIPAddress); } } diff --git a/Scripts/NetworkInfo.cs b/Scripts/NetworkInfo.cs index c53fdc2..00c81d9 100644 --- a/Scripts/NetworkInfo.cs +++ b/Scripts/NetworkInfo.cs @@ -7,27 +7,86 @@ namespace Netick.Samples { [AddComponentMenu("Netick/Network Info")] public class NetworkInfo : NetworkEventsListener - { + { + [Header("Network Stats")] + public Vector2 Offset = new Vector2(27, 20); + + [Header("Network Conditions Icons")] + public float MediumLatencyThreshold = 150; + public float HighLatencyThreshold = 250; + public float MediumPacketLossThreshold = 1; + public float HighPacketLossThreshold = 10; + + public Vector2 Icon1Offset = new Vector2(-80, 30); + public Vector2 Icon2Offset = new Vector2(-80, 70); + public Vector2 Icon3Offset = new Vector2(-80, 110); + public float IconSize = 30; + + private Texture _packetLossIcon; + private Texture _latencyIcon; + private Texture _serverLagIcon; + + private void Awake() + { + _packetLossIcon = Resources.Load("Network Icons/PacketLoss"); + _latencyIcon = Resources.Load("Network Icons/Latency"); + _serverLagIcon = Resources.Load("Network Icons/ServerLag"); + } + private void OnGUI() { - if (Network.Instance != null) + if (Network.IsRunning) { if (Sandbox != null && Sandbox.IsConnected) { - Draw(0, "In", Sandbox.InKBps.ToString(), "KB/s"); - Draw(1, "Out", Sandbox.OutKBps.ToString(), "KB/s"); - Draw(2, "RTT", (Sandbox.RTT * 1000f).ToString(), "ms"); - Draw(3, "Interp Delay", (Sandbox.InterpolationDelay * 1000f).ToString(), "ms"); - Draw(4, "Resims", Sandbox.Monitor.Resimulations.Average.ToString(), "Ticks"); - Draw(5, "Delta time", (Time.deltaTime * 1000f).ToString(), "ms"); + DrawText(0, "RTT", (Sandbox.RTT * 1000f).ToString(), "ms"); + DrawText(1, "In", Sandbox.InKBps.ToString(), "KB/s"); + DrawText(2, "Out", Sandbox.OutKBps.ToString(), "KB/s"); + DrawText(3, "In Loss", (Sandbox.InPacketLoss * 100f).ToString(), "%"); + DrawText(4, "Out Loss", (Sandbox.OutPacketLoss * 100f).ToString(), "%"); + DrawText(5, "Interp Delay", (Sandbox.InterpolationDelay * 1000f).ToString(), "ms"); + DrawText(6, "Resims", Sandbox.Monitor.Resimulations.Average.ToString(), "Ticks"); + DrawText(7, "Srv Tick Time", (Sandbox.Monitor.ServerTickTime.Max * 1000f).ToString(), "ms"); + DrawText(8, "Delta time", (Time.deltaTime * 1000f).ToString(), "ms"); + + DrawIcons(); } } } - private void Draw(int offset, string title, string content, string unit) + private void DrawText(int offset, string title, string content, string unit) { - GUI.Label(new Rect(10, 10 + (15 * offset), 200, 50), $"{title}: "); - GUI.Label(new Rect(130, 10 + (15 * offset), 200, 50), $"{content} {unit}"); + GUI.Label(new Rect(Offset.x + 10, Offset.y + 10 + (15 * offset), 200, 50), $"{title}: "); + GUI.Label(new Rect(Offset.x + 130, Offset.y + 10 + (15 * offset), 200, 50), $"{content} {unit}"); + } + + public void DrawIcons() + { + var pktLossIconPos = Icon1Offset + (Screen.width * Vector2.right); + var latencyIconPos = Icon2Offset + (Screen.width * Vector2.right); + var serverLagIconPos = Icon3Offset + (Screen.width * Vector2.right); + + var pktLoss = Mathf.Max(Sandbox.InPacketLoss, Sandbox.OutPacketLoss) * 100; // multiplying by 100 to convert from a decimal to a percentage. + var rtt = Sandbox.RTT * 1000f; // multiplying by 1000 to convert from seconds to milliseconds. + + if (pktLoss >= MediumPacketLossThreshold) + { + Color color = pktLoss < HighPacketLossThreshold ? Color.yellow : Color.red; + GUI.DrawTexture(new Rect(pktLossIconPos, Vector2.one * IconSize), _packetLossIcon, ScaleMode.ScaleToFit, true, 1f, color, 0f, 0f); + } + + if (rtt >= MediumLatencyThreshold) + { + Color color = rtt >= HighLatencyThreshold ? Color.red : Color.yellow; + GUI.DrawTexture(new Rect(latencyIconPos, Vector2.one * IconSize), _latencyIcon, ScaleMode.ScaleToFit, true, 1f, color, 0f, 0f); + } + + if (Sandbox.Monitor.ServerTickTime.Max >= Sandbox.FixedDeltaTime) + { + Color color = Sandbox.Monitor.ServerTickTime.Average >= Sandbox.FixedDeltaTime ? Color.red : Color.yellow; + GUI.DrawTexture(new Rect(serverLagIconPos, Vector2.one * IconSize), _serverLagIcon, ScaleMode.ScaleToFit, true, 1f, color, 0f, 0f); + } + } } } diff --git a/package.json b/package.json index 4dc98fb..3707f32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.karrar.netick", - "version": "0.12.20", + "version": "0.12.21", "displayName": "Netick", "description": "A networking solution for Unity", "unity": "2021.3",