Changed NetworkRoomPlayer to use virtual SyncVar hook

This commit is contained in:
Chris Langsenkamp 2020-05-19 10:31:14 -04:00
parent 94795c50fb
commit 0cf5f27421
3 changed files with 23 additions and 5 deletions

View File

@ -1,3 +1,5 @@
using System;
using System.ComponentModel;
using UnityEngine;
namespace Mirror
@ -81,9 +83,16 @@ public void CmdChangeReadyState(bool readyState)
#region SyncVar Hooks
void ReadyStateChanged(bool _, bool newReadyState)
/// <summary>
/// This is a hook that is invoked on clients when a RoomPlayer switches between ready or not ready.
/// <para>This function is called when the a client player calls CmdChangeReadyState.</para>
/// </summary>
/// <param name="newReadyState">New Ready State</param>
public virtual void ReadyStateChanged(bool _, bool newReadyState)
{
#pragma warning disable CS0618 // Type or member is obsolete
OnClientReady(newReadyState);
#pragma warning restore CS0618 // Type or member is obsolete
}
#endregion
@ -101,11 +110,11 @@ public virtual void OnClientEnterRoom() { }
/// </summary>
public virtual void OnClientExitRoom() { }
// Deprecated 05/18/2020
/// <summary>
/// This is a hook that is invoked on clients when a RoomPlayer switches between ready or not ready.
/// <para>This function is called when the a client player calls CmdChangeReadyState.</para>
/// Obsolete: Override <see cref="ReadyStateChanged(bool, bool)">ReadyStateChanged(bool, bool)</see> instead.
/// </summary>
/// <param name="readyState">Whether the player is ready or not.</param>
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Override ReadyStateChanged(bool, bool) instead")]
public virtual void OnClientReady(bool readyState) { }
#endregion

View File

@ -24,5 +24,10 @@ public override void OnClientExitRoom()
{
if (logger.LogEnabled()) logger.LogFormat(LogType.Log, "OnClientExitRoom {0}", SceneManager.GetActiveScene().path);
}
public override void ReadyStateChanged(bool _, bool newReadyState)
{
if (logger.LogEnabled()) logger.LogFormat(LogType.Log, "ReadyStateChanged {0}", newReadyState);
}
}
}

View File

@ -75,12 +75,16 @@ public class #SCRIPTNAME# : NetworkRoomPlayer
/// </summary>
public override void OnClientExitRoom() { }
#endregion
#region SyncVar Hooks
/// <summary>
/// This is a hook that is invoked on clients when a RoomPlayer switches between ready or not ready.
/// <para>This function is called when the a client player calls SendReadyToBeginMessage() or SendNotReadyToBeginMessage().</para>
/// </summary>
/// <param name="readyState">Whether the player is ready or not.</param>
public override void OnClientReady(bool readyState) { }
public override void ReadyStateChanged(bool _, bool readyState) { }
#endregion