2024-10-16 20:41:40 +08:00
|
|
|
|
using System.Collections.Generic;
|
2024-08-31 15:35:12 +08:00
|
|
|
|
using System.Linq;
|
2024-08-17 14:27:18 +08:00
|
|
|
|
using AppGame;
|
2024-08-31 15:35:12 +08:00
|
|
|
|
using AppGame.Sync;
|
2024-08-17 14:27:18 +08:00
|
|
|
|
using Game.Input;
|
2024-10-17 01:59:25 +08:00
|
|
|
|
using JNGame.Runtime.Util;
|
2024-08-17 14:27:18 +08:00
|
|
|
|
using JNGame.Math;
|
2024-08-31 15:35:12 +08:00
|
|
|
|
using JNGame.Util;
|
2024-11-24 19:33:12 +08:00
|
|
|
|
using Samples.AppGame;
|
2024-08-17 14:27:18 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace UI
|
|
|
|
|
{
|
|
|
|
|
public class DMainUI : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public GameObject root;
|
|
|
|
|
public Text SizeText;
|
|
|
|
|
public Text ByteSizeText;
|
|
|
|
|
|
|
|
|
|
public Camera MainCamera;
|
|
|
|
|
|
2024-08-31 15:35:12 +08:00
|
|
|
|
public Dropdown tileDropdown;
|
|
|
|
|
|
|
|
|
|
public List<TileServerInfo> servers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
AddListener();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 14:27:18 +08:00
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
SizeText.text = $"{root.transform.childCount}";
|
|
|
|
|
if (App.IsClient())
|
|
|
|
|
{
|
|
|
|
|
// ByteSizeText.text = $"{JNTCPClient.Size}";
|
|
|
|
|
}
|
|
|
|
|
if (App.IsServer())
|
|
|
|
|
{
|
|
|
|
|
ByteSizeText.text = $"{App.Server.GetByteSize()}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(App.IsClient())) return;
|
|
|
|
|
|
|
|
|
|
float moveHorizontal = Input.GetAxis("Horizontal");
|
|
|
|
|
float moveVertical = Input.GetAxis("Vertical");
|
|
|
|
|
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
|
|
|
|
|
var transform1 = MainCamera.transform;
|
|
|
|
|
movement = transform1.forward * movement.z + transform1.right * movement.x;
|
|
|
|
|
movement = movement.normalized;
|
|
|
|
|
|
|
|
|
|
IDPlayerMoveVector vector = new IDPlayerMoveVector
|
|
|
|
|
{
|
|
|
|
|
X = movement.x.ToLFloat(),
|
|
|
|
|
Y = movement.z.ToLFloat(),
|
|
|
|
|
};
|
2024-08-22 20:37:39 +08:00
|
|
|
|
if (App.Game.IsStartClient)
|
2024-08-17 14:27:18 +08:00
|
|
|
|
{
|
|
|
|
|
App.Game.GetInput<IDPlayer>().MoveVector = vector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-31 15:35:12 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 监听事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void AddListener()
|
|
|
|
|
{
|
|
|
|
|
App.Event.AddListener(GEvent.GSwPlayerTile,OnGSwPlayerTile);
|
|
|
|
|
App.Event.AddListener(GEvent.NetNewTileServer,OnGSwPlayerTile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
App.Event.RemoveListener(GEvent.GSwPlayerTile,OnGSwPlayerTile);
|
|
|
|
|
App.Event.RemoveListener(GEvent.NetNewTileServer,OnGSwPlayerTile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 玩家区块切换了
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async void OnGSwPlayerTile()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int? tile = App.Game.GetClient<JNGTileClientSystem>()?.PlayerTile;
|
|
|
|
|
if (tile is null) return;
|
|
|
|
|
|
|
|
|
|
async void Action()
|
|
|
|
|
{
|
|
|
|
|
servers = (await App.GAPI.NSyncTileListServer(tile.Value)).data;
|
|
|
|
|
tileDropdown.ClearOptions();
|
|
|
|
|
tileDropdown.AddOptions(servers.Select(server => $"{(server.master ? "主" : "副")}:{server.port}").ToList());
|
|
|
|
|
}
|
|
|
|
|
await UnityMainThreadDispatcher.Instance.EnqueueAsync(Action);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 切换区块
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void OnSwitchTile()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (servers.Count <= tileDropdown.value) return;
|
|
|
|
|
|
|
|
|
|
App.Game.GetClient<JNGTileClientSystem>()
|
|
|
|
|
?.SwSocket(servers[tileDropdown.value].tile, servers[tileDropdown.value]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 14:27:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|