Skip to content

Commit

Permalink
ADDED: Simple Connection Stats UI Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonmelo committed Jan 14, 2021
1 parent 69fc26d commit ff3343c
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 0 deletions.
8 changes: 8 additions & 0 deletions BoltRealtimeStats.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions BoltRealtimeStats/Prefabs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added BoltRealtimeStats/Prefabs/BoltStats.prefab
Binary file not shown.
7 changes: 7 additions & 0 deletions BoltRealtimeStats/Prefabs/BoltStats.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added BoltRealtimeStats/Prefabs/FrameStats.prefab
Binary file not shown.
7 changes: 7 additions & 0 deletions BoltRealtimeStats/Prefabs/FrameStats.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions BoltRealtimeStats/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions BoltRealtimeStats/Scripts/BoltFrameController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using Photon.Bolt;
using UnityEngine;
using UnityEngine.UI;

public class BoltFrameController : MonoBehaviour
{
[SerializeField] private Text Label;
[SerializeField] private Text ValuePing;
[SerializeField] private Text ValueBitsInt;
[SerializeField] private Text ValueBitsOut;

public void SetLabel(BoltConnection connection)
{
this.Label.text = string.Format("[{0}] {1}", connection.ConnectionType, connection.RemoteEndPoint.ToString());
}

public void SetValue(float ping, float bitsIn, float bitsOut)
{
this.ValuePing.text = ping.ToString();
this.ValueBitsInt.text = bitsIn.ToString();
this.ValueBitsOut.text = bitsOut.ToString();
}
}
11 changes: 11 additions & 0 deletions BoltRealtimeStats/Scripts/BoltFrameController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions BoltRealtimeStats/Scripts/BoltStatsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using Photon.Bolt;
using UnityEngine;
using UnityEngine.UI;

public class BoltStatsController : GlobalEventListener
{
[SerializeField] private GameObject RemoteConnectionHolder;
[SerializeField] private GameObject FrameStatPrefab;

private Dictionary<BoltConnection, BoltFrameController> remoteFrameStateMap;

void Start()
{
remoteFrameStateMap = new Dictionary<BoltConnection, BoltFrameController>();
}

void FixedUpdate()
{
if (BoltNetwork.IsRunning)
{
foreach (var conn in BoltNetwork.Connections)
{
if (remoteFrameStateMap.TryGetValue(conn, out var frameController) == false)
{
var frameControllerGO = Instantiate(FrameStatPrefab);
frameControllerGO.transform.parent = RemoteConnectionHolder.transform;

frameController = frameControllerGO.GetComponent<BoltFrameController>();
frameController.SetLabel(conn);

remoteFrameStateMap.Add(conn, frameController);
}

frameController.SetValue(conn.PingNetwork * 1000, conn.BitsPerSecondIn, conn.BitsPerSecondOut);
}
}
}

public override void Disconnected(BoltConnection connection)
{
if (remoteFrameStateMap.TryGetValue(connection, out var frameController))
{
Destroy(frameController.gameObject);
}
}
}
11 changes: 11 additions & 0 deletions BoltRealtimeStats/Scripts/BoltStatsController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff3343c

Please sign in to comment.