很多更新,服务端连接,新UI和系统
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GameServer.Client;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class roomPrefab : MonoBehaviour
|
||||
{
|
||||
public Image btmImg;
|
||||
public Text roommateID;
|
||||
public Image ownerImage;
|
||||
public Text roommateUsername;
|
||||
public Text playMode_inRoom;
|
||||
public Dropdown usercando;
|
||||
public Image roommate_readyStatus;
|
||||
|
||||
private Action<string> _onKick;
|
||||
private string _targetSteamId;
|
||||
private bool _dropdownBound;
|
||||
|
||||
public void Bind(ArenaRoomParticipant participant, int displayIndex, bool localIsHost,
|
||||
string localSteamId, Sprite backgroundSprite, Action<string> onKick)
|
||||
{
|
||||
_onKick = onKick;
|
||||
_targetSteamId = participant != null ? participant.steam_id : null;
|
||||
|
||||
if (btmImg != null)
|
||||
{
|
||||
btmImg.sprite = backgroundSprite;
|
||||
}
|
||||
|
||||
if (roommateID != null)
|
||||
{
|
||||
roommateID.text = displayIndex.ToString();
|
||||
}
|
||||
|
||||
if (ownerImage != null)
|
||||
{
|
||||
ownerImage.gameObject.SetActive(participant != null && participant.is_host);
|
||||
}
|
||||
|
||||
if (roommateUsername != null)
|
||||
{
|
||||
roommateUsername.text = participant != null
|
||||
? string.IsNullOrWhiteSpace(participant.display_name) ? participant.steam_id : participant.display_name
|
||||
: string.Empty;
|
||||
}
|
||||
|
||||
if (playMode_inRoom != null)
|
||||
{
|
||||
playMode_inRoom.text = "游玩";
|
||||
}
|
||||
|
||||
if (roommate_readyStatus != null)
|
||||
{
|
||||
bool isReady = participant != null && participant.is_ready;
|
||||
roommate_readyStatus.enabled = isReady;
|
||||
roommate_readyStatus.gameObject.SetActive(isReady);
|
||||
}
|
||||
|
||||
ConfigureDropdown(participant, localIsHost, localSteamId);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (usercando != null && _dropdownBound)
|
||||
{
|
||||
usercando.onValueChanged.RemoveListener(OnDropdownValueChanged);
|
||||
_dropdownBound = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigureDropdown(ArenaRoomParticipant participant, bool localIsHost, string localSteamId)
|
||||
{
|
||||
if (usercando == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_dropdownBound)
|
||||
{
|
||||
usercando.onValueChanged.RemoveListener(OnDropdownValueChanged);
|
||||
_dropdownBound = false;
|
||||
}
|
||||
|
||||
usercando.ClearOptions();
|
||||
|
||||
bool canKick = participant != null
|
||||
&& localIsHost
|
||||
&& !participant.is_host
|
||||
&& !string.Equals(participant.steam_id, localSteamId, StringComparison.Ordinal);
|
||||
if (canKick)
|
||||
{
|
||||
usercando.interactable = true;
|
||||
usercando.AddOptions(new List<string> { "操作", "Kick" });
|
||||
usercando.value = 0;
|
||||
usercando.RefreshShownValue();
|
||||
usercando.onValueChanged.AddListener(OnDropdownValueChanged);
|
||||
_dropdownBound = true;
|
||||
return;
|
||||
}
|
||||
|
||||
usercando.interactable = false;
|
||||
if (participant != null && participant.is_host)
|
||||
{
|
||||
usercando.AddOptions(new List<string> { "房主" });
|
||||
}
|
||||
else
|
||||
{
|
||||
usercando.AddOptions(new List<string> { "无权限" });
|
||||
}
|
||||
usercando.value = 0;
|
||||
usercando.RefreshShownValue();
|
||||
}
|
||||
|
||||
private void OnDropdownValueChanged(int index)
|
||||
{
|
||||
if (index != 1 || string.IsNullOrWhiteSpace(_targetSteamId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_onKick?.Invoke(_targetSteamId);
|
||||
|
||||
if (usercando != null)
|
||||
{
|
||||
usercando.value = 0;
|
||||
usercando.RefreshShownValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user