mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
CHANGED TO MIRROR
This commit is contained in:
@@ -3,8 +3,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using MLAPI;
|
||||
using MLAPI.Transports.UNET;
|
||||
using Mirror;
|
||||
|
||||
public class DebugCanvas : MonoBehaviour
|
||||
{
|
||||
@@ -37,22 +36,6 @@ public class DebugCanvas : MonoBehaviour
|
||||
{
|
||||
DebugTextGrounded.text = "isGrounded: " + Player.GetComponent<PlayerController>().isGrounded.ToString();
|
||||
|
||||
if (GameManager.GetComponent<NetworkManager>().IsHost)
|
||||
{
|
||||
DebugTextClientServer.text = "Host";
|
||||
DebugTextClientServer.text += "\n127.0.0.1";
|
||||
}
|
||||
else if(GameManager.GetComponent<NetworkManager>().IsClient)
|
||||
{
|
||||
DebugTextClientServer.text = "Client";
|
||||
DebugTextClientServer.text += "\n" + GameManager.GetComponent<UNetTransport>().ConnectAddress;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugTextClientServer.text = "Server";
|
||||
}
|
||||
|
||||
|
||||
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
|
||||
float fps = 1.0f / deltaTime;
|
||||
fpsText.text = Mathf.Ceil(fps).ToString() + "FPS";
|
||||
|
||||
@@ -3,27 +3,33 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
// Erstellung von Teams
|
||||
// Auflistung von den Spielern
|
||||
// Verwaltung der Spieler und Teams
|
||||
//
|
||||
|
||||
public class GameMaster : MonoBehaviour
|
||||
{
|
||||
[Header("GameMaster")]
|
||||
[SerializeField] private List<Team> teams = new List<Team>();
|
||||
[SerializeField] private List<Player> Players = new List<Player>();
|
||||
private void Start()
|
||||
{
|
||||
|
||||
CreateTeam("Orange");
|
||||
CreateTeam("Blue");
|
||||
|
||||
MLAPI.NetworkManager.Singleton.StartHost();
|
||||
}
|
||||
|
||||
private void CreateTeam(string name, int score = 0)
|
||||
private void Update()
|
||||
{
|
||||
Team team = new Team(name, score);
|
||||
teams.Add(team);
|
||||
if (Input.GetKeyDown(KeyCode.H))
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Confined;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.J))
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Team> GetTeams()
|
||||
{
|
||||
return teams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
public class Networking : NetworkManager
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f54db2e39d506634a9373c6d52305187
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
public class PlayerMaster : MonoBehaviour
|
||||
{
|
||||
[Header("PlayerMaster")]
|
||||
[SerializeField] private List<ServerPlayer> Players = new List<ServerPlayer>(); //Contains All Players which are currently connected/in-game
|
||||
//[SerializeField] private List<ServerPlayer> Players = new List<ServerPlayer>(); //Contains All Players which are currently connected/in-game
|
||||
|
||||
//JUST FOR DEBUG
|
||||
[SerializeField] private GameObject TestPlayer;
|
||||
@@ -21,7 +21,7 @@ public class PlayerMaster : MonoBehaviour
|
||||
{
|
||||
foreach(GameObject p in GameObject.FindGameObjectsWithTag("Player"))
|
||||
{
|
||||
Players.Add(new ServerPlayer(p));
|
||||
//Players.Add(new ServerPlayer(p));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class PlayerMaster : MonoBehaviour
|
||||
//Join
|
||||
public void OnPlayerJoin(GameObject player) //When a Player joins
|
||||
{
|
||||
foreach (ServerPlayer p in Players)
|
||||
/*foreach (ServerPlayer p in Players)
|
||||
{
|
||||
if (p.Player == player)
|
||||
{
|
||||
@@ -43,30 +43,30 @@ public class PlayerMaster : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
}
|
||||
Players.Add(new ServerPlayer(player));
|
||||
Players.Add(new ServerPlayer(player));*/
|
||||
}
|
||||
|
||||
//Leave
|
||||
public void OnPlayerLeave(GameObject player) //When a Player leaves
|
||||
{
|
||||
foreach (ServerPlayer p in Players)
|
||||
/*foreach (ServerPlayer p in Players)
|
||||
{
|
||||
if (p.Player == player)
|
||||
{
|
||||
Players.Remove(p);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public int SyncHealth(GameObject player)
|
||||
{
|
||||
foreach (ServerPlayer p in Players)
|
||||
/*foreach (ServerPlayer p in Players)
|
||||
{
|
||||
if (p.Player == player)
|
||||
{
|
||||
return p.GetHealth();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ServerPlayer
|
||||
{
|
||||
public GameObject Player;
|
||||
public bool isAlive;
|
||||
public Team team;
|
||||
private int health;
|
||||
private int kills;
|
||||
private int deaths;
|
||||
private const int defaultHp = 100;
|
||||
|
||||
public ServerPlayer(GameObject _Player, bool _isAlive = true, int _health = defaultHp, int _kills = 0, int _deaths = 0, Team _team = null)
|
||||
{
|
||||
Player = _Player;
|
||||
isAlive = _isAlive;
|
||||
health = _health;
|
||||
kills = _kills;
|
||||
deaths = _deaths;
|
||||
team = _team;
|
||||
}
|
||||
|
||||
public void Respawn()
|
||||
{
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
public void Die()
|
||||
{
|
||||
isAlive = false;
|
||||
AddDeaths(1);
|
||||
}
|
||||
|
||||
//Health
|
||||
public void AddHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health += value;
|
||||
}
|
||||
|
||||
}
|
||||
public void RemoveHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health -= value;
|
||||
if (health <= 0)
|
||||
{
|
||||
AddDeaths(1);
|
||||
health = 0;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void SetHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health = value;
|
||||
if (health <= 0)
|
||||
{
|
||||
AddDeaths(1);
|
||||
health = 0;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetHealth()
|
||||
{
|
||||
return health;
|
||||
}
|
||||
|
||||
//Kills
|
||||
public void AddKills(int value)
|
||||
{
|
||||
kills += value;
|
||||
}
|
||||
public void RemoveKills(int value)
|
||||
{
|
||||
kills -= value;
|
||||
}
|
||||
public void SetKills(int value)
|
||||
{
|
||||
kills = value;
|
||||
}
|
||||
|
||||
public int GetKills()
|
||||
{
|
||||
return kills;
|
||||
}
|
||||
|
||||
//Deaths
|
||||
public void AddDeaths(int value)
|
||||
{
|
||||
deaths += value;
|
||||
}
|
||||
public void RemoveDeaths(int value)
|
||||
{
|
||||
deaths -= value;
|
||||
}
|
||||
public void SetDeaths(int value)
|
||||
{
|
||||
deaths = value;
|
||||
}
|
||||
|
||||
public int GetDeaths()
|
||||
{
|
||||
return deaths;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2e457ad00c1a044a924a5bc00776df9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,38 +1,119 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
public class Player : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] int health;
|
||||
[SerializeField] float SyncIntervalSeconds = 5.0f;
|
||||
[SerializeField] GameObject GameManager;
|
||||
|
||||
public bool isAlive;
|
||||
public Team team;
|
||||
[SerializeField] private const int defaultHp = 100;
|
||||
|
||||
private PlayerMaster playerMaster;
|
||||
public ulong clientId;
|
||||
private string name;
|
||||
private int health;
|
||||
private int kills;
|
||||
private int deaths;
|
||||
|
||||
private void Start()
|
||||
|
||||
public void SetName(string newName)
|
||||
{
|
||||
GameManager = GameObject.Find("GameManager");
|
||||
playerMaster = GameManager.GetComponent<PlayerMaster>();
|
||||
|
||||
//InvokeRepeating("Sync", 3.0f, SyncIntervalSeconds);
|
||||
name = newName;
|
||||
}
|
||||
|
||||
|
||||
private void Sync()
|
||||
public string GetName()
|
||||
{
|
||||
Debug.Log("Sync");
|
||||
health = playerMaster.SyncHealth(gameObject);
|
||||
return name;
|
||||
}
|
||||
public void Respawn()
|
||||
{
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
public void SubstractHealth(int value)
|
||||
public void Die()
|
||||
{
|
||||
health -= value;
|
||||
isAlive = false;
|
||||
AddDeaths(1);
|
||||
}
|
||||
|
||||
//Health
|
||||
public void AddHealth(int value)
|
||||
{
|
||||
health += value;
|
||||
if (isAlive)
|
||||
{
|
||||
health += value;
|
||||
}
|
||||
|
||||
}
|
||||
public void RemoveHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health -= value;
|
||||
if (health <= 0)
|
||||
{
|
||||
AddDeaths(1);
|
||||
health = 0;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void SetHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health = value;
|
||||
if (health <= 0)
|
||||
{
|
||||
AddDeaths(1);
|
||||
health = 0;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetHealth()
|
||||
{
|
||||
return health;
|
||||
}
|
||||
|
||||
//Kills
|
||||
public void AddKills(int value)
|
||||
{
|
||||
kills += value;
|
||||
}
|
||||
public void RemoveKills(int value)
|
||||
{
|
||||
kills -= value;
|
||||
}
|
||||
public void SetKills(int value)
|
||||
{
|
||||
kills = value;
|
||||
}
|
||||
|
||||
public int GetKills()
|
||||
{
|
||||
return kills;
|
||||
}
|
||||
|
||||
//Deaths
|
||||
public void AddDeaths(int value)
|
||||
{
|
||||
deaths += value;
|
||||
}
|
||||
public void RemoveDeaths(int value)
|
||||
{
|
||||
deaths -= value;
|
||||
}
|
||||
public void SetDeaths(int value)
|
||||
{
|
||||
deaths = value;
|
||||
}
|
||||
|
||||
public int GetDeaths()
|
||||
{
|
||||
return deaths;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
using Mirror;
|
||||
|
||||
// https://youtu.be/PmIPqGqp8UY
|
||||
// https://youtu.be/n-KX8AeGK7E?t=997
|
||||
@@ -48,7 +48,7 @@ public class PlayerController : NetworkBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (IsLocalPlayer)
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
controller = GetComponent<CharacterController>();
|
||||
if (lockCursor)
|
||||
@@ -65,16 +65,11 @@ public class PlayerController : NetworkBehaviour
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (IsLocalPlayer)
|
||||
{
|
||||
UpdateMouseLook();
|
||||
Grounded();
|
||||
UpdateMovement();
|
||||
}
|
||||
else
|
||||
{
|
||||
playerCamera.gameObject.SetActive(false);
|
||||
}
|
||||
if (!isLocalPlayer) return;
|
||||
|
||||
UpdateMouseLook();
|
||||
Grounded();
|
||||
UpdateMovement();
|
||||
|
||||
}
|
||||
private void Grounded()
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
using MLAPI.NetworkVariable;
|
||||
using MLAPI.Transports;
|
||||
using MLAPI.Messaging;
|
||||
using TMPro;
|
||||
|
||||
public class PlayerNetworkingScript : NetworkBehaviour
|
||||
{
|
||||
public NetworkVariableInt dice = new NetworkVariableInt(new NetworkVariableSettings
|
||||
{
|
||||
WritePermission = NetworkVariablePermission.ServerOnly,
|
||||
ReadPermission = NetworkVariablePermission.Everyone
|
||||
});
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.J))
|
||||
{
|
||||
Debug.Log("J");
|
||||
NetworkManager.Singleton.StopHost();
|
||||
NetworkManager.Singleton.StartClient();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfd6cd3bbcb023440832d53f9f1f0041
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user