Updated PlayerTest

- Added Henchman
- Fixed PlayerReliable Label
- Fixed PlayerCamera Z offlset
- Enabled Debug UI
- Mirror Icon
This commit is contained in:
MrGadget 2024-11-03 15:01:14 -05:00
parent 303a698213
commit b32c6677c9
6 changed files with 37 additions and 242 deletions

View File

@ -450,7 +450,7 @@ MonoBehaviour:
syncDirection: 0
syncMode: 0
syncInterval: 0
offset: {x: 0, y: 3, z: -8}
offset: {x: 0, y: 3, z: -12}
rotation: {x: 10, y: 0, z: 0}
--- !u!114 &5277671853267693090
MonoBehaviour:
@ -479,8 +479,8 @@ MonoBehaviour:
syncPosition: 1
syncRotation: 1
disableSendingThisToClients: 0
showGizmos: 0
showOverlay: 0
showGizmos: 1
showOverlay: 1
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
--- !u!114 &-218831818502395344
MonoBehaviour:

View File

@ -338,7 +338,7 @@ MonoBehaviour:
syncDirection: 0
syncMode: 0
syncInterval: 0
offset: {x: 0, y: 3, z: -8}
offset: {x: 0, y: 3, z: -12}
rotation: {x: 10, y: 0, z: 0}
--- !u!114 &5382001159774817068
MonoBehaviour:
@ -510,7 +510,7 @@ TextMesh:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8833598509264872235}
m_Text: RB Reliable
m_Text: Reliable
m_OffsetZ: 0
m_CharacterSize: 0.5
m_LineSpacing: 1

View File

@ -1,257 +1,41 @@
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using Mirror;
using System.Collections;
/*
Documentation: https://mirror-networking.gitbook.io/docs/components/network-manager
API Reference: https://mirror-networking.com/docs/api/Mirror.NetworkManager.html
*/
namespace Mirror.Examples.PlayerTest
{
public class PlayerTestNetMan : NetworkManager
{
// Overrides the base singleton so we don't
// have to cast to this type everywhere.
public static new PlayerTestNetMan singleton => (PlayerTestNetMan)NetworkManager.singleton;
/// <summary>
/// Runs on both Server and Client
/// Networking is NOT initialized when this fires
/// </summary>
public override void Awake()
{
base.Awake();
}
#region Unity Callbacks
[Header("Henchman")]
public bool spawnHenchman;
public GameObject henchmanPrefab;
public override void OnValidate()
{
base.OnValidate();
// don't use same prefab for player and henchman
if (henchmanPrefab != null && playerPrefab == henchmanPrefab)
henchmanPrefab = null;
}
/// <summary>
/// Runs on both Server and Client
/// Networking is NOT initialized when this fires
/// </summary>
public override void Start()
public override void OnStartClient()
{
base.Start();
if (spawnHenchman && henchmanPrefab != null)
NetworkClient.RegisterPrefab(henchmanPrefab);
}
/// <summary>
/// Runs on both Server and Client
/// </summary>
public override void LateUpdate()
{
base.LateUpdate();
}
/// <summary>
/// Runs on both Server and Client
/// </summary>
public override void OnDestroy()
{
base.OnDestroy();
}
#endregion
#region Start & Stop
/// <summary>
/// Set the frame rate for a headless server.
/// <para>Override if you wish to disable the behavior or set your own tick rate.</para>
/// </summary>
public override void ConfigureHeadlessFrameRate()
{
base.ConfigureHeadlessFrameRate();
}
#endregion
#region Scene Management
/// <summary>
/// This causes the server to switch scenes and sets the networkSceneName.
/// <para>Clients that connect to this server will automatically switch to this scene. This is called automatically if onlineScene or offlineScene are set, but it can be called from user code to switch scenes again while the game is in progress. This automatically sets clients to be not-ready. The clients must call NetworkClient.Ready() again to participate in the new scene.</para>
/// </summary>
/// <param name="newSceneName"></param>
public override void ServerChangeScene(string newSceneName)
{
base.ServerChangeScene(newSceneName);
}
/// <summary>
/// Called from ServerChangeScene immediately before SceneManager.LoadSceneAsync is executed
/// <para>This allows server to do work / cleanup / prep before the scene changes.</para>
/// </summary>
/// <param name="newSceneName">Name of the scene that's about to be loaded</param>
public override void OnServerChangeScene(string newSceneName) { }
/// <summary>
/// Called on the server when a scene is completed loaded, when the scene load was initiated by the server with ServerChangeScene().
/// </summary>
/// <param name="sceneName">The name of the new scene.</param>
public override void OnServerSceneChanged(string sceneName) { }
/// <summary>
/// Called from ClientChangeScene immediately before SceneManager.LoadSceneAsync is executed
/// <para>This allows client to do work / cleanup / prep before the scene changes.</para>
/// </summary>
/// <param name="newSceneName">Name of the scene that's about to be loaded</param>
/// <param name="sceneOperation">Scene operation that's about to happen</param>
/// <param name="customHandling">true to indicate that scene loading will be handled through overrides</param>
public override void OnClientChangeScene(string newSceneName, SceneOperation sceneOperation, bool customHandling) { }
/// <summary>
/// Called on clients when a scene has completed loaded, when the scene load was initiated by the server.
/// <para>Scene changes can cause player objects to be destroyed. The default implementation of OnClientSceneChanged in the NetworkManager is to add a player object for the connection if no player object exists.</para>
/// </summary>
public override void OnClientSceneChanged()
{
base.OnClientSceneChanged();
}
#endregion
#region Server System Callbacks
/// <summary>
/// Called on the server when a new client connects.
/// <para>Unity calls this on the Server when a Client connects to the Server. Use an override to tell the NetworkManager what to do when a client connects to the server.</para>
/// </summary>
/// <param name="conn">Connection from client.</param>
public override void OnServerConnect(NetworkConnectionToClient conn) { }
/// <summary>
/// Called on the server when a client is ready.
/// <para>The default implementation of this function calls NetworkServer.SetClientReady() to continue the network setup process.</para>
/// </summary>
/// <param name="conn">Connection from client.</param>
public override void OnServerReady(NetworkConnectionToClient conn)
{
base.OnServerReady(conn);
}
/// <summary>
/// Called on the server when a client adds a new player with ClientScene.AddPlayer.
/// <para>The default implementation for this function creates a new player object from the playerPrefab.</para>
/// </summary>
/// <param name="conn">Connection from client.</param>
public override void OnServerAddPlayer(NetworkConnectionToClient conn)
{
base.OnServerAddPlayer(conn);
}
/// <summary>
/// Called on the server when a client disconnects.
/// <para>This is called on the Server when a Client disconnects from the Server. Use an override to decide what should happen when a disconnection is detected.</para>
/// </summary>
/// <param name="conn">Connection from client.</param>
public override void OnServerDisconnect(NetworkConnectionToClient conn)
if (spawnHenchman && henchmanPrefab != null)
{
base.OnServerDisconnect(conn);
}
/// <summary>
/// Called on server when transport raises an error.
/// <para>NetworkConnection may be null.</para>
/// </summary>
/// <param name="conn">Connection of the client...may be null</param>
/// <param name="transportError">TransportError enum</param>
/// <param name="message">String message of the error.</param>
public override void OnServerError(NetworkConnectionToClient conn, TransportError transportError, string message) { }
/// <summary>
/// Called on server when transport raises an exception.
/// <para>NetworkConnection may be null.</para>
/// </summary>
/// <param name="conn">Connection of the client...may be null</param>
/// <param name="exception">Exception thrown from the Transport.</param>
public override void OnServerTransportException(NetworkConnectionToClient conn, Exception exception) { }
#endregion
#region Client System Callbacks
/// <summary>
/// Called on the client when connected to a server.
/// <para>The default implementation of this function sets the client as ready and adds a player. Override the function to dictate what happens when the client connects.</para>
/// </summary>
public override void OnClientConnect()
{
base.OnClientConnect();
}
/// <summary>
/// Called on clients when disconnected from a server.
/// <para>This is called on the client when it disconnects from the server. Override this function to decide what happens when the client disconnects.</para>
/// </summary>
public override void OnClientDisconnect() { }
/// <summary>
/// Called on clients when a servers tells the client it is no longer ready.
/// <para>This is commonly used when switching scenes.</para>
/// </summary>
public override void OnClientNotReady() { }
/// <summary>
/// Called on client when transport raises an error.</summary>
/// </summary>
/// <param name="transportError">TransportError enum.</param>
/// <param name="message">String message of the error.</param>
public override void OnClientError(TransportError transportError, string message) { }
/// <summary>
/// Called on client when transport raises an exception.</summary>
/// </summary>
/// <param name="exception">Exception thrown from the Transport.</param>
public override void OnClientTransportException(Exception exception) { }
#endregion
#region Start & Stop Callbacks
// Since there are multiple versions of StartServer, StartClient and StartHost, to reliably customize
// their functionality, users would need override all the versions. Instead these callbacks are invoked
// from all versions, so users only need to implement this one case.
/// <summary>
/// This is invoked when a host is started.
/// <para>StartHost has multiple signatures, but they all cause this hook to be called.</para>
/// </summary>
public override void OnStartHost() { }
/// <summary>
/// This is invoked when a server is started - including when a host is started.
/// <para>StartServer has multiple signatures, but they all cause this hook to be called.</para>
/// </summary>
public override void OnStartServer() { }
/// <summary>
/// This is invoked when the client is started.
/// </summary>
public override void OnStartClient() { }
/// <summary>
/// This is called when a host is stopped.
/// </summary>
public override void OnStopHost() { }
/// <summary>
/// This is called when a server is stopped - including when a host is stopped.
/// </summary>
public override void OnStopServer() { }
/// <summary>
/// This is called when a client is stopped.
/// </summary>
public override void OnStopClient() { }
#endregion
Transform t = conn.identity.transform;
Vector3 startPos = t.position + t.forward * 2;
GameObject henchaman = Instantiate(henchmanPrefab, startPos, Quaternion.identity);
NetworkServer.Spawn(henchaman, conn);
}
}
}
}

View File

@ -902,7 +902,9 @@ MonoBehaviour:
deliveryTimeEmaDuration: 2
evaluationMethod: 0
evaluationInterval: 3
timeInterpolationGui: 0
timeInterpolationGui: 1
spawnHenchman: 1
henchmanPrefab: {fileID: 7863680369626900553, guid: 400bac1c9e1e96648a83f333d4837484, type: 3}
--- !u!114 &2126814507
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -450,7 +450,7 @@ MonoBehaviour:
syncDirection: 0
syncMode: 0
syncInterval: 0
offset: {x: 0, y: 3, z: -8}
offset: {x: 0, y: 3, z: -12}
rotation: {x: 10, y: 0, z: 0}
--- !u!114 &1260535960049292642
MonoBehaviour:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: cf4bdd41c196e4c42b272b25c3755b98
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 7453abfe9e8b2c04a8a47eb536fe21eb, type: 3}
userData:
assetBundleName:
assetBundleVariant: