NameSync
This commit is contained in:
@@ -30,6 +30,8 @@ public class Client : MonoBehaviour
|
||||
|
||||
string roomCode = PlayerPrefs.GetString("roomcode");
|
||||
stream.Write(Encoding.ASCII.GetBytes(roomCode));
|
||||
string name = PlayerPrefs.GetString("name");
|
||||
stream.Write(Encoding.ASCII.GetBytes(name));
|
||||
|
||||
new Thread(Read).Start();
|
||||
}
|
||||
@@ -57,7 +59,6 @@ public class Client : MonoBehaviour
|
||||
script.nextField = nextField;
|
||||
script.dice = dice;
|
||||
script.camera = cam;
|
||||
script.Init();
|
||||
}
|
||||
//player is not playable
|
||||
else
|
||||
@@ -71,7 +72,6 @@ public class Client : MonoBehaviour
|
||||
script.nextField = nextField;
|
||||
script.dice = dice;
|
||||
script.camera = cam;
|
||||
script.Init();
|
||||
}
|
||||
break;
|
||||
//---------------------------------------------------------
|
||||
@@ -87,6 +87,18 @@ public class Client : MonoBehaviour
|
||||
case 4:
|
||||
((NoPlayablePlayer)players[job.data[1]]).ArrowSelect(job.data[2]);
|
||||
break;
|
||||
case 5:
|
||||
byte[] name = new byte[8];
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
name[i] = job.data[i + 2];
|
||||
}
|
||||
|
||||
players[job.data[1]].name = Encoding.ASCII.GetString(name).Replace(" ", "");
|
||||
players[job.data[1]].Init();
|
||||
|
||||
Debug.Log("test");
|
||||
break;
|
||||
case 127:
|
||||
client.Close();
|
||||
SceneManager.LoadScene(0, LoadSceneMode.Single);
|
||||
|
||||
@@ -21,7 +21,7 @@ public class NoPlayablePlayer : Player
|
||||
|
||||
private Vector3 useLess = new Vector3();
|
||||
|
||||
public void Init()
|
||||
public override void Init()
|
||||
{
|
||||
activated = false;
|
||||
diceScript = dice.GetComponent<Dice>();
|
||||
@@ -57,7 +57,7 @@ public class NoPlayablePlayer : Player
|
||||
private void FixedUpdate()
|
||||
{
|
||||
|
||||
if (activated)
|
||||
if (activated && !name.Equals(""))
|
||||
{
|
||||
camera.transform.position = Vector3.SmoothDamp(camera.transform.position, transform.position + cameraOffset, ref velocity, 0.2f);
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class PlayablePlayer : Player
|
||||
|
||||
public Client client;
|
||||
|
||||
public void Init()
|
||||
public override void Init()
|
||||
{
|
||||
activated = false;
|
||||
QualitySettings.vSyncCount = 0;
|
||||
@@ -34,7 +34,7 @@ public class PlayablePlayer : Player
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (activated)
|
||||
if (activated && !name.Equals(""))
|
||||
{
|
||||
//Generiere Würfelzahl von 1-6 wenn gerade gewürfelt werden darf
|
||||
if ((Input.GetMouseButtonDown(0)) && wurfelZahl == 0 && !wurfelt)
|
||||
@@ -58,7 +58,7 @@ public class PlayablePlayer : Player
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (activated)
|
||||
if (activated && !name.Equals(""))
|
||||
{
|
||||
camera.transform.position = Vector3.SmoothDamp(camera.transform.position, transform.position + cameraOffset, ref velocity, 0.2f);
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
public abstract class Player : MonoBehaviour
|
||||
{
|
||||
public string name = "";
|
||||
public bool activated = false;
|
||||
protected bool wurfelt = false;
|
||||
|
||||
@@ -24,4 +25,6 @@ public class Player : MonoBehaviour
|
||||
{
|
||||
activated = false;
|
||||
}
|
||||
|
||||
public abstract void Init();
|
||||
}
|
||||
|
||||
@@ -10,16 +10,30 @@ using UnityEngine.SceneManagement;
|
||||
public class StartHandler : MonoBehaviour
|
||||
{
|
||||
private TcpClient client;
|
||||
[SerializeField] private GameObject layout0;
|
||||
[SerializeField] private GameObject layout1;
|
||||
[SerializeField] private GameObject layout2;
|
||||
[SerializeField] private TMP_Text roomCodeEnter;
|
||||
[SerializeField] private TMP_Text nameEnter;
|
||||
[SerializeField] private GameObject buttonJoin;
|
||||
[SerializeField] private GameObject buttonSubmitName;
|
||||
|
||||
private string roomcode;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
layout1.SetActive(true);
|
||||
PlayerPrefs.DeleteAll();
|
||||
|
||||
if (PlayerPrefs.HasKey("name"))
|
||||
{
|
||||
layout0.SetActive(false);
|
||||
layout1.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
layout0.SetActive(true);
|
||||
layout1.SetActive(false);
|
||||
}
|
||||
layout2.SetActive(false);
|
||||
client = new TcpClient("185.245.96.48", 8051);
|
||||
buttonJoin.SetActive(false);
|
||||
@@ -39,8 +53,6 @@ public class StartHandler : MonoBehaviour
|
||||
//wait for room code
|
||||
int i = stream.Read(readMessage, 0, 10);
|
||||
|
||||
Debug.Log(i);
|
||||
|
||||
string code = Encoding.ASCII.GetString(readMessage);
|
||||
|
||||
PlayerPrefs.SetString("roomcode", code);
|
||||
@@ -91,4 +103,31 @@ public class StartHandler : MonoBehaviour
|
||||
buttonJoin.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTextHasChangedNameInput(string s)
|
||||
{
|
||||
if (s.Length > 0)
|
||||
{
|
||||
buttonSubmitName.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonSubmitName.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void ButtonSubmitName()
|
||||
{
|
||||
string name = nameEnter.text;
|
||||
for (int i = name.Length; i < 10; i++)
|
||||
{
|
||||
name += " ";
|
||||
}
|
||||
|
||||
PlayerPrefs.SetString("name", name);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
layout0.SetActive(false);
|
||||
layout1.SetActive(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user