mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交新概念 Tile从服务器
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
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;
|
||||
|
||||
@@ -17,6 +22,16 @@ namespace UI
|
||||
|
||||
public Camera MainCamera;
|
||||
|
||||
public Dropdown tileDropdown;
|
||||
|
||||
public List<TileServerInfo> servers;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
AddListener();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
@@ -51,5 +66,54 @@ namespace UI
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <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]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user