修改联机UI,马甲选择第二版
This commit is contained in:
@@ -6,7 +6,10 @@ using TruegearSdk;
|
||||
|
||||
public class ConPanel : UIBehaviour
|
||||
{
|
||||
public static ConPanel Instance { get; private set; }
|
||||
public TrueGearPanel trueGearPanel;
|
||||
public Common.State PanelState;
|
||||
public Transform Page1;
|
||||
public Transform Page2;
|
||||
|
||||
public GameObject IPBtn;
|
||||
@@ -14,6 +17,10 @@ public class ConPanel : UIBehaviour
|
||||
public List<IPBtn> IPBtns;
|
||||
public bool IsInit = false;
|
||||
|
||||
// 选中的房间索引
|
||||
private int _selectedRoomIndex = -1;
|
||||
private IPBtn _selectedBtn = null;
|
||||
|
||||
public static void Show()
|
||||
{
|
||||
WorldUIManager.Ins.Cover("UI/ConPanel", false);
|
||||
@@ -21,14 +28,51 @@ public class ConPanel : UIBehaviour
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
// 根据是否启用马甲功能来决定IPBtn生成在哪个面板
|
||||
// 当使用马甲功能时,生成在第一个面板
|
||||
// 当不使用马甲功能时,生成在第二个面板
|
||||
Transform parentTransform = Page1;
|
||||
if (TrueGearEffectManager.Ins != null && !TrueGearEffectManager.Ins.EnableTrueGear)
|
||||
{
|
||||
parentTransform = Page2;
|
||||
// 当enableTrueGear=false时,显示第二面板,隐藏第一面板
|
||||
if (Page1 != null)
|
||||
{
|
||||
Page1.gameObject.SetActive(false);
|
||||
}
|
||||
if (Page2 != null)
|
||||
{
|
||||
Page2.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// 当enableTrueGear=true时,显示第一面板,隐藏第二面板
|
||||
if (Page1 != null)
|
||||
{
|
||||
Page1.gameObject.SetActive(true);
|
||||
|
||||
}
|
||||
if (Page2 != null)
|
||||
{
|
||||
Page2.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
IPBtn btn = Instantiate(IPBtn, Page2).GetComponent<IPBtn>();
|
||||
IPBtn btn = Instantiate(IPBtn, parentTransform).GetComponent<IPBtn>();
|
||||
btn.gameObject.SetActive(false);
|
||||
IPBtns.Add(btn);
|
||||
}
|
||||
|
||||
IsInit = true;
|
||||
|
||||
// 打开界面时自动开始搜索
|
||||
StartDiscovery();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
@@ -40,6 +84,57 @@ public class ConPanel : UIBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// 启动搜索
|
||||
private void StartDiscovery()
|
||||
{
|
||||
MRNetworkManager.Ins.DiscoveredServers.Clear();
|
||||
MRNetworkManager.Ins.DiscoveredServersList.Clear();
|
||||
MRNetworkManager.Ins.networkDiscovery.StartDiscovery();
|
||||
// 注意:不再自动切换页面,保持当前页面显示
|
||||
}
|
||||
|
||||
// 刷新按钮 - 重新搜索
|
||||
public void OnClickRefresh()
|
||||
{
|
||||
// 清除之前的选中状态
|
||||
ClearSelection();
|
||||
|
||||
// 重新搜索
|
||||
StartDiscovery();
|
||||
}
|
||||
|
||||
// 加入按钮 - 加入选中的房间
|
||||
public void OnClickJoin()
|
||||
{
|
||||
if (_selectedBtn != null && _selectedBtn.GetRoomInfo() != null)
|
||||
{
|
||||
_selectedBtn.JoinRoom();
|
||||
}
|
||||
}
|
||||
|
||||
// 选中房间
|
||||
public void OnSelectRoom(IPBtn btn)
|
||||
{
|
||||
// 清除之前的选中状态
|
||||
ClearSelection();
|
||||
|
||||
// 选中新房间
|
||||
_selectedBtn = btn;
|
||||
_selectedRoomIndex = IPBtns.IndexOf(btn);
|
||||
btn.SetSelected(true);
|
||||
}
|
||||
|
||||
// 清除选中状态
|
||||
private void ClearSelection()
|
||||
{
|
||||
if (_selectedBtn != null)
|
||||
{
|
||||
_selectedBtn.SetSelected(false);
|
||||
_selectedBtn = null;
|
||||
}
|
||||
_selectedRoomIndex = -1;
|
||||
}
|
||||
|
||||
public void OnClickHost()
|
||||
{
|
||||
// 用户未选择设备直接开始游戏,停止扫描
|
||||
@@ -109,4 +204,4 @@ public class ConPanel : UIBehaviour
|
||||
MRNetworkManager.Ins.CreateAndJoinRoom();
|
||||
MRNetworkManager.Ins.networkDiscovery.AdvertiseServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user