Online Function With Room Codes
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Camera : MonoBehaviour
|
||||
{
|
||||
//TODO: Replace with Follow Function later (player camera should follow)
|
||||
[SerializeField] private GameObject followUp;
|
||||
private Vector3 offset;
|
||||
private Vector3 velocity = Vector3.zero;
|
||||
|
||||
//TODO: Replace with Follow Function later (player camera should follow)
|
||||
private void Start()
|
||||
{
|
||||
offset = followUp.transform.position - transform.position;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
transform.position = Vector3.SmoothDamp(transform.position, followUp.transform.position - offset, ref velocity, 0.2f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
public class Client : MonoBehaviour
|
||||
{
|
||||
private TcpClient client;
|
||||
private Stream stream;
|
||||
[SerializeField] private GameObject playerPrefab;
|
||||
private Player[] players = new Player[4];
|
||||
private Queue<Job> jobs = new Queue<Job>();
|
||||
[SerializeField] private GameObject dice;
|
||||
[SerializeField] private Field nextField;
|
||||
[SerializeField] private GameObject cam;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
client = new TcpClient("185.245.96.48", 8051);
|
||||
stream = client.GetStream();
|
||||
|
||||
stream.Write(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 10);
|
||||
|
||||
|
||||
string roomCode = PlayerPrefs.GetString("roomcode");
|
||||
stream.Write(Encoding.ASCII.GetBytes(roomCode));
|
||||
|
||||
new Thread(Read).Start();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (jobs.Count > 0)
|
||||
{
|
||||
Job job = jobs.Dequeue();
|
||||
|
||||
switch (job.data[0])
|
||||
{
|
||||
//-----Create A new player-----
|
||||
case 1:
|
||||
//player is playable
|
||||
if (job.data[1] == 1)
|
||||
{
|
||||
GameObject player = Instantiate(playerPrefab);
|
||||
|
||||
player.transform.position = new Vector3(job.data[2], job.data[3] + 0.5f, job.data[4]);
|
||||
|
||||
PlayablePlayer script = player.AddComponent<PlayablePlayer>();
|
||||
players[job.data[5]] = script;
|
||||
script.client = this;
|
||||
script.nextField = nextField;
|
||||
script.dice = dice;
|
||||
script.Init();
|
||||
}
|
||||
//player is not playable
|
||||
else
|
||||
{
|
||||
GameObject player = Instantiate(playerPrefab);
|
||||
|
||||
player.transform.position = new Vector3(job.data[2], job.data[3] + 0.5f, job.data[4]);
|
||||
|
||||
NoPlayablePlayer script = player.AddComponent<NoPlayablePlayer>();
|
||||
players[job.data[5]] = script;
|
||||
script.nextField = nextField;
|
||||
script.dice = dice;
|
||||
script.Init();
|
||||
}
|
||||
break;
|
||||
//---------------------------------------------------------
|
||||
//-----Activate a Player
|
||||
case 2:
|
||||
Activate(job.data[1]);
|
||||
break;
|
||||
//Jemand hat gewürfelt
|
||||
case 3:
|
||||
((NoPlayablePlayer)players[job.data[1]]).Wurfeln(job.data[2]);
|
||||
break;
|
||||
//Jemand hat den Pfeil geklickt
|
||||
case 4:
|
||||
((NoPlayablePlayer)players[job.data[1]]).ArrowSelect(job.data[2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Activate(int player)
|
||||
{
|
||||
for (int i = 0; i < players.Length; i++)
|
||||
{
|
||||
if (players[i] != null)
|
||||
{
|
||||
if (i == player)
|
||||
{
|
||||
players[i].Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
players[i].DeActivate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cam.transform.parent = players[player].transform;
|
||||
cam.transform.localPosition = new Vector3(-3, 8, 7);
|
||||
}
|
||||
|
||||
|
||||
private void Read()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
byte[] read = new byte[10];
|
||||
|
||||
stream.Read(read, 0, 10);
|
||||
|
||||
jobs.Enqueue(new Job(read));
|
||||
}
|
||||
}
|
||||
|
||||
//0 3 wurfeln
|
||||
//1 x, x = zahl
|
||||
public void SendWurfeln(int zahl)
|
||||
{
|
||||
|
||||
stream.Write(new byte[]{3, (byte)zahl, 0, 0, 0, 0, 0, 0, 0, 0});
|
||||
}
|
||||
|
||||
//0 4 arrow selected
|
||||
//1 x, x = arrow idx
|
||||
public void SendArrowSelected(int idx)
|
||||
{
|
||||
stream.Write(new byte[]{4, (byte)idx, 0, 0, 0, 0, 0, 0, 0, 0});
|
||||
}
|
||||
|
||||
//0 5
|
||||
public void SendFinished()
|
||||
{
|
||||
stream.Write(new byte[]{5, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f02425538b327cc47a5d70da69804669
|
||||
guid: 812fca21913ccbd42a3f716f9c3b7727
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Job
|
||||
{
|
||||
public byte[] data;
|
||||
|
||||
public Job(byte[] data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e64a1673d23a4304fa81de76a9941bb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,126 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class NoPlayablePlayer : Player
|
||||
{
|
||||
public Field nextField;
|
||||
private Field currentField;
|
||||
public GameObject dice;
|
||||
private Dice diceScript;
|
||||
private Vector3 moveTo = Vector3.zero;
|
||||
private Vector3 lastPos = Vector3.zero;
|
||||
private float speed = 5;
|
||||
private float interPol = 0;
|
||||
private int wurfelZahl = 0;
|
||||
|
||||
private bool wait = false;
|
||||
private bool lastActivated = false;
|
||||
|
||||
private float timeSinceWurfeln = 0;
|
||||
|
||||
private Vector3 useLess = new Vector3();
|
||||
|
||||
public void Init()
|
||||
{
|
||||
activated = false;
|
||||
diceScript = dice.GetComponent<Dice>();
|
||||
}
|
||||
|
||||
public void Wurfeln(int wurfelZahl)
|
||||
{
|
||||
this.wurfelZahl = wurfelZahl;
|
||||
//nächstes Feld anvisieren
|
||||
TargetNextField();
|
||||
|
||||
//stop the dice
|
||||
diceScript.StopRandom(wurfelZahl);
|
||||
|
||||
//delay for walk start
|
||||
timeSinceWurfeln = Time.time;
|
||||
}
|
||||
|
||||
public void ArrowSelect(int idx)
|
||||
{
|
||||
foreach (Arrow a in nextField.DirectionalArrow)
|
||||
{
|
||||
a.Deactivate();
|
||||
}
|
||||
|
||||
nextField = nextField.Target[idx];
|
||||
moveTo = nextField.transform.position;
|
||||
wait = false;
|
||||
}
|
||||
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (activated)
|
||||
{
|
||||
if (!wait)
|
||||
{
|
||||
//Laufe zum nöchsten Feld, falls noch Züge übrig sind
|
||||
if (interPol < 1 && wurfelZahl > 0)
|
||||
{
|
||||
//delay
|
||||
if (Time.time - timeSinceWurfeln > 1)
|
||||
{
|
||||
InterPolerate();
|
||||
}
|
||||
}
|
||||
//Würfelzahl um 1 verringern falls noch züge übrig sind
|
||||
else if (wurfelZahl > 0)
|
||||
{
|
||||
wurfelZahl--;
|
||||
|
||||
//Visiere das nächste Feld an falls noch ein Zug übrig ist (Player steht gerade auf einem Feld oder läuft darüber)
|
||||
if (wurfelZahl > 0)
|
||||
{
|
||||
TargetNextField();
|
||||
}
|
||||
}
|
||||
//Der Spieler steht gerade
|
||||
else
|
||||
{
|
||||
//start the dice
|
||||
dice.transform.position = Vector3.SmoothDamp(dice.transform.position,
|
||||
transform.position + Vector3.up * 2, ref useLess, 0.2f);
|
||||
diceScript.StartRandom();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Arrow a in nextField.DirectionalArrow)
|
||||
{
|
||||
a.Activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Das nächste Feld aufgrund des aktuellen Feldes anvisieren
|
||||
private void TargetNextField()
|
||||
{
|
||||
interPol = 0;
|
||||
lastPos = transform.position;
|
||||
currentField = nextField;
|
||||
if (nextField.Target.Length == 1)
|
||||
{
|
||||
nextField = nextField.Target[0];
|
||||
moveTo = nextField.transform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
wait = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Bewegt den Player von einem Punkt(lastPos) zu einem anderen Punkt(moveTo) mit konstanter Geschwindigkeit
|
||||
private void InterPolerate()
|
||||
{
|
||||
Vector3 nextPoint = Vector3.Lerp(lastPos, moveTo, interPol);
|
||||
transform.position = new Vector3(nextPoint.x, transform.position.y, nextPoint.z);
|
||||
interPol += (Time.deltaTime * speed) / Mathf.Abs(Vector3.Distance(moveTo, lastPos));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68609d4bfa4ff26459dc9a4f510bf86d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,161 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayablePlayer : Player
|
||||
{
|
||||
public Field nextField;
|
||||
private Field currentField;
|
||||
public GameObject dice;
|
||||
private Dice diceScript;
|
||||
private Vector3 moveTo = Vector3.zero;
|
||||
private Vector3 lastPos = Vector3.zero;
|
||||
private float speed = 5;
|
||||
private float interPol = 0;
|
||||
private int wurfelZahl = 0;
|
||||
|
||||
private bool wait = false;
|
||||
|
||||
|
||||
private float timeSinceWurfeln = 0;
|
||||
|
||||
private Vector3 useLess = new Vector3();
|
||||
|
||||
public Client client;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
activated = false;
|
||||
QualitySettings.vSyncCount = 0;
|
||||
Application.targetFrameRate = 59;
|
||||
diceScript = dice.GetComponent<Dice>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (activated)
|
||||
{
|
||||
//Generiere Würfelzahl von 1-6 wenn gerade gewürfelt werden darf
|
||||
if ((Input.GetMouseButtonDown(0)) && wurfelZahl == 0 && !wurfelt)
|
||||
{
|
||||
wurfelt = true;
|
||||
wurfelZahl = Random.Range(1, 7);
|
||||
|
||||
client.SendWurfeln(wurfelZahl);
|
||||
|
||||
//nächstes Feld anvisieren
|
||||
TargetNextField();
|
||||
|
||||
//stop the dice
|
||||
diceScript.StopRandom(wurfelZahl);
|
||||
|
||||
//delay for walk start
|
||||
timeSinceWurfeln = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (activated)
|
||||
{
|
||||
if (!wait)
|
||||
{
|
||||
//Laufe zum nöchsten Feld, falls noch Züge übrig sind
|
||||
if (interPol < 1 && wurfelZahl > 0)
|
||||
{
|
||||
//delay
|
||||
if (Time.time - timeSinceWurfeln > 1)
|
||||
{
|
||||
InterPolerate();
|
||||
}
|
||||
}
|
||||
//Würfelzahl um 1 verringern falls noch züge übrig sind
|
||||
else if (wurfelZahl > 0)
|
||||
{
|
||||
wurfelZahl--;
|
||||
|
||||
//Visiere das nächste Feld an falls noch ein Zug übrig ist (Player steht gerade auf einem Feld oder läuft darüber)
|
||||
if (wurfelZahl > 0)
|
||||
{
|
||||
TargetNextField();
|
||||
}
|
||||
}
|
||||
//Der Spieler steht gerade
|
||||
else
|
||||
{
|
||||
//start the dice
|
||||
dice.transform.position = Vector3.SmoothDamp(dice.transform.position,
|
||||
transform.position + Vector3.up * 2, ref useLess, 0.2f);
|
||||
diceScript.StartRandom();
|
||||
|
||||
//TODO: temp spieler finsihed erst, wenn field action ausgeführt wurde
|
||||
if (wurfelt)
|
||||
{
|
||||
client.SendFinished();
|
||||
activated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Arrow a in nextField.DirectionalArrow)
|
||||
{
|
||||
a.Activate();
|
||||
}
|
||||
|
||||
if (nextField.DirectionalArrow[0].IsClicked())
|
||||
{
|
||||
client.SendArrowSelected(0);
|
||||
|
||||
foreach (Arrow a in nextField.DirectionalArrow)
|
||||
{
|
||||
a.Deactivate();
|
||||
}
|
||||
|
||||
nextField = nextField = nextField.Target[0];
|
||||
moveTo = nextField.transform.position;
|
||||
wait = false;
|
||||
}
|
||||
else if (nextField.DirectionalArrow[1].IsClicked())
|
||||
{
|
||||
client.SendArrowSelected(1);
|
||||
foreach (Arrow a in nextField.DirectionalArrow)
|
||||
{
|
||||
a.Deactivate();
|
||||
}
|
||||
|
||||
nextField = nextField = nextField.Target[1];
|
||||
moveTo = nextField.transform.position;
|
||||
wait = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Das nächste Feld aufgrund des aktuellen Feldes anvisieren
|
||||
private void TargetNextField()
|
||||
{
|
||||
interPol = 0;
|
||||
lastPos = transform.position;
|
||||
currentField = nextField;
|
||||
if (nextField.Target.Length == 1)
|
||||
{
|
||||
nextField = nextField.Target[0];
|
||||
moveTo = nextField.transform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
wait = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Bewegt den Player von einem Punkt(lastPos) zu einem anderen Punkt(moveTo) mit konstanter Geschwindigkeit
|
||||
private void InterPolerate()
|
||||
{
|
||||
Vector3 nextPoint = Vector3.Lerp(lastPos, moveTo, interPol);
|
||||
transform.position = new Vector3(nextPoint.x, transform.position.y, nextPoint.z);
|
||||
interPol += (Time.deltaTime * speed) / Mathf.Abs(Vector3.Distance(moveTo, lastPos));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec20d73d6ef92f6469fe8f5daf50c15c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,159 +1,17 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Field nextField;
|
||||
private Field currentField;
|
||||
[SerializeField] private GameObject dice;
|
||||
private Dice diceScript;
|
||||
private Vector3 moveTo = Vector3.zero;
|
||||
private Vector3 lastPos = Vector3.zero;
|
||||
private float speed = 5;
|
||||
private float interPol = 0;
|
||||
private int wurfelZahl = 0;
|
||||
|
||||
private bool activated = true;
|
||||
private bool wait = false;
|
||||
private bool lastActivated = false;
|
||||
|
||||
private float timeSinceWurfeln = 0;
|
||||
public bool activated = false;
|
||||
protected bool wurfelt = false;
|
||||
|
||||
//TESTTTTT
|
||||
[SerializeField] private TMP_Text fpsText;
|
||||
|
||||
private Vector3 useLess = new Vector3();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
QualitySettings.vSyncCount = 0;
|
||||
Application.targetFrameRate = 9999;
|
||||
diceScript = dice.GetComponent<Dice>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
fpsText.text = ((int)Time.frameCount / (int)Time.time) + " fps";
|
||||
|
||||
if(activated)
|
||||
{
|
||||
//Generiere Würfelzahl von 1-6 wenn gerade gewürfelt werden darf
|
||||
if ((Input.GetMouseButtonDown(0)) && wurfelZahl == 0)
|
||||
{
|
||||
wurfelZahl = Random.Range(1, 7);
|
||||
//nächstes Feld anvisieren
|
||||
TargetNextField();
|
||||
|
||||
//stop the dice
|
||||
diceScript.StopRandom(wurfelZahl);
|
||||
|
||||
//delay for walk start
|
||||
timeSinceWurfeln = Time.time;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (activated)
|
||||
{
|
||||
if (!wait)
|
||||
{
|
||||
//Laufe zum nöchsten Feld, falls noch Züge übrig sind
|
||||
if (interPol < 1 && wurfelZahl > 0)
|
||||
{
|
||||
|
||||
//delay
|
||||
if(Time.time - timeSinceWurfeln > 1)
|
||||
{
|
||||
InterPolerate();
|
||||
}
|
||||
}
|
||||
//Würfelzahl um 1 verringern falls noch züge übrig sind
|
||||
else if (wurfelZahl > 0 )
|
||||
{
|
||||
wurfelZahl--;
|
||||
|
||||
//Visiere das nächste Feld an falls noch ein Zug übrig ist (Player steht gerade auf einem Feld oder läuft darüber)
|
||||
if (wurfelZahl > 0)
|
||||
{
|
||||
TargetNextField();
|
||||
}
|
||||
}
|
||||
//Der Spieler steht gerade
|
||||
else
|
||||
{
|
||||
//start the dice
|
||||
dice.transform.position = Vector3.SmoothDamp(dice.transform.position,
|
||||
transform.position + Vector3.up * 2, ref useLess, 0.2f);
|
||||
diceScript.StartRandom();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach(Arrow a in nextField.DirectionalArrow)
|
||||
{
|
||||
a.Activate();
|
||||
}
|
||||
|
||||
if (nextField.DirectionalArrow[0].IsClicked())
|
||||
{
|
||||
foreach(Arrow a in nextField.DirectionalArrow)
|
||||
{
|
||||
a.Deactivate();
|
||||
}
|
||||
nextField = nextField = nextField.Target[0];
|
||||
moveTo = nextField.transform.position;
|
||||
wait = false;
|
||||
}
|
||||
else if (nextField.DirectionalArrow[1].IsClicked())
|
||||
{
|
||||
foreach(Arrow a in nextField.DirectionalArrow)
|
||||
{
|
||||
a.Deactivate();
|
||||
}
|
||||
nextField = nextField = nextField.Target[1];
|
||||
moveTo = nextField.transform.position;
|
||||
wait = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Das nächste Feld aufgrund des aktuellen Feldes anvisieren
|
||||
private void TargetNextField()
|
||||
{
|
||||
interPol = 0;
|
||||
lastPos = transform.position;
|
||||
currentField = nextField;
|
||||
if(nextField.Target.Length == 1)
|
||||
{
|
||||
nextField = nextField.Target[0];
|
||||
moveTo = nextField.transform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
wait = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Bewegt den Player von einem Punkt(lastPos) zu einem anderen Punkt(moveTo) mit konstanter Geschwindigkeit
|
||||
private void InterPolerate()
|
||||
{
|
||||
Vector3 nextPoint = Vector3.Lerp(lastPos, moveTo, interPol);
|
||||
transform.position = new Vector3(nextPoint.x, transform.position.y, nextPoint.z);
|
||||
interPol += (Time.deltaTime * speed) / Mathf.Abs(Vector3.Distance(moveTo, lastPos));
|
||||
}
|
||||
|
||||
//Aktiviert den Player
|
||||
public void Activate()
|
||||
{
|
||||
activated = true;
|
||||
wurfelt = false;
|
||||
}
|
||||
|
||||
//Deaktiviert den Player
|
||||
@@ -161,4 +19,4 @@ public class Player : MonoBehaviour
|
||||
{
|
||||
activated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c996b0ab459030a4e9d75049c0105263
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class StartHandler : MonoBehaviour
|
||||
{
|
||||
private TcpClient client;
|
||||
[SerializeField] private GameObject layout1;
|
||||
[SerializeField] private GameObject layout2;
|
||||
[SerializeField] private TMP_Text roomCodeEnter;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
client = new TcpClient("185.245.96.48", 8051);
|
||||
|
||||
layout1.SetActive(true);
|
||||
layout2.SetActive(false);
|
||||
}
|
||||
|
||||
public void ButtonNewRoom()
|
||||
{
|
||||
Stream stream = client.GetStream();
|
||||
byte[] readMessage = new byte[10];
|
||||
|
||||
//Send message new room
|
||||
stream.Write(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
||||
|
||||
layout1.SetActive(false);
|
||||
layout2.SetActive(true);
|
||||
|
||||
//wait for room code
|
||||
int i = stream.Read(readMessage, 0, 10);
|
||||
|
||||
Debug.Log(i);
|
||||
|
||||
string code = Encoding.ASCII.GetString(readMessage);
|
||||
|
||||
PlayerPrefs.SetString("roomcode", code);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
GUIUtility.systemCopyBuffer = code;
|
||||
layout2.GetComponentInChildren<TMP_Text>().text = "Your room code is: \n" + code + "\n copied to clipboard!";
|
||||
}
|
||||
|
||||
public void ButtonJoin()
|
||||
{
|
||||
string code = roomCodeEnter.text;
|
||||
PlayerPrefs.SetString("roomcode", code);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
SceneManager.LoadScene(1, LoadSceneMode.Single);
|
||||
client.Close();
|
||||
}
|
||||
|
||||
public void ButtonJoin2()
|
||||
{
|
||||
SceneManager.LoadScene(1, LoadSceneMode.Single);
|
||||
client.Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c98cb2b6987650844a331238afcbf2f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user