98 lines
2.9 KiB
C#
98 lines
2.9 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.InputSystem;
|
||
|
using BITKit;
|
||
|
using BITKit.UX;
|
||
|
using Net;
|
||
|
using Net.Client;
|
||
|
using Net.Share;
|
||
|
namespace BITFALL.UX
|
||
|
{
|
||
|
public class Menu : UXPanel
|
||
|
{
|
||
|
[Header(Constant.Header.Components)]
|
||
|
public UXButton connectButton;
|
||
|
public UXButton localhostButton;
|
||
|
public UXButton disconnectButton;
|
||
|
public UXButton returnButton;
|
||
|
public UXImage backgroundImage;
|
||
|
[Header(Constant.Header.Input)]
|
||
|
public InputActionReference returnAction;
|
||
|
public InputActionGroup inputActionGroup;
|
||
|
public override void OnStart()
|
||
|
{
|
||
|
base.OnStart();
|
||
|
BITNet.OnConnected += OnConnected;
|
||
|
BITNet.OnConnectLost += OnDisconnect;
|
||
|
BITNet.OnConnectLost += OnDisconnect;
|
||
|
BITNet.OnConnectFailed += OnDisconnect;
|
||
|
|
||
|
inputActionGroup.RegisterCallback(returnAction, OnReturn);
|
||
|
|
||
|
OnDisconnected();
|
||
|
}
|
||
|
public override void Set(bool active)
|
||
|
{
|
||
|
base.Set(active);
|
||
|
inputActionGroup.allowInput.SetElements(this, active);
|
||
|
}
|
||
|
public void StartIntelnetConnect()
|
||
|
{
|
||
|
DI.Get<BITNet>().ConnectToServer();
|
||
|
}
|
||
|
public void StartLocalConnect()
|
||
|
{
|
||
|
DI.Get<BITNet>().ConnectToLocal();
|
||
|
}
|
||
|
public void Disconnect()
|
||
|
{
|
||
|
DI.Get<BITNet>().Disconnect();
|
||
|
}
|
||
|
public void OnConnected()
|
||
|
{
|
||
|
connectButton.SetEnabled(true);
|
||
|
localhostButton.SetEnabled(true);
|
||
|
|
||
|
returnButton.SetActive(true);
|
||
|
connectButton.SetActive(false);
|
||
|
localhostButton.SetActive(false);
|
||
|
disconnectButton.SetActive(true);
|
||
|
backgroundImage.SetActive(false);
|
||
|
}
|
||
|
public void OnConnectFailed()
|
||
|
{
|
||
|
UXFramework.Enter<Menu>();
|
||
|
connectButton.SetEnabled(true);
|
||
|
localhostButton.SetEnabled(true);
|
||
|
OnDisconnected();
|
||
|
}
|
||
|
public void OnStartConnect()
|
||
|
{
|
||
|
connectButton.SetEnabled(false);
|
||
|
localhostButton.SetEnabled(false);
|
||
|
}
|
||
|
public void OnDisconnected()
|
||
|
{
|
||
|
returnButton.SetActive(false);
|
||
|
connectButton.SetActive(true);
|
||
|
localhostButton.SetActive(true);
|
||
|
disconnectButton.SetActive(false);
|
||
|
backgroundImage.SetActive(true);
|
||
|
}
|
||
|
void OnDisconnect()
|
||
|
{
|
||
|
BIT4Log.Log<Menu>("正在尝试返回到主菜单");
|
||
|
UXFramework.Enter<Menu>();
|
||
|
OnDisconnected();
|
||
|
}
|
||
|
void OnReturn(InputAction.CallbackContext context)
|
||
|
{
|
||
|
/* if (ClientManager.Instance.client.Connected)
|
||
|
if (context.ReadValueAsButton())
|
||
|
{
|
||
|
UXFramework.Enter<HUD>();
|
||
|
} */
|
||
|
}
|
||
|
}
|
||
|
}
|