Added base Round Logic and base map with characters

This commit is contained in:
2026-06-19 17:55:30 +03:00
parent 86d59db726
commit f5c79c7241
117 changed files with 14744 additions and 128 deletions
+5 -17
View File
@@ -12,7 +12,7 @@ GameObject:
- component: {fileID: 5879760844024625276}
- component: {fileID: 4435106788601278084}
- component: {fileID: 6510610849707753597}
- component: {fileID: 8045646663011112701}
- component: {fileID: -7388457339229672161}
m_Layer: 0
m_Name: HitVFX
m_TagString: Untagged
@@ -105,11 +105,11 @@ BoxCollider:
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
m_Enabled: 0
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &8045646663011112701
--- !u!114 &-7388457339229672161
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@@ -118,19 +118,7 @@ MonoBehaviour:
m_GameObject: {fileID: 2245960613504829429}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Script: {fileID: 11500000, guid: 1c955a16de27b5240996f015ca5c3b37, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 3810363958
InScenePlacedSourceGlobalObjectIdHash: 0
DeferredDespawnTick: 0
Ownership: 1
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1
ActiveSceneSynchronization: 0
SceneMigrationSynchronization: 0
SpawnWithObservers: 1
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
SyncOwnerTransformWhenParented: 1
AllowOwnerToParent: 0
destroyDelay: 1
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,18 @@
using UnityEngine;
using Unity.Netcode;
public class PitZone : NetworkBehaviour
{
private void OnTriggerEnter(Collider _other)
{
if (!IsServer) return;
PlayerHealth _playerHealth = _other.GetComponent<PlayerHealth>();
if (_playerHealth == null) return;
if(!RoundManager.Current.IsRoundActive) return;
RoundManager.Current.OnPlayerFellIntoPit(_playerHealth.OwnerClientId);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7fc2240aa8f9545428450e441a6c85eb
@@ -0,0 +1,176 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5944090919160834262
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8402122196850195783}
- component: {fileID: 1861476033851908899}
- component: {fileID: 4410707825217940865}
- component: {fileID: 6418970462643556314}
- component: {fileID: 8891301244357959447}
- component: {fileID: 6559213490887209871}
- component: {fileID: 2921838207524867903}
m_Layer: 0
m_Name: PitZone
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8402122196850195783
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5944090919160834262}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -53.58, y: -1.08, z: -0.1466}
m_LocalScale: {x: 6.4368, y: 6.952, z: 16.396576}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &1861476033851908899
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5944090919160834262}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &4410707825217940865
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5944090919160834262}
m_Enabled: 0
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!65 &6418970462643556314
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5944090919160834262}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &8891301244357959447
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5944090919160834262}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0de9c2653c954307856264ec248eab4d, type: 3}
m_Name:
m_EditorClassIdentifier:
drawSolid: 1
drawWire: 1
solidColor: {r: 0, g: 1, b: 0, a: 0.15}
wireColor: {r: 0, g: 1, b: 0, a: 1}
wireSegments: 24
maxMeshTriangles: 0
capsuleArcSegments: 8
meshBox: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
meshSphere: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
meshCylinder: {fileID: 4300000, guid: 3554d6a17caef8148b1220e9e2e79454, type: 2}
upperHalfSphere: {fileID: 4300000, guid: ea110afe4078082468955a8ec59d1ee0, type: 2}
lowerHalfSphere: {fileID: 4300000, guid: 2150e3d3605f3f54087ca225c7af31aa, type: 2}
coloredShader: {fileID: 4800000, guid: 38859b428448107418ad51fa96d642e7, type: 3}
--- !u!114 &6559213490887209871
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5944090919160834262}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 2885340176
InScenePlacedSourceGlobalObjectIdHash: 0
DeferredDespawnTick: 0
Ownership: 1
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1
ActiveSceneSynchronization: 0
SceneMigrationSynchronization: 0
SpawnWithObservers: 1
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
SyncOwnerTransformWhenParented: 1
AllowOwnerToParent: 0
--- !u!114 &2921838207524867903
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5944090919160834262}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7fc2240aa8f9545428450e441a6c85eb, type: 3}
m_Name:
m_EditorClassIdentifier:
ShowTopMostFoldoutHeaderGroup: 1
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8c239db36c826a54bb3f30f29bda194b
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,13 +1,15 @@
using Unity.Netcode;
using UnityEngine;
using TMPro;
using Unity.Collections;
public class PlayerController : NetworkBehaviour
{
[SerializeField] private float moveSpeed = 5f;
[SerializeField] private Camera playerCamera;
[SerializeField] private Camera playerHandCamera;
[SerializeField] private GameObject tpvHands;
[SerializeField] private GameObject fpvHands;
[SerializeField] private float mouseSensitivity = 2f;
[SerializeField] private Transform cameraRoot;
@@ -19,7 +21,10 @@ public class PlayerController : NetworkBehaviour
if (playerCamera != null)
{
playerCamera.enabled = IsOwner;
playerHandCamera.enabled = IsOwner;
playerCamera.GetComponent<AudioListener>().enabled = IsOwner;
fpvHands.SetActive(IsOwner);
tpvHands.SetActive(!IsOwner);
}
if (IsOwner)
@@ -28,19 +33,16 @@ public class PlayerController : NetworkBehaviour
Cursor.visible = false;
}
if (IsOwner)
Color playerColor = IsOwner ? Color.blue : Color.red;
foreach (MeshRenderer meshRenderer in GetComponentsInChildren<MeshRenderer>())
{
GetComponent<Renderer>().material.color = Color.blue;
}
else
{
GetComponent<Renderer>().material.color = Color.red;
meshRenderer.material.color = playerColor;
}
if (IsOwner)
{
transform.position = new Vector3(Random.Range(-10f, 10f), 1f, Random.Range(-10f, 10f));
}
// if (IsOwner)
// {
// transform.position = new Vector3(Random.Range(-10f, 10f), 1f, Random.Range(-10f, 10f));
// }
}
public void Update()
@@ -10,9 +10,11 @@ public class PlayerHealth : NetworkBehaviour
public NetworkVariable<int> currentHealth = new NetworkVariable<int>(
100,
NetworkVariableReadPermission.Everyone,
NetworkVariableWritePermission.Owner
NetworkVariableWritePermission.Server
);
public NetworkVariable<bool> isDead = new NetworkVariable<bool>(false);
public override void OnNetworkSpawn()
{
currentHealth.OnValueChanged += OnHealthChanged;
@@ -20,8 +22,10 @@ public class PlayerHealth : NetworkBehaviour
if (IsServer)
{
currentHealth.Value = maxHealth;
healthText.text = $"Health: {maxHealth}";
RoundManager.Current?.RegisterPlayer(OwnerClientId);
}
healthText.text = $"Health: {maxHealth}";
}
private void OnHealthChanged(int _previousValue, int _newValue)
@@ -34,8 +38,11 @@ public class PlayerHealth : NetworkBehaviour
public void TakeDamage(int _damageAmount)
{
if (!IsServer) return;
if(isDead.Value) return;
currentHealth.Value -= _damageAmount;
if (RoundManager.Current == null || !RoundManager.Current.IsRoundActive) return;
currentHealth.Value = Mathf.Max(0, currentHealth.Value - _damageAmount);
if (currentHealth.Value <= 0)
{
@@ -45,18 +52,50 @@ public class PlayerHealth : NetworkBehaviour
private void Die()
{
if(!IsServer) return;
isDead.Value = true;
OnDiedClientRpc();
// RoundManager.Current?.OnPlayerDied(this);
}
[ClientRpc]
private void OnDiedClientRpc()
{
Debug.Log($"Player {OwnerClientId} died");
gameObject.SetActive(false);
SetPhysicsAndVisualsActive(false);
}
public override void OnNetworkDespawn()
{
currentHealth.OnValueChanged -= OnHealthChanged;
}
public void Respawn(Vector3 _spawnPosition)
{
if(!IsServer) return;
isDead.Value = false;
currentHealth.Value = maxHealth;
RespawnClientRpc(_spawnPosition);
}
[ClientRpc]
private void RespawnClientRpc(Vector3 _spawnPosition)
{
SetPhysicsAndVisualsActive(true);
transform.position = _spawnPosition;
}
private void SetPhysicsAndVisualsActive(bool _isActive)
{
foreach (Collider collider in GetComponentsInChildren<Collider>())
collider.enabled = _isActive;
foreach (MeshRenderer meshRenderer in GetComponentsInChildren<MeshRenderer>())
meshRenderer.enabled = _isActive;
GetComponent<Rigidbody>().isKinematic = !_isActive;
}
}
@@ -9,9 +9,25 @@ public class PlayerShoot : NetworkBehaviour
[SerializeField] GameObject hitEffectPrefab;
private PlayerHealth playerHealth;
public override void OnNetworkSpawn()
{
if (IsOwner)
{
playerHealth = GetComponent<PlayerHealth>();
if (playerHealth == null)
{
Debug.LogError("PlayerHealth component not found on player");
}
}
}
void Update()
{
if (!IsOwner) return;
if(playerHealth == null || playerHealth.isDead.Value) return;
if (Input.GetMouseButtonDown(0))
{
@@ -44,6 +60,6 @@ public class PlayerShoot : NetworkBehaviour
private void SpawnHitEffectClientRpc(Vector3 _hitPosition)
{
Debug.Log($"Spawning hit effect at {_hitPosition}");
NetworkBehaviour.Instantiate(hitEffectPrefab, _hitPosition, Quaternion.identity);
Instantiate(hitEffectPrefab, _hitPosition, Quaternion.identity);
}
}
@@ -1,10 +1,17 @@
using UnityEngine;
using Unity.Netcode;
using System.Collections;
public class PlayerUIController : NetworkBehaviour
{
public override void OnNetworkSpawn()
[SerializeField] private Canvas hudCanvas;
public IEnumerator Start()
{
GetComponent<Canvas>().enabled = IsOwner;
NetworkObject _netObj = GetComponentInParent<NetworkObject>();
yield return new WaitUntil(() => _netObj != null);
hudCanvas.enabled = _netObj.IsOwner;
}
}
@@ -0,0 +1,173 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
public struct PlayerScore : INetworkSerializable, System.IEquatable<PlayerScore>
{
public ulong ClientId;
public int Score;
public bool Equals(PlayerScore _other)
{
return ClientId == _other.ClientId && Score == _other.Score;
}
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
serializer.SerializeValue(ref ClientId);
serializer.SerializeValue(ref Score);
}
}
public class RoundManager : NetworkBehaviour
{
public static RoundManager Current { get; private set; }
[SerializeField] private float roundStartDelay = 3f;
[SerializeField] private Transform[] spawnPoints;
private NetworkVariable<int> currentRound = new NetworkVariable<int>(0);
private NetworkVariable<bool> isRoundActive = new NetworkVariable<bool>(false);
private List<PlayerHealth> alivePlayers = new List<PlayerHealth>();
private NetworkList<PlayerScore> playerScores;
void Awake()
{
Current = this;
playerScores = new NetworkList<PlayerScore>();
}
public override void OnNetworkSpawn()
{
currentRound.OnValueChanged += OnRoundChanged;
isRoundActive.OnValueChanged += OnRoundStateChanged;
if (IsServer)
{
StartCoroutine(StartRoundWithDelay());
}
}
public void OnPlayerFellIntoPit(ulong _winnerClientId)
{
if (!IsServer) return;
if(!isRoundActive.Value) return;
for (int _i = 0; _i < playerScores.Count; _i++)
{
playerScores[_i] = new PlayerScore
{
ClientId = _winnerClientId,
Score = playerScores[_i].Score + 1
};
break;
}
StartCoroutine(EndRound(_winnerClientId));
}
public void OnPlayerDied(PlayerHealth _playerHealth)
{
// if (!IsServer) return;
// alivePlayers.Remove(_playerHealth);
// if (alivePlayers.Count <= 1)
// {
// StartCoroutine(EndRound());
// }
}
public void RegisterPlayer(ulong _clientId)
{
if (!IsServer) return;
foreach (var _s in playerScores)
if (_s.ClientId == _clientId) return;
playerScores.Add(new PlayerScore { ClientId = _clientId, Score = 0 });
}
private IEnumerator EndRound(ulong _winnerClientId)
{
isRoundActive.Value = false;
string _winner = _winnerClientId != 0 ? $"Player {_winnerClientId} wins!" : "No winner";
RoundEndedClientRPC(_winner);
yield return new WaitForSeconds(roundStartDelay);
currentRound.Value++;
StartCoroutine(StartRoundWithDelay());
}
private void RespawnAllPlayers()
{
if (!IsServer) return;
var _allPlayers = FindObjectsByType<PlayerHealth>(FindObjectsSortMode.None);
alivePlayers.Clear();
for (int _q = 0; _q < _allPlayers.Length; _q++)
{
Vector3 _spawnPosition = spawnPoints[_q % spawnPoints.Length].position;
_allPlayers[_q].Respawn(_spawnPosition);
alivePlayers.Add(_allPlayers[_q]);
}
}
private IEnumerator StartRoundWithDelay()
{
yield return new WaitForSeconds(1f);
yield return new WaitUntil(() =>
FindObjectsByType<PlayerHealth>(FindObjectsSortMode.None).Length >= 2);
RespawnAllPlayers();
isRoundActive.Value = true;
RoundStartedClientRPC(currentRound.Value);
}
[ClientRpc]
private void RoundStartedClientRPC(int _round)
{
Debug.Log($"Round {_round} started");
}
[ClientRpc]
private void RoundEndedClientRPC(string _winnerText)
{
Debug.Log($"Round ended: {_winnerText}");
}
public bool IsRoundActive => isRoundActive.Value;
public override void OnNetworkDespawn()
{
if (IsServer && Current == this)
Current = null;
currentRound.OnValueChanged -= OnRoundChanged;
isRoundActive.OnValueChanged -= OnRoundStateChanged;
}
private void OnRoundChanged(int _previousValue, int _newValue)
{
}
private void OnRoundStateChanged(bool _previousValue, bool _newValue)
{
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c49d068c5999505438184c5104013c89
@@ -0,0 +1,11 @@
using UnityEngine;
public class VFXDestroyer : MonoBehaviour
{
[SerializeField] float destroyDelay = 1f;
void Start()
{
Destroy(gameObject, destroyDelay);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1c955a16de27b5240996f015ca5c3b37