63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using NaughtyAttributes;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class IPBtn : MonoBehaviour
|
||
{
|
||
public Text IPText;
|
||
public Image BgImage;
|
||
public Sprite[] BgSprites; // 背景图片数组:RoomBg1, RoomBg2, RoomBg3
|
||
private ServerResponse _Info;
|
||
private bool _isSelected = false;
|
||
private int _roomId = 0;
|
||
private Vector3 _normalScale = Vector3.one;
|
||
private Vector3 _selectedScale = new Vector3(1.15f, 1.15f, 1.15f);
|
||
|
||
public void Init(int RoomId, ServerResponse info)
|
||
{
|
||
_Info = info;
|
||
_roomId = RoomId;
|
||
IPText.text = "房间" + RoomId + " " + GameLocal.Ins.ConvertTimestampToDateTime(info.createTime);
|
||
|
||
// 设置背景图片:根据房间号使用对应的图片,超过3个循环
|
||
if (BgImage != null && BgSprites != null && BgSprites.Length > 0)
|
||
{
|
||
int bgIndex = (RoomId - 1) % BgSprites.Length;
|
||
BgImage.sprite = BgSprites[bgIndex];
|
||
}
|
||
}
|
||
|
||
// 选中房间(点击房间按钮时调用)
|
||
public void OnTouchBtn()
|
||
{
|
||
if (ConPanel.Instance != null)
|
||
{
|
||
ConPanel.Instance.OnSelectRoom(this);
|
||
}
|
||
}
|
||
|
||
// 设置选中状态
|
||
public void SetSelected(bool isSelected)
|
||
{
|
||
_isSelected = isSelected;
|
||
// 选中时放大,取消选中时恢复
|
||
transform.localScale = isSelected ? _selectedScale : _normalScale;
|
||
}
|
||
|
||
// 获取房间信息
|
||
public ServerResponse GetRoomInfo()
|
||
{
|
||
return _Info;
|
||
}
|
||
|
||
// 加入房间(由ConPanel的OnClickJoin调用)
|
||
public void JoinRoom()
|
||
{
|
||
WorldUIManager.Ins.BackTo(null);
|
||
MRNetworkManager.Ins.JoinRoom(_Info.EndPoint.Address.ToString(), _Info.createTime);
|
||
}
|
||
}
|