Merge branch 'main' into weapons-without-scriptableobjects

This commit is contained in:
Noah4ever
2021-11-05 14:03:16 +01:00
42 changed files with 5159 additions and 728 deletions

View File

@@ -13,10 +13,9 @@ public class GameMaster : MonoBehaviour
{
[Header("GameMaster")]
[SerializeField] private List<Player> Players = new List<Player>();
private void Start()
{
[SerializeField] private int countOfRounds = 10;
}
public GameObject localPlayer;
private void Update()
{
@@ -33,4 +32,7 @@ public class GameMaster : MonoBehaviour
Cursor.visible = false;
}
}
}

View File

@@ -0,0 +1,28 @@
using Mirror;
using UnityEngine;
public class JoinLeaveManager : MonoBehaviour
{
private NetworkManager networkManager;
private void Start()
{
networkManager = GetComponent<NetworkManager>();
}
public void Join(string ip, string username)
{
Debug.Log("[JoinLeaveManager] Trying to join server: " + ip + " as " + username);
networkManager.StartClient();
networkManager.networkAddress = ip;
Debug.Log("[JoinLeaveManager] " + username + " joined the server: " + ip);
}
public void Host()
{
networkManager.StartHost();
}
}

View File

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

View File

@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class Manager : NetworkManager
{
public override void OnClientConnect(NetworkConnection conn)
{
base.OnClientConnect(conn);
//Debug.Log(conn.identity.gameObject.GetComponent<Player>().username);
//conn.identity.gameObject.GetComponent<Player>().username = "Test";
}
}

View File

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

View File

@@ -0,0 +1,78 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class Headbob : NetworkBehaviour
{
[SerializeField] private PlayerController playerController;
[SerializeField] private float posCheckDistance = 0.01f;
[SerializeField] private float checkDist = 0.0f;
private float currentDist = 0;
[Header("Step Settings")]
[SerializeField] private float stepAmplitudeWalking;
[SerializeField] private float stepAmplitudeSprinting;
[SerializeField] [Range(0.01f, 10.0f)] private float stepFrequency;
[SerializeField] private Transform Neck;
private Vector3 lastPos;
private Vector3 newPos;
private float oldDist = 0;
private float lerpVal = 0;
private void Start()
{
lastPos = this.transform.position;
}
private void Update()
{
float amplitude;
if (playerController.isGrounded)
{
lerpVal = 0;
float dist = Vector3.Distance(lastPos, this.transform.position);
if (playerController.isSprinting)
amplitude = stepAmplitudeSprinting;
else
amplitude = stepAmplitudeWalking;
if (dist > posCheckDistance)
{
currentDist += dist;
lastPos = this.transform.position;
}
else
{
checkDist = currentDist + dist;
}
newPos = new Vector3(getSin(amplitude / 2, stepFrequency, checkDist), getSin(amplitude, stepFrequency, checkDist), 0);
Neck.localPosition = newPos;
}
else
{
Neck.localPosition = Vector3.zero;
if (false) {
Neck.localPosition = Vector3.Lerp(newPos, Vector3.zero, lerpVal);
if (lerpVal < 1)
{
lerpVal = lerpVal + 0.01f;
}
else
{
Neck.position = Vector3.zero;
}
}
}
}
private float getSin(float multiplier, float devisor,float x)
{
return multiplier * Mathf.Sin((x/3.14f) * 10 * devisor);
}
}

View File

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

View File

@@ -5,23 +5,33 @@ using Mirror;
public class Player : NetworkBehaviour
{
public bool isAlive;
public bool isAlive = true;
public Team team;
[SerializeField] private const int defaultHp = 100;
public ulong clientId;
[SyncVar(hook = nameof(SetName))]
[SyncVar(hook = nameof(SetName))]
public string username;
[SerializeField] GameObject usernameTextObj;
private int health;
[SerializeField] [SyncVar]public int health = 100;
private int kills;
private int deaths;
private void Start()
{
if (isServer)
{
health = defaultHp;
}
}
public override void OnStartLocalPlayer()
{
base.OnStartClient();
}
public void SetName(string oldName, string newName)
@@ -56,8 +66,11 @@ public class Player : NetworkBehaviour
}
public void RemoveHealth(int value)
{
if (isAlive)
{
Debug.Log("yeet" + value);
health -= value;
if (health <= 0)
{

View File

@@ -11,6 +11,8 @@ public class PlayerController : NetworkBehaviour
[Header("Movement")]
[SerializeField] private float walkSpeed = 6.0f;
[SerializeField] private float sprintSpeed = 10.0f;
[SerializeField][Range(0.0f, 0.5f)] private float moveSmoothTime = 0.001f;
[SerializeField] float gravity = -10.0f;
[SerializeField] private float jumpHeight;
@@ -26,6 +28,8 @@ public class PlayerController : NetworkBehaviour
[SerializeField] private float moveGroundAngle;
public bool isGrounded;
public bool isSprinting;
private float movementSpeed;
private float velocityY = 0.0f;
private CharacterController controller;
@@ -48,7 +52,9 @@ public class PlayerController : NetworkBehaviour
Grounded();
CheckGoundAngle();
UpdateMovement();
}
}
private void Grounded()
{
@@ -81,9 +87,9 @@ public class PlayerController : NetworkBehaviour
}
groundAngle = Vector3.Angle(hit.normal,transform.up);
//Debug.Log(moveGroundAngle);
}
}
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
@@ -92,8 +98,29 @@ public class PlayerController : NetworkBehaviour
private void UpdateMovement()
{
if (Input.GetAxisRaw("Sprint") > 0 && isGrounded)
{
Debug.Log("Sprint");
movementSpeed = sprintSpeed;
isSprinting = true;
}
else
{
movementSpeed = walkSpeed;
isSprinting = false;
}
//Grounded
velocityY += gravity * Time.deltaTime;
if (velocityY < 0)
{
velocityY += gravity * Time.deltaTime;
}
else
{
velocityY += gravity * 1.0f * Time.deltaTime;
}
if (isGrounded && velocityY < 0)
velocityY = 0.0f;
@@ -101,7 +128,7 @@ public class PlayerController : NetworkBehaviour
if (Input.GetButtonDown("Jump") && isGrounded)
{
//Debug.Log("Jump");
velocityY += Mathf.Sqrt(jumpHeight * 4f);
velocityY += Mathf.Sqrt(jumpHeight * -2f * gravity);
}
inputDirection = new Vector3(Input.GetAxisRaw("Horizontal"),0, Input.GetAxisRaw("Vertical")); //Get Inputs
@@ -117,8 +144,7 @@ public class PlayerController : NetworkBehaviour
currentDir = moveDirection;
}
currentDir = currentDir + new Vector3(0, velocityY, 0);
velocity = currentDir * walkSpeed;
velocity = currentDir * movementSpeed + new Vector3(0, velocityY, 0);
controller.Move(velocity * Time.deltaTime);

View File

@@ -14,7 +14,7 @@ public class PlayerMouseLook : NetworkBehaviour
[SerializeField] private float neckStartAngle = 0f;
[SerializeField] private float minCameraAngle = -90f;
[SerializeField] private float neckLength = 0.2f;
private float neckLength = 0.2f;
[SerializeField] [Range(0.0f, 0.5f)] private float mouseSmoothTime = 0.001f;
[SerializeField] private bool lockCursor = true;
@@ -36,6 +36,7 @@ public class PlayerMouseLook : NetworkBehaviour
controller = GetComponent<CharacterController>();
playerCamera.gameObject.SetActive(true);
neckLength = Vector3.Distance(playerNeck.position,playerCamera.position);
if (lockCursor)
{

View File

@@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SaveData : MonoBehaviour
{
[SerializeField] PlayerData _PlayerData = new PlayerData();
private void Start()
{
gameObject.GetComponent<Button>().onClick.AddListener(SavePlayerToJson);
}
public void SavePlayerToJson()
{
string playerData = JsonUtility.ToJson(_PlayerData);
System.IO.File.WriteAllText(Application.persistentDataPath + "/PlayerData.json", playerData);
Debug.Log(Application.persistentDataPath);
}
}
[System.Serializable]
public class PlayerData
{
public string username;
}

View File

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

View File

@@ -11,6 +11,6 @@ public class HostBtnScript : MonoBehaviour
public void HostServer()
{
NetworkClient.ConnectHost();
GameObject.Find("GameManager").GetComponent<JoinLeaveManager>().Host();
}
}

View File

@@ -8,13 +8,18 @@ public class JoinBtnScript : MonoBehaviour
[SerializeField] private TMP_InputField inputIp;
[SerializeField] private TMP_InputField inputUsername;
private JoinLeaveManager joinLeaveManager;
private void Start()
{
gameObject.GetComponent<Button>().onClick.AddListener(JoinServer);
joinLeaveManager = GameObject.Find("GameManager").GetComponent<JoinLeaveManager>();
}
public void JoinServer()
{
NetworkClient.Connect(inputIp.text);
joinLeaveManager.Join(inputIp.text, inputUsername.text);
}
}