Player.cs 780 B

123456789101112131415161718192021222324252627282930
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace Mirror.Examples.Chat
  4. {
  5. public class Player : NetworkBehaviour
  6. {
  7. internal static readonly HashSet<string> playerNames = new HashSet<string>();
  8. [SerializeField, SyncVar]
  9. internal string playerName;
  10. // RuntimeInitializeOnLoadMethod -> fast playmode without domain reload
  11. [UnityEngine.RuntimeInitializeOnLoadMethod]
  12. static void ResetStatics()
  13. {
  14. playerNames.Clear();
  15. }
  16. public override void OnStartServer()
  17. {
  18. playerName = (string)connectionToClient.authenticationData;
  19. }
  20. public override void OnStartLocalPlayer()
  21. {
  22. ChatUI.localPlayerName = playerName;
  23. }
  24. }
  25. }