Files
Test-Multiplayer/Assets/Scripts/Chat/ChatNetworkManager.cs
T
pelpanagiotisandClaude Opus 5.5 5fc9ebf1e6 Add practice range: shooting, AK47, intro cinematic, dressed warehouse scene
- PortalTestDestination practice range: Valorant-style hitscan rifle (recoil,
  spray/bloom, reload, controller support), debug HUD, practice-dummy targets
  with head/body hitboxes, hit/death/respawn animations, procedural SFX/FX
- AK47 model (Quaternius, CC0) held via Animator IK, with fire/reload/equip anims
- Intro cinematic (camera shots, title card, target beam-in, GO hand-off)
- Scene dressing editor pass: CC0 textures, props, warehouse roof, lighting and
  post-processing; custom stylized skybox shader
- CharacterMovement: camera recoil, shoulder offset, cinematic control lock
- Unity CLI pipeline package; plus in-progress chat/Rive/player changes

Asset credits: Assets/Models/Props/PROPS_CREDITS.txt (3 CC-BY 3.0 props),
Assets/Textures/Range/TEXTURES_LICENSE.txt, Assets/Resources/*/..._LICENSE.txt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 08:56:35 +03:00

113 lines
3.5 KiB
C#

using UnityEngine;
using Mirror;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
[AddComponentMenu("")]
public class ChatNetworkManager : NetworkManager
{
[SerializeField] private GameObject chatUIPrefab;
[SerializeField] private GameObject riveLoginCanvas;
// Server-side authoritative store of chat messages
private readonly List<string> chatMessages = new();
// Server-side map of connections to player names (moved from the old ChatUI)
internal static readonly Dictionary<NetworkConnectionToClient, string> connNames = new();
public void SetHostname(string hostname)
{
networkAddress = hostname;
}
public override void OnServerDisconnect(NetworkConnectionToClient conn)
{
Debug.Log($"[ChatNetworkManager] Server disconnecting connection {conn.connectionId}. Active scene: '{SceneManager.GetActiveScene().name}'");
if (conn.authenticationData != null)
ChatAuthenticator.playerNames.Remove((string)conn.authenticationData);
connNames.Remove(conn);
base.OnServerDisconnect(conn);
}
public override void OnClientDisconnect()
{
Debug.Log($"[ChatNetworkManager] Client disconnected. Active scene: '{SceneManager.GetActiveScene().name}'");
base.OnClientDisconnect();
// Destroy ChatUI instance when disconnecting
ChatUI existingChatUI = FindFirstObjectByType<ChatUI>();
if (existingChatUI != null)
{
Destroy(existingChatUI.gameObject);
}
// Show LoginUI again
if (LoginUI.instance != null)
{
LoginUI.instance.gameObject.SetActive(true);
LoginUI.instance.usernameInput.text = "";
LoginUI.instance.usernameInput.ActivateInputField();
}
}
public override void OnClientConnect()
{
base.OnClientConnect();
Debug.Log($"[ChatNetworkManager] OnClientConnect called. Active scene: '{SceneManager.GetActiveScene().name}'");
// Spawn ChatUI prefab locally when client successfully connects
if (chatUIPrefab == null)
{
Debug.LogError("ChatNetworkManager: ChatUI prefab is not assigned in the inspector!");
return;
}
if (riveLoginCanvas == null)
{
Debug.LogError("ChatNetworkManager: Rive Login Canvas is not assigned in the inspector!");
}
// Check if ChatUI already exists to avoid duplicates
ChatUI existingChatUI = FindFirstObjectByType<ChatUI>();
if (existingChatUI == null)
{
GameObject chatUIInstance = Instantiate(chatUIPrefab);
if (chatUIInstance == null)
{
Debug.LogError("ChatNetworkManager: Failed to instantiate ChatUI prefab!");
return;
}
chatUIInstance.SetActive(true);
}
// Hide LoginUI when successfully connected
if (LoginUI.instance != null)
{
LoginUI.instance.gameObject.SetActive(false);
}
if (riveLoginCanvas != null)
riveLoginCanvas.SetActive(false);
Debug.Log($"[ChatNetworkManager] Client connection setup completed. Active scene: '{SceneManager.GetActiveScene().name}'");
}
[Server]
public void AddServerMessage(string message)
{
if (string.IsNullOrWhiteSpace(message)) return;
chatMessages.Add(message);
}
[Server]
public string[] GetHistory()
{
return chatMessages.ToArray();
}
}