Files
Test-Multiplayer/Assets/Scripts/Chat/ChatNetworkManager.cs
T
pelpanagiotis d04ff998cb Add main menu scene with Rive UI, procedural background, and scene transitions
- Add Menu scene with Rive-driven login and navigation UI
  (RiveLoginController, RiveNavigationController) for entering a
  username and starting/navigating the client via Rive triggers
- Add SceneTransitionController to fade out and load the Landscape
  gameplay scene when Play is selected
- Add procedural low-poly triangle field background and animated wave
  panel (LowPolyTriangleField, TriangleWavePanel) with matching
  editor menus and materials
- Add MenuLightAnimator for animated menu lighting and UI fade helpers
  (MenuFadeIn, DebugFadeToggle/Bridge)
- Rename SampleScene to Landscape and wire ChatNetworkManager to hide
  the new Rive login canvas once gameplay starts
- Bump Input System action codegen version and add Rive package
  references/project settings updates to support the new UI
2026-09-17 17:18:45 +03:00

107 lines
3.0 KiB
C#

using UnityEngine;
using Mirror;
using System.Collections.Generic;
[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)
{
if (conn.authenticationData != null)
ChatAuthenticator.playerNames.Remove((string)conn.authenticationData);
connNames.Remove(conn);
base.OnServerDisconnect(conn);
}
public override void OnClientDisconnect()
{
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");
// 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);
}
[Server]
public void AddServerMessage(string message)
{
if (string.IsNullOrWhiteSpace(message)) return;
chatMessages.Add(message);
}
[Server]
public string[] GetHistory()
{
return chatMessages.ToArray();
}
}