mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
119
JNFrame2/Assets/Scripts/Samples/UI/DMainUI.cs
Normal file
119
JNFrame2/Assets/Scripts/Samples/UI/DMainUI.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AppGame;
|
||||
using AppGame.Sync;
|
||||
using Game.Input;
|
||||
using JNGame.Math;
|
||||
using JNGame.Util;
|
||||
using Plugins.JNGame.Network;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class DMainUI : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject root;
|
||||
public Text SizeText;
|
||||
public Text ByteSizeText;
|
||||
|
||||
public Camera MainCamera;
|
||||
|
||||
public Dropdown tileDropdown;
|
||||
|
||||
public List<TileServerInfo> servers;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
AddListener();
|
||||
}
|
||||
|
||||
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(),
|
||||
};
|
||||
if (App.Game.IsStartClient)
|
||||
{
|
||||
App.Game.GetInput<IDPlayer>().MoveVector = vector;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <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]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
3
JNFrame2/Assets/Scripts/Samples/UI/DMainUI.cs.meta
Normal file
3
JNFrame2/Assets/Scripts/Samples/UI/DMainUI.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92f14f0fc9194cc3993c79ccce2bc7ee
|
||||
timeCreated: 1722219215
|
Reference in New Issue
Block a user