first commit

This commit is contained in:
2022-07-08 09:14:55 +08:00
commit 4d6bd72555
1123 changed files with 456307 additions and 0 deletions

View File

@ -0,0 +1,109 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PhotonLagSimulationGui.cs" company="Exit Games GmbH">
// Part of: Photon Unity Utilities,
// </copyright>
// <summary>
// This MonoBehaviour is a basic GUI for the Photon client's network-simulation feature.
// It can modify lag (fixed delay), jitter (random lag) and packet loss.
// Part of the [Optional GUI](@ref optionalGui).
// </summary>
// <author>developer@exitgames.com</author>
// --------------------------------------------------------------------------------------------------------------------
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using ExitGames.Client.Photon;
namespace Photon.Pun.UtilityScripts
{
/// <summary>
/// This MonoBehaviour is a basic GUI for the Photon client's network-simulation feature.
/// It can modify lag (fixed delay), jitter (random lag) and packet loss.
/// </summary>
/// \ingroup optionalGui
public class PhotonLagSimulationGui : MonoBehaviour
{
/// <summary>Positioning rect for window.</summary>
public Rect WindowRect = new Rect(0, 100, 120, 100);
/// <summary>Unity GUI Window ID (must be unique or will cause issues).</summary>
public int WindowId = 101;
/// <summary>Shows or hides GUI (does not affect settings).</summary>
public bool Visible = true;
/// <summary>The peer currently in use (to set the network simulation).</summary>
public PhotonPeer Peer { get; set; }
public void Start()
{
this.Peer = PhotonNetwork.NetworkingClient.LoadBalancingPeer;
}
public void OnGUI()
{
if (!this.Visible)
{
return;
}
if (this.Peer == null)
{
this.WindowRect = GUILayout.Window(this.WindowId, this.WindowRect, this.NetSimHasNoPeerWindow, "Netw. Sim.");
}
else
{
this.WindowRect = GUILayout.Window(this.WindowId, this.WindowRect, this.NetSimWindow, "Netw. Sim.");
}
}
private void NetSimHasNoPeerWindow(int windowId)
{
GUILayout.Label("No peer to communicate with. ");
}
private void NetSimWindow(int windowId)
{
GUILayout.Label(string.Format("Rtt:{0,4} +/-{1,3}", this.Peer.RoundTripTime, this.Peer.RoundTripTimeVariance));
bool simEnabled = this.Peer.IsSimulationEnabled;
bool newSimEnabled = GUILayout.Toggle(simEnabled, "Simulate");
if (newSimEnabled != simEnabled)
{
this.Peer.IsSimulationEnabled = newSimEnabled;
}
float inOutLag = this.Peer.NetworkSimulationSettings.IncomingLag;
GUILayout.Label("Lag " + inOutLag);
inOutLag = GUILayout.HorizontalSlider(inOutLag, 0, 500);
this.Peer.NetworkSimulationSettings.IncomingLag = (int)inOutLag;
this.Peer.NetworkSimulationSettings.OutgoingLag = (int)inOutLag;
float inOutJitter = this.Peer.NetworkSimulationSettings.IncomingJitter;
GUILayout.Label("Jit " + inOutJitter);
inOutJitter = GUILayout.HorizontalSlider(inOutJitter, 0, 100);
this.Peer.NetworkSimulationSettings.IncomingJitter = (int)inOutJitter;
this.Peer.NetworkSimulationSettings.OutgoingJitter = (int)inOutJitter;
float loss = this.Peer.NetworkSimulationSettings.IncomingLossPercentage;
GUILayout.Label("Loss " + loss);
loss = GUILayout.HorizontalSlider(loss, 0, 10);
this.Peer.NetworkSimulationSettings.IncomingLossPercentage = (int)loss;
this.Peer.NetworkSimulationSettings.OutgoingLossPercentage = (int)loss;
// if anything was clicked, the height of this window is likely changed. reduce it to be layouted again next frame
if (GUI.changed)
{
this.WindowRect.height = 100;
}
GUI.DragWindow();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5867a53c8db0e6745818285bb6b6e1b9
labels:
- ExitGames
- PUN
- Photon
- Networking
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@ -0,0 +1,170 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PhotonStatsGui.cs" company="Exit Games GmbH">
// Part of: Photon Unity Utilities,
// </copyright>
// <summary>
// Basic GUI to show traffic and health statistics of the connection to Photon,
// toggled by shift+tab.
// Part of the [Optional GUI](@ref optionalGui).
// </summary>
// <author>developer@exitgames.com</author>
// --------------------------------------------------------------------------------------------------------------------
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using ExitGames.Client.Photon;
namespace Photon.Pun.UtilityScripts
{
/// <summary>
/// Basic GUI to show traffic and health statistics of the connection to Photon,
/// toggled by shift+tab.
/// </summary>
/// <remarks>
/// The shown health values can help identify problems with connection losses or performance.
/// Example:
/// If the time delta between two consecutive SendOutgoingCommands calls is a second or more,
/// chances rise for a disconnect being caused by this (because acknowledgements to the server
/// need to be sent in due time).
/// </remarks>
/// \ingroup optionalGui
public class PhotonStatsGui : MonoBehaviour
{
/// <summary>Shows or hides GUI (does not affect if stats are collected).</summary>
public bool statsWindowOn = true;
/// <summary>Option to turn collecting stats on or off (used in Update()).</summary>
public bool statsOn = true;
/// <summary>Shows additional "health" values of connection.</summary>
public bool healthStatsVisible;
/// <summary>Shows additional "lower level" traffic stats.</summary>
public bool trafficStatsOn;
/// <summary>Show buttons to control stats and reset them.</summary>
public bool buttonsOn;
/// <summary>Positioning rect for window.</summary>
public Rect statsRect = new Rect(0, 100, 200, 50);
/// <summary>Unity GUI Window ID (must be unique or will cause issues).</summary>
public int WindowId = 100;
public void Start()
{
if (this.statsRect.x <= 0)
{
this.statsRect.x = Screen.width - this.statsRect.width;
}
}
/// <summary>Checks for shift+tab input combination (to toggle statsOn).</summary>
public void Update()
{
if (Input.GetKeyDown(KeyCode.Tab) && Input.GetKey(KeyCode.LeftShift))
{
this.statsWindowOn = !this.statsWindowOn;
this.statsOn = true; // enable stats when showing the window
}
}
public void OnGUI()
{
if (PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsEnabled != statsOn)
{
PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsEnabled = this.statsOn;
}
if (!this.statsWindowOn)
{
return;
}
this.statsRect = GUILayout.Window(this.WindowId, this.statsRect, this.TrafficStatsWindow, "Messages (shift+tab)");
}
public void TrafficStatsWindow(int windowID)
{
bool statsToLog = false;
TrafficStatsGameLevel gls = PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsGameLevel;
long elapsedMs = PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsElapsedMs / 1000;
if (elapsedMs == 0)
{
elapsedMs = 1;
}
GUILayout.BeginHorizontal();
this.buttonsOn = GUILayout.Toggle(this.buttonsOn, "buttons");
this.healthStatsVisible = GUILayout.Toggle(this.healthStatsVisible, "health");
this.trafficStatsOn = GUILayout.Toggle(this.trafficStatsOn, "traffic");
GUILayout.EndHorizontal();
string total = string.Format("Out {0,4} | In {1,4} | Sum {2,4}", gls.TotalOutgoingMessageCount, gls.TotalIncomingMessageCount, gls.TotalMessageCount);
string elapsedTime = string.Format("{0}sec average:", elapsedMs);
string average = string.Format("Out {0,4} | In {1,4} | Sum {2,4}", gls.TotalOutgoingMessageCount / elapsedMs, gls.TotalIncomingMessageCount / elapsedMs, gls.TotalMessageCount / elapsedMs);
GUILayout.Label(total);
GUILayout.Label(elapsedTime);
GUILayout.Label(average);
if (this.buttonsOn)
{
GUILayout.BeginHorizontal();
this.statsOn = GUILayout.Toggle(this.statsOn, "stats on");
if (GUILayout.Button("Reset"))
{
PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsReset();
PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsEnabled = true;
}
statsToLog = GUILayout.Button("To Log");
GUILayout.EndHorizontal();
}
string trafficStatsIn = string.Empty;
string trafficStatsOut = string.Empty;
if (this.trafficStatsOn)
{
GUILayout.Box("Traffic Stats");
trafficStatsIn = "Incoming: \n" + PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsIncoming.ToString();
trafficStatsOut = "Outgoing: \n" + PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsOutgoing.ToString();
GUILayout.Label(trafficStatsIn);
GUILayout.Label(trafficStatsOut);
}
string healthStats = string.Empty;
if (this.healthStatsVisible)
{
GUILayout.Box("Health Stats");
healthStats = string.Format(
"ping: {6}[+/-{7}]ms resent:{8} \n\nmax ms between\nsend: {0,4} \ndispatch: {1,4} \n\nlongest dispatch for: \nev({3}):{2,3}ms \nop({5}):{4,3}ms",
gls.LongestDeltaBetweenSending,
gls.LongestDeltaBetweenDispatching,
gls.LongestEventCallback,
gls.LongestEventCallbackCode,
gls.LongestOpResponseCallback,
gls.LongestOpResponseCallbackOpCode,
PhotonNetwork.NetworkingClient.LoadBalancingPeer.RoundTripTime,
PhotonNetwork.NetworkingClient.LoadBalancingPeer.RoundTripTimeVariance,
PhotonNetwork.NetworkingClient.LoadBalancingPeer.ResentReliableCommands);
GUILayout.Label(healthStats);
}
if (statsToLog)
{
string complete = string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}", total, elapsedTime, average, trafficStatsIn, trafficStatsOut, healthStats);
Debug.Log(complete);
}
// if anything was clicked, the height of this window is likely changed. reduce it to be layouted again next frame
if (GUI.changed)
{
this.statsRect.height = 100;
}
GUI.DragWindow();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d06466c03d263624786afa88b52928b6
labels:
- ExitGames
- PUN
- Photon
- Networking
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@ -0,0 +1,84 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PointedAtGameObjectInfo.cs" company="Exit Games GmbH">
// </copyright>
// <summary>
// Display ViewId, OwnerActorNr, IsCeneView and IsMine when clicked using the old UI system
// </summary>
// <author>developer@exitgames.com</author>
// --------------------------------------------------------------------------------------------------------------------
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using Photon.Pun;
using Photon.Realtime;
namespace Photon.Pun.UtilityScripts
{
/// <summary>
/// Display ViewId, OwnerActorNr, IsCeneView and IsMine when clicked.
/// </summary>
public class PointedAtGameObjectInfo : MonoBehaviour
{
public static PointedAtGameObjectInfo Instance;
public Text text;
Transform focus;
void Start()
{
if (Instance != null)
{
Debug.LogWarning("PointedAtGameObjectInfo is already featured in the scene, gameobject is destroyed");
Destroy(this.gameObject);
}
Instance = this;
}
public void SetFocus(PhotonView pv)
{
focus = pv != null ? pv.transform : null;
if (pv != null)
{
text.text = string.Format("id {0} own: {1} {2}{3}", pv.ViewID, pv.OwnerActorNr, (pv.IsRoomView) ? "scn" : "", (pv.IsMine) ? " mine" : "");
//GUI.Label (new Rect (Input.mousePosition.x + 5, Screen.height - Input.mousePosition.y - 15, 300, 30), );
}
else
{
text.text = string.Empty;
}
}
public void RemoveFocus(PhotonView pv)
{
if (pv == null)
{
text.text = string.Empty;
return;
}
if (pv.transform == focus)
{
text.text = string.Empty;
return;
}
}
void LateUpdate()
{
if (focus != null)
{
this.transform.position = Camera.main.WorldToScreenPoint(focus.position);
}
}
}
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e6262dd9a9b078c4e8cbd47495aa6d23
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@ -0,0 +1,212 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TabViewManager.cs" company="Exit Games GmbH">
// </copyright>
// <summary>
// Output detailed information about Pun Current states, using the old Unity UI framework.
// </summary>
// <author>developer@exitgames.com</author>
// --------------------------------------------------------------------------------------------------------------------
using UnityEngine;
using Photon.Realtime;
namespace Photon.Pun.UtilityScripts
{
/// <summary>
/// Output detailed information about Pun Current states, using the old Unity UI framework.
/// </summary>
public class StatesGui : MonoBehaviour
{
public Rect GuiOffset = new Rect(250, 0, 300, 300);
public bool DontDestroy = true;
public bool ServerTimestamp;
public bool DetailedConnection;
public bool Server;
public bool AppVersion;
public bool UserId;
public bool Room;
public bool RoomProps;
public bool EventsIn;
public bool LocalPlayer;
public bool PlayerProps;
public bool Others;
public bool Buttons;
public bool ExpectedUsers;
private Rect GuiRect = new Rect();
private static StatesGui Instance;
void Awake()
{
if (Instance != null)
{
DestroyImmediate(this.gameObject);
return;
}
if (DontDestroy)
{
Instance = this;
DontDestroyOnLoad(this.gameObject);
}
if (EventsIn)
{
PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsEnabled = true;
}
}
void OnDisable()
{
if (DontDestroy && Instance == this)
{
Instance = null;
}
}
float native_width = 800;
float native_height = 480;
void OnGUI()
{
if (PhotonNetwork.NetworkingClient == null || PhotonNetwork.NetworkingClient.LoadBalancingPeer == null || PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsIncoming == null)
{
return;
}
//set up scaling
float rx = Screen.width / native_width;
float ry = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, new Vector3 (rx, ry, 1));
Rect GuiOffsetRuntime = new Rect(this.GuiOffset);
if (GuiOffsetRuntime.x < 0)
{
GuiOffsetRuntime.x = Screen.width - GuiOffsetRuntime.width;
}
GuiRect.xMin = GuiOffsetRuntime.x;
GuiRect.yMin = GuiOffsetRuntime.y;
GuiRect.xMax = GuiOffsetRuntime.x + GuiOffsetRuntime.width;
GuiRect.yMax = GuiOffsetRuntime.y + GuiOffsetRuntime.height;
GUILayout.BeginArea(GuiRect);
GUILayout.BeginHorizontal();
if (this.ServerTimestamp)
{
GUILayout.Label((((double)PhotonNetwork.ServerTimestamp) / 1000d).ToString("F3"));
}
if (Server)
{
GUILayout.Label(PhotonNetwork.ServerAddress + " " + PhotonNetwork.Server);
}
if (DetailedConnection)
{
GUILayout.Label(PhotonNetwork.NetworkClientState.ToString());
}
if (AppVersion)
{
GUILayout.Label(PhotonNetwork.NetworkingClient.AppVersion);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (UserId)
{
GUILayout.Label("UID: " + ((PhotonNetwork.AuthValues != null) ? PhotonNetwork.AuthValues.UserId : "no UserId"));
GUILayout.Label("UserId:" + PhotonNetwork.LocalPlayer.UserId);
}
GUILayout.EndHorizontal();
if (Room)
{
if (PhotonNetwork.InRoom)
{
GUILayout.Label(this.RoomProps ? PhotonNetwork.CurrentRoom.ToStringFull() : PhotonNetwork.CurrentRoom.ToString());
}
else
{
GUILayout.Label("not in room");
}
}
if (EventsIn)
{
int fragments = PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsIncoming.FragmentCommandCount;
GUILayout.Label("Events Received: "+PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsGameLevel.EventCount + " Fragments: "+fragments);
}
if (this.LocalPlayer)
{
GUILayout.Label(PlayerToString(PhotonNetwork.LocalPlayer));
}
if (Others)
{
foreach (Player player in PhotonNetwork.PlayerListOthers)
{
GUILayout.Label(PlayerToString(player));
}
}
if (ExpectedUsers)
{
if (PhotonNetwork.InRoom)
{
int countExpected = (PhotonNetwork.CurrentRoom.ExpectedUsers != null) ? PhotonNetwork.CurrentRoom.ExpectedUsers.Length : 0;
GUILayout.Label("Expected: " + countExpected + " " +
((PhotonNetwork.CurrentRoom.ExpectedUsers != null) ? string.Join(",", PhotonNetwork.CurrentRoom.ExpectedUsers) : "")
);
}
}
if (Buttons)
{
if (!PhotonNetwork.IsConnected && GUILayout.Button("Connect"))
{
PhotonNetwork.ConnectUsingSettings();
}
GUILayout.BeginHorizontal();
if (PhotonNetwork.IsConnected && GUILayout.Button("Disconnect"))
{
PhotonNetwork.Disconnect();
}
if (PhotonNetwork.IsConnected && GUILayout.Button("Close Socket"))
{
PhotonNetwork.NetworkingClient.LoadBalancingPeer.StopThread();
}
GUILayout.EndHorizontal();
if (PhotonNetwork.IsConnected && PhotonNetwork.InRoom && GUILayout.Button("Leave"))
{
PhotonNetwork.LeaveRoom();
}
if (PhotonNetwork.IsConnected && PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom.PlayerTtl>0 && GUILayout.Button("Leave(abandon)"))
{
PhotonNetwork.LeaveRoom(false);
}
if (PhotonNetwork.IsConnected && !PhotonNetwork.InRoom && GUILayout.Button("Join Random"))
{
PhotonNetwork.JoinRandomRoom();
}
if (PhotonNetwork.IsConnected && !PhotonNetwork.InRoom && GUILayout.Button("Create Room"))
{
PhotonNetwork.CreateRoom(null);
}
}
GUILayout.EndArea();
}
private string PlayerToString(Player player)
{
if (PhotonNetwork.NetworkingClient == null)
{
Debug.LogError("nwp is null");
return "";
}
return string.Format("#{0:00} '{1}'{5} {4}{2} {3} {6}", player.ActorNumber + "/userId:<" + player.UserId + ">", player.NickName, player.IsMasterClient ? "(master)" : "", this.PlayerProps ? player.CustomProperties.ToStringFull() : "", (PhotonNetwork.LocalPlayer.ActorNumber == player.ActorNumber) ? "(you)" : "", player.UserId, player.IsInactive ? " / Is Inactive" : "");
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 62880f27e95abf2418fd79e9d9d568b4
timeCreated: 1493998271
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: