AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/AppMain/Utility.cs

63 lines
2.1 KiB
C#
Raw Normal View History

2024-12-11 21:21:27 +08:00
using AxibugEmuOnline.Client.ClientCore;
using AxibugProtobuf;
using System;
using System.Collections.Generic;
2024-12-20 12:11:02 +08:00
using System.Linq;
2024-12-11 21:21:27 +08:00
using UnityEngine;
namespace AxibugEmuOnline.Client
{
public static class Utility
{
public static void SetActiveEx(this GameObject go, bool active)
{
if (active && go.activeSelf) return;
if (!active && !go.activeSelf) return;
go.SetActive(active);
}
public static string GetHostNickName(this Protobuf_Room_MiniInfo roomInfo)
{
var hostUID = roomInfo.HostPlayerUID;
2024-12-20 12:11:02 +08:00
Protobuf_Room_GamePlaySlot slotdata = roomInfo.GamePlaySlotList.FirstOrDefault(w => w.PlayerUID == hostUID);
if (slotdata != null)
return slotdata.PlayerNickName;
else
return string.Empty;
2024-12-11 21:21:27 +08:00
}
public static void GetRoomPlayers(this Protobuf_Room_MiniInfo roomInfo, out int current, out int max)
{
current = 0; max = 4;
2024-12-20 12:11:02 +08:00
current = roomInfo.GamePlaySlotList.Count(w => w.PlayerUID > 0);
2024-12-11 21:21:27 +08:00
}
private static Dictionary<int, RomFile> s_RomFileCahcesInRoomInfo = new Dictionary<int, RomFile>();
public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action<Protobuf_Room_MiniInfo, RomFile> callback)
{
RomFile romFile;
if (s_RomFileCahcesInRoomInfo.TryGetValue(roomInfo.GameRomID, out romFile))
2024-12-11 21:21:27 +08:00
{
callback.Invoke(roomInfo, romFile);
return;
}
switch (platform)
{
case EnumPlatform.NES:
App.StartCoroutine(App.httpAPI.GetNesRomInfo(roomInfo.GameRomID, (romWebData) =>
{
RomFile _romFile = new RomFile(EnumPlatform.NES, 0, 0);
_romFile.SetWebData(romWebData);
s_RomFileCahcesInRoomInfo[roomInfo.GameRomID] = _romFile;
2024-12-11 21:21:27 +08:00
callback.Invoke(roomInfo, _romFile);
2024-12-11 21:21:27 +08:00
}));
break;
}
}
}
}