show other names
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
@@ -19,6 +20,7 @@ public class Client
|
||||
private UdpClient client;
|
||||
private int port;
|
||||
private Thread receiveThread;
|
||||
private string nameOther = null;
|
||||
|
||||
public Client(string hostname, int port, World world, string name)
|
||||
{
|
||||
@@ -236,6 +238,19 @@ public class Client
|
||||
|
||||
world.UpdatePlayerRotation(new Quaternion(x, y, z, w), id);
|
||||
}
|
||||
|
||||
//name request
|
||||
if (data[0] == 11)
|
||||
{
|
||||
List<byte> nameASCII = new List<byte>();
|
||||
|
||||
for (int i = 1; i < data.Length; i++)
|
||||
{
|
||||
nameASCII.Add(data[i]);
|
||||
}
|
||||
|
||||
nameOther = Encoding.ASCII.GetString(nameASCII.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -265,6 +280,19 @@ public class Client
|
||||
client.Send(data, data.Length);
|
||||
}
|
||||
|
||||
public string GetPlayerName(int id)
|
||||
{
|
||||
Send(new byte[]{11, (byte)id});
|
||||
|
||||
while (nameOther == null)
|
||||
{
|
||||
}
|
||||
|
||||
string ret = nameOther;
|
||||
nameOther = null;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void SaveWorld()
|
||||
{
|
||||
Send(new byte[]{9});
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class World : MonoBehaviour
|
||||
{
|
||||
@@ -25,6 +26,7 @@ public class World : MonoBehaviour
|
||||
[SerializeField] private GameObject deadScreen;
|
||||
[SerializeField] private GameObject pauseScreen;
|
||||
[SerializeField] private GameObject optionsScreen;
|
||||
[SerializeField] private Camera camera;
|
||||
private ChunkCoord lastPlayerChunkCoord = new ChunkCoord(0, 0);
|
||||
|
||||
//chunks
|
||||
@@ -93,11 +95,16 @@ public class World : MonoBehaviour
|
||||
if (playersToCreate.Count > 0)
|
||||
{
|
||||
byte id = playersToCreate.Dequeue();
|
||||
string nameOther = client.GetPlayerName(id);
|
||||
GameObject player = Instantiate(playerPrefab);
|
||||
player.transform.position = new Vector3((int)player.transform.position.x,
|
||||
GetHeight((byte)player.transform.position.x, (byte)player.transform.position.z) + 2,
|
||||
(int)player.transform.position.z);
|
||||
player.transform.SetParent(gameObject.transform);
|
||||
Canvas canvas = player.GetComponentInChildren<Canvas>();
|
||||
canvas.worldCamera = camera;
|
||||
Text nameText = player.GetComponentInChildren<Text>();
|
||||
nameText.text = nameOther;
|
||||
otherPlayers.Add(id, player);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user