Files
DefendNJ/Assets/_DefendNJ/Scripts/UI/IPBtn.cs
2026-04-10 15:46:49 +08:00

63 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}