42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using System;
|
||
using UnityEngine;
|
||
using XWorld.Framework;
|
||
// Alias to resolve ambiguity between XWorld.Framework.ILogger and UnityEngine.ILogger
|
||
using IFwkLogger = XWorld.Framework.ILogger;
|
||
|
||
namespace XGame.MiniGame
|
||
{
|
||
// 注入给 IGameClient 的上下文:资源/日志/发送/退出
|
||
public sealed class GameClientCtx : IGameClientCtx
|
||
{
|
||
public IAssetLoader Assets { get; }
|
||
public IFwkLogger Logger { get; }
|
||
public IRoomPlayerService Players { get; }
|
||
|
||
private readonly Action<NetMessage> _send;
|
||
private readonly Action _exit;
|
||
|
||
public GameClientCtx(IAssetLoader assets, IFwkLogger logger, IRoomPlayerService players, Action<NetMessage> send, Action exit)
|
||
{
|
||
Assets = assets;
|
||
Logger = logger;
|
||
Players = players;
|
||
_send = send;
|
||
_exit = exit;
|
||
}
|
||
|
||
public void Send(NetMessage message) => _send(message);
|
||
public void Exit() => _exit();
|
||
}
|
||
|
||
// 简单 Unity 日志器(实现框架 ILogger)
|
||
public sealed class UnityLogger : IFwkLogger
|
||
{
|
||
private readonly string _prefix;
|
||
public UnityLogger(string prefix = "[minigame]") { _prefix = prefix; }
|
||
public void Info(string m) => Debug.Log($"{_prefix} {m}");
|
||
public void Warn(string m) => Debug.LogWarning($"{_prefix} {m}");
|
||
public void Error(string m) => Debug.LogError($"{_prefix} {m}");
|
||
}
|
||
}
|