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

65 lines
2.4 KiB
C#
Raw Normal View History

2024-09-18 15:53:58 +08:00
using AxibugEmuOnline.Client.ClientCore;
using AxibugProtobuf;
using System;
2024-08-16 14:45:44 +08:00
using System.Collections;
using System.Collections.Generic;
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);
}
2024-09-18 15:53:58 +08:00
public static string GetHostNickName(this Protobuf_Room_MiniInfo roomInfo)
{
var hostUID = roomInfo.HostPlayerUID;
if (hostUID == roomInfo.Player1UID) return roomInfo.Player1NickName;
else if (hostUID == roomInfo.Player2UID) return roomInfo.Player2NickName;
else if (hostUID == roomInfo.Player3UID) return roomInfo.Player3NickName;
else if (hostUID == roomInfo.Player4UID) return roomInfo.Player4NickName;
else return string.Empty;
}
public static void GetRoomPlayers(this Protobuf_Room_MiniInfo roomInfo, out int current, out int max)
{
current = 0; max = 4;
if (roomInfo.Player1UID > 0) current++;
if (roomInfo.Player2UID > 0) current++;
if (roomInfo.Player3UID > 0) current++;
if (roomInfo.Player4UID > 0) current++;
}
private static Dictionary<int, RomFile> s_RomFileCahcesInRoomInfo = new Dictionary<int, RomFile>();
public static void FetchRomFileInRoomInfo(this Protobuf_Room_MiniInfo roomInfo, EnumPlatform platform, Action<RomFile> callback)
{
if (s_RomFileCahcesInRoomInfo.TryGetValue(roomInfo.GameRomID, out RomFile romFile))
{
callback.Invoke(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);
callback.Invoke(romFile);
s_RomFileCahcesInRoomInfo[roomInfo.GameRomID] = romFile;
}));
break;
}
}
2024-08-16 14:45:44 +08:00
}
}