mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
Ready Up and Clean Up
This commit is contained in:
@@ -38,7 +38,7 @@ RenderSettings:
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1}
|
||||
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
@@ -1100,7 +1100,7 @@ Camera:
|
||||
m_GameObject: {fileID: 958699927}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_ClearFlags: 3
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
@@ -1122,7 +1122,7 @@ Camera:
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_Bits: 32
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
@@ -1604,7 +1604,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &1223089884
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -2094,7 +2094,7 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 0.17254902, g: 0.18431373, b: 0.2, a: 1}
|
||||
m_Color: {r: 0.13314347, g: 0.13314347, b: 0.1509434, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
@@ -2203,7 +2203,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!224 &1813956224
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -993,6 +993,10 @@ PrefabInstance:
|
||||
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_CallState
|
||||
value: 2
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8076035533974620946, guid: a973691757099224ca132b32daabf67c, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: RdyBtnText
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: a973691757099224ca132b32daabf67c, type: 3}
|
||||
--- !u!224 &594583494 stripped
|
||||
@@ -1000,6 +1004,17 @@ RectTransform:
|
||||
m_CorrespondingSourceObject: {fileID: 2454942472495841689, guid: a973691757099224ca132b32daabf67c, type: 3}
|
||||
m_PrefabInstance: {fileID: 594583493}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!114 &594583495 stripped
|
||||
MonoBehaviour:
|
||||
m_CorrespondingSourceObject: {fileID: 1513820883277351791, guid: a973691757099224ca132b32daabf67c, type: 3}
|
||||
m_PrefabInstance: {fileID: 594583493}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &949082596
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1238,6 +1253,11 @@ CanvasRenderer:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1185775522}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &1197550804 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 759482234963316101, guid: a973691757099224ca132b32daabf67c, type: 3}
|
||||
m_PrefabInstance: {fileID: 594583493}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1 &1234182190
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -2330,6 +2350,14 @@ PrefabInstance:
|
||||
propertyPath: sceneId
|
||||
value: 2342159728
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7129514368576730103, guid: af2b86e6ca1c8404a857e6bfa4294f3c, type: 3}
|
||||
propertyPath: rdyButton
|
||||
value:
|
||||
objectReference: {fileID: 1197550804}
|
||||
- target: {fileID: 7129514368576730103, guid: af2b86e6ca1c8404a857e6bfa4294f3c, type: 3}
|
||||
propertyPath: rdyButtonText
|
||||
value:
|
||||
objectReference: {fileID: 594583495}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: af2b86e6ca1c8404a857e6bfa4294f3c, type: 3}
|
||||
--- !u!1001 &7946605864942981377
|
||||
|
||||
@@ -1,26 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using TMPro;
|
||||
|
||||
|
||||
/* TODO:
|
||||
* - Changing Lobby Title Objects causes bugs on client
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* The Lobby Class is used to give all LobbyPlayer an instance above them for managing purposes.
|
||||
* You could write this into a NetworkManager, but I thought it would be nicer in a seperate script.
|
||||
*/
|
||||
|
||||
public class Lobby : NetworkBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public List<LobbyPlayer> LobbyPlayers = new List<LobbyPlayer>();
|
||||
// Sync Vars
|
||||
[SyncVar] //A list of all connected player
|
||||
public List<LobbyPlayer> LobbyPlayers = new List<LobbyPlayer>(); // All player a register themselves when they join (LobbyPlayer.cs)
|
||||
|
||||
[SyncVar(hook = "ChangeTitle")]
|
||||
[SerializeField] private string lobbyTitle;
|
||||
[SerializeField] string lobbyTitle; // Title/Name of the Lobby; Can only be changed by the host, because of "AuthHost"
|
||||
|
||||
public bool AuthHost(LobbyPlayer player)
|
||||
[SyncVar]
|
||||
public bool allReady = false; // All players are ready?
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(LobbyPlayers.IndexOf(player) == 0)
|
||||
CheckLobbyPlayers(); // Checking the LobbyPlayer List
|
||||
allReady = CheckAllReady(); // Continous checking if all player are ready
|
||||
}
|
||||
|
||||
public void StartGame() // initializes the In-Game Scene and converts LobbyPlayers to GamePlayers
|
||||
{
|
||||
Debug.Log("START");
|
||||
/* https://youtu.be/HZIzGLe-2f4?t=586
|
||||
* Start Loading Panel
|
||||
* Destroy LobbyPlayer
|
||||
* Instatiate Player Objects and connect them to "conn"
|
||||
* Switch Scene
|
||||
*/
|
||||
}
|
||||
|
||||
#region LobbyPlayer Interaction (Public)
|
||||
/* Public (Where the LobbyPlayer interacts with) */
|
||||
public bool AuthHost(LobbyPlayer player) // Checks if player is the host
|
||||
{
|
||||
// In theory the host should always be the first connected player, which means he is index 0 in the LobbyPlayers-List
|
||||
if (LobbyPlayers.IndexOf(player) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetTitle(LobbyPlayer player, string text)
|
||||
public void SetTitle(LobbyPlayer player, string text) // the host can set the LobbyTitle
|
||||
{
|
||||
if (AuthHost(player))
|
||||
{
|
||||
@@ -28,13 +64,44 @@ public class Lobby : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterPlayer(LobbyPlayer player)
|
||||
public void RegisterPlayer(LobbyPlayer player) // Where a Player can register himself
|
||||
{
|
||||
LobbyPlayers.Add(player);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void ChangeTitle(string oldTitle, string newTitle)
|
||||
#region checks
|
||||
/* Checks */
|
||||
bool CheckAllReady() // Checks if all players are ready
|
||||
{
|
||||
// Check if all players are ready (if a player is not ready)
|
||||
foreach (LobbyPlayer player in LobbyPlayers)
|
||||
{
|
||||
if (!player.ready)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CheckLobbyPlayers() // Checks if all LobbyPlayers in the list are still connected (having a GameObject) -> Clears missing players
|
||||
{
|
||||
foreach(LobbyPlayer player in LobbyPlayers)
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
LobbyPlayers.Remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region hooks
|
||||
/* HOOKS */
|
||||
void ChangeTitle(string oldTitle, string newTitle) // Changes the Title Object
|
||||
{
|
||||
GameObject.Find("title").GetComponent<TextMeshProUGUI>().text = newTitle;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,74 +1,116 @@
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI; // For <Button>
|
||||
using Mirror;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/*
|
||||
* This class manages the LobbyPlayer, which is the player object while the player is connected only to the lobby
|
||||
* AND is not IN-GAME (just a text-based player)!
|
||||
* this LobbyPlayer will get converted into a Player/GamePlayer for in-game use.
|
||||
*/
|
||||
|
||||
public class LobbyPlayer : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private Button rdyBtn;
|
||||
[SerializeField] private TextMeshProUGUI usernameText;
|
||||
[SerializeField] private TextMeshProUGUI rdyText;
|
||||
// UI Objects
|
||||
[SerializeField] Button rdyBtn; // Button Object for listeners
|
||||
[SerializeField] TextMeshProUGUI rdyButtonText; // Seperatly getting the text, because it's safer instead of "rdy.Btn.getChild..."
|
||||
|
||||
[SerializeField] private Button team1Btn;
|
||||
[SerializeField] private Button team2Btn;
|
||||
[SerializeField] TextMeshProUGUI usernameText; // Username Text Object -> Where the Username of every LobbyPlayer will get displayed
|
||||
[SerializeField] TextMeshProUGUI rdyText; // Ready Text Object -> Where the Ready-State of every LobbyPlayer will get displayed
|
||||
|
||||
[SerializeField] Button team1Btn; // Join Team 1 Button
|
||||
[SerializeField] Button team2Btn; // Join Team 2 Button
|
||||
|
||||
// Sync vars
|
||||
[SyncVar(hook = "DisplayPlayerName")]
|
||||
[SerializeField] public string username;
|
||||
|
||||
[SyncVar(hook = "ChangeReadyState")]
|
||||
[SerializeField] bool ready = false;
|
||||
public bool ready = false; // is the LobbyPlayer ready?
|
||||
|
||||
[SyncVar(hook = "ChangeDisplayTeam")]
|
||||
[SerializeField] int teamId = 0;
|
||||
[SerializeField] int teamId = 0; // which team did the player choose?
|
||||
|
||||
// Vars
|
||||
Lobby lobby;
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
lobby = GameObject.Find("LobbyManager").GetComponent<Lobby>();
|
||||
lobby.RegisterPlayer(this);
|
||||
lobby = GameObject.Find("LobbyManager").GetComponent<Lobby>(); // Get the Lobby Object in Scene
|
||||
lobby.RegisterPlayer(this); // Register the LobbyPlayer, so the lobby can store him in a list for future use
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
VariableSaver vs = GameObject.FindGameObjectWithTag("VariableSaver").GetComponent<VariableSaver>();
|
||||
/*
|
||||
* The Varaible Saver is used to store vars across different scenes and Player-Objects(LobbyPlayer/GamePlayer).
|
||||
* In this case it's used to get the values of the players BEFORE they joined the server.
|
||||
* -> username input field
|
||||
*/
|
||||
VariableSaver vs = GameObject.FindGameObjectWithTag("VariableSaver").GetComponent<VariableSaver>();
|
||||
|
||||
// Find GameObjects in Scene BY NAME
|
||||
rdyBtn = GameObject.Find("ReadyButton").GetComponent<Button>();
|
||||
rdyBtn.onClick.AddListener(CmdChangeReady);
|
||||
CmdSendName(vs.username);
|
||||
lobby.SetTitle(this, "Game Of\n" + username);
|
||||
rdyButtonText = GameObject.Find("RdyBtnText").GetComponent<TextMeshProUGUI>();
|
||||
team1Btn = GameObject.Find("Team1Btn").GetComponent<Button>();
|
||||
team2Btn = GameObject.Find("Team2Btn").GetComponent<Button>();
|
||||
|
||||
// Set Button Listeners
|
||||
rdyBtn.onClick.AddListener(CmdChangeReady);
|
||||
team1Btn.onClick.AddListener(delegate { SelectTeam(1); });
|
||||
team2Btn.onClick.AddListener(delegate { SelectTeam(2); });
|
||||
|
||||
// Send the username from the local variable saver to the synced var
|
||||
CmdSendName(vs.username);
|
||||
|
||||
// Set the lobby title -> only works if you're the host
|
||||
lobby.SetTitle(this, "Game Of\n" + username);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
public void CmdSendName(string playerName)
|
||||
void Update()
|
||||
{
|
||||
username = playerName;
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
/*
|
||||
* Update the "Ready-Button":
|
||||
* Change the text based on host or client / ready or not ready.
|
||||
* Adds and removes Start Listener to the hosts button
|
||||
*/
|
||||
|
||||
rdyBtn.onClick.RemoveListener(CmdStartGame); // Clear listener
|
||||
if (lobby.AuthHost(this) && lobby.allReady) // If all players are ready and your the host
|
||||
{
|
||||
rdyBtn.onClick.AddListener(CmdStartGame);
|
||||
rdyButtonText.SetText("Start");
|
||||
}
|
||||
else // You are not the host OR not all Players are ready
|
||||
{
|
||||
if (ready) // You are already ready
|
||||
{
|
||||
rdyButtonText.SetText("Un-Ready");
|
||||
}
|
||||
else // You are not ready
|
||||
{
|
||||
rdyButtonText.SetText("Ready");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
public void CmdChangeReady()
|
||||
#region hooks
|
||||
/* HOOKS */
|
||||
public void DisplayPlayerName(string oldName, string newName) // Changes the text value of the Player-Username-GameObject
|
||||
{
|
||||
ready = !ready;
|
||||
Debug.Log("Player changed name from " + oldName + " to " + newName); // Just for debug -> No future use
|
||||
usernameText.text = newName; // sets the new text in the gameobject
|
||||
}
|
||||
|
||||
[Command]
|
||||
public void SelectTeam(int _teamId)
|
||||
{
|
||||
teamId = _teamId;
|
||||
}
|
||||
public void DisplayPlayerName(string oldName, string newName)
|
||||
{
|
||||
Debug.Log("Player changed name from " + oldName + " to " + newName);
|
||||
usernameText.text = newName;
|
||||
}
|
||||
|
||||
public void ChangeReadyState(bool oldState, bool newState)
|
||||
public void ChangeReadyState(bool oldState, bool newState) // Changes the Ready-Text-Object of the player
|
||||
{
|
||||
// sets the new text based on the ready state of the player
|
||||
if (newState)
|
||||
{
|
||||
rdyText.text = "Ready";
|
||||
@@ -77,17 +119,49 @@ public class LobbyPlayer : NetworkBehaviour
|
||||
{
|
||||
rdyText.text = "Not Ready";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ChangeDisplayTeam(int oldTeamId, int newTeamId)
|
||||
|
||||
public void ChangeDisplayTeam(int oldTeamId, int newTeamId) // moves the player into the correct team-list
|
||||
{
|
||||
if(newTeamId == 1)
|
||||
// moves the player based on which team he has choosen
|
||||
if (newTeamId == 1)
|
||||
{
|
||||
gameObject.transform.parent = GameObject.FindGameObjectWithTag("Team1List").transform;
|
||||
}else if(newTeamId == 2)
|
||||
}
|
||||
else if (newTeamId == 2)
|
||||
{
|
||||
gameObject.transform.parent = GameObject.FindGameObjectWithTag("Team2List").transform;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region commands
|
||||
/* COMMANDS */
|
||||
[Command]
|
||||
void CmdStartGame()
|
||||
{
|
||||
if (lobby.AuthHost(this))
|
||||
{
|
||||
lobby.StartGame();
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSendName(string playerName) //Send/Set the username from local to the synced var
|
||||
{
|
||||
username = playerName;
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdChangeReady() // Updates the Ready-State of the Player (Synced Var)
|
||||
{
|
||||
ready = !ready;
|
||||
}
|
||||
|
||||
[Command]
|
||||
void SelectTeam(int _teamId) // Updates the team of the Player (Synced Var)
|
||||
{
|
||||
teamId = _teamId;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c84dd6fea7b1a564dac024e85dee0f66
|
||||
guid: 8200a488f55a39a46852e1266a825379
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
18
Assets/Scripts/Lobby/LobbyStartGame.cs
Normal file
18
Assets/Scripts/Lobby/LobbyStartGame.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ReadyUp : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Lobby/LobbyStartGame.cs.meta
Normal file
11
Assets/Scripts/Lobby/LobbyStartGame.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 435efa23db9058e4ba98afefb0f5f72e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 887196b8fb0b9eb4d9672b1ca0861e34
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user