Browse Source

Merge branch 'main' of https://github.com/KeyKoder/cards-simulator into main

new_protocol
ThePerkinrex 5 years ago
parent
commit
a8f9c1ae54
No known key found for this signature in database GPG Key ID: 1F45A7C4BFB41607
  1. 3607
      unity/Assets/Scenes/MainMenu.unity
  2. 7
      unity/Assets/Scenes/MainMenu.unity.meta
  3. 8
      unity/Assets/Scripts/Client.cs
  4. 90
      unity/Assets/Scripts/MainMenuController.cs
  5. 11
      unity/Assets/Scripts/MainMenuController.cs.meta
  6. 21
      unity/Assets/Scripts/Scrollable.cs
  7. 11
      unity/Assets/Scripts/Scrollable.cs.meta

3607
unity/Assets/Scenes/MainMenu.unity

File diff suppressed because it is too large

7
unity/Assets/Scenes/MainMenu.unity.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2e7eb87aefbaeed4692a1080bf81f769
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
unity/Assets/Scripts/Client.cs

@ -4,9 +4,9 @@ public static class Client
{ {
private static Connection reference; private static Connection reference;
public static void Connect(string name) public static void Connect(string name, string address="127.0.0.1:50052")
{ {
reference = new Connection(name); reference = new Connection(name, address);
} }
public static ref Connection GetConnection() public static ref Connection GetConnection()
@ -30,9 +30,9 @@ public static class Client
private Channel channel; private Channel channel;
private string connId; private string connId;
private uint? lobby = null; private uint? lobby = null;
public Connection(string user) public Connection(string user, string address)
{ {
channel = new Channel("127.0.0.1:50052", ChannelCredentials.Insecure); channel = new Channel(address, ChannelCredentials.Insecure);
connection = new Game.Connection.ConnectionClient(channel); connection = new Game.Connection.ConnectionClient(channel);
lobby_client = new Game.Lobby.LobbyClient(channel); lobby_client = new Game.Lobby.LobbyClient(channel);
connId = connection.connect(new Game.Username { Name = user }).Id; connId = connection.connect(new Game.Username { Name = user }).Id;

90
unity/Assets/Scripts/MainMenuController.cs

@ -0,0 +1,90 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MainMenuController : MonoBehaviour {
public GameObject mainMenu;
public GameObject serverMenu;
public GameObject lobbyMenu;
public InputField username;
public InputField ip;
public InputField port;
void Start() {
// Simulate Lobbies in a Server
for (int i = 0; i < 10; i++) {
var lobby = Instantiate(serverMenu.transform.GetChild(2).GetChild(0).GetChild(0), serverMenu.transform.GetChild(2).GetChild(0));
lobby.GetComponentInChildren<Text>().text = "LBY" + Random.Range(0, 10) + Random.Range(0, 10) + Random.Range(0, 10);
lobby.gameObject.SetActive(true);
}
}
void Update() {}
public void ConnectServer() {
var conn = Client.GetConnection();
if (conn == null) {
if (ip.text != "" && port.text != "")
Client.Connect(username.text, ip.text + ":" + port.text);
else
Client.Connect(username.text);
conn = Client.GetConnection();
}
if (conn != null) {
mainMenu.SetActive(false);
serverMenu.SetActive(true);
lobbyMenu.SetActive(false);
}
}
public void LeaveServer() {
Client.CloseConnection();
mainMenu.SetActive(true);
serverMenu.SetActive(false);
lobbyMenu.SetActive(false);
}
public void ConnectLobby(Text codeText) {
var code = codeText.text;
Debug.Log(code);
var conn = Client.GetConnection();
if (conn != null) {
var lobby = conn.GetLobby();
if (lobby == null) {
conn.JoinLobby(code);
mainMenu.SetActive(false);
serverMenu.SetActive(false);
lobbyMenu.SetActive(true);
}
}
}
public void CreateLobby() {
var conn = Client.GetConnection();
if (conn != null) {
var lobby = conn.GetLobby();
if (lobby == null) {
conn.CreateLobby();
mainMenu.SetActive(false);
serverMenu.SetActive(false);
lobbyMenu.SetActive(true);
}
}
}
public void LeaveLobby() {
var conn = Client.GetConnection();
if (conn == null) {
var lobby = conn.GetLobby();
if (lobby != null) {
//conn.LeaveLobby();
mainMenu.SetActive(false);
serverMenu.SetActive(true);
lobbyMenu.SetActive(false);
}
}
}
}

11
unity/Assets/Scripts/MainMenuController.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71f2f00df2a8c024a8b4bfc9d8412dbe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

21
unity/Assets/Scripts/Scrollable.cs

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Scrollable : MonoBehaviour {
public const float size = 35f;
void Start() {
var sizeY = -(transform.childCount-1) * (transform.GetChild(0).GetComponent<RectTransform>().sizeDelta.y + GetComponent<VerticalLayoutGroup>().spacing);
Debug.Log(transform.parent.GetComponent<RectTransform>().sizeDelta.y + " -- " + (-sizeY));
GetComponent<RectTransform>().offsetMin = new Vector2(GetComponent<RectTransform>().offsetMin.x, (transform.parent.GetComponent<RectTransform>().sizeDelta.y > -sizeY ? 0 : sizeY + transform.parent.GetComponent<RectTransform>().sizeDelta.y + GetComponent<VerticalLayoutGroup>().spacing));
int i = 1;
foreach(Transform child in transform) {
if(i % 2 == 1)
child.GetComponent<RawImage>().color = new Color(child.GetComponent<RawImage>().color.r, child.GetComponent<RawImage>().color.g, child.GetComponent<RawImage>().color.b, child.GetComponent<RawImage>().color.a / 2);
i++;
}
}
void Update() {}
}

11
unity/Assets/Scripts/Scrollable.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dc417d59709b83f40a9f4f9541441269
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save