This commit is contained in:
2026-03-19 06:31:08 +01:00
parent 2804acb9fb
commit 8735498b8f
97 changed files with 63618 additions and 34 deletions

View File

@@ -0,0 +1,16 @@
using UnityEngine;
public class Checkpoint : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 83324a7ce5cc7e64a9ff596a58bf010b

View File

@@ -43,6 +43,9 @@ public class Player : MonoBehaviour
[Tooltip("Layers considered as ground")]
public LayerMask GroundLayer = 1;
[Tooltip("Layers considered as death zone")]
public LayerMask DeathLayer = 0;
[Header("Forces")]
[Tooltip("Decay rate of extra forces (m/s²)")]
@@ -83,11 +86,26 @@ public class Player : MonoBehaviour
public Vector3 HorizontalVelocity => new Vector3(Velocity.x, 0, Velocity.z);
}
[System.Serializable]
public class HealthContainer
{
[Tooltip("Maximum health points")]
public int MaxHealth = 3;
[Tooltip("Current health points")]
public int CurrentHealth;
[Tooltip("Checkpoint for respawn")]
public Checkpoint Checkpoint;
}
[SerializeField] private Settings _settings;
[SerializeField] private References _references;
[SerializeField] private StateContainer _state;
[SerializeField] private HealthContainer _health;
public StateContainer State => _state;
public HealthContainer Health => _health;
#region Private Fields
private InputAction _moveAction;
@@ -152,6 +170,14 @@ public class Player : MonoBehaviour
#endregion
#region Unity Lifecycle
void OnControllerColliderHit(ControllerColliderHit hit)
{
if ((_settings.DeathLayer & (1 << hit.gameObject.layer)) != 0)
{
Eliminate();
}
}
void Awake()
{
if (Instance != null && Instance != this)
@@ -194,6 +220,7 @@ public class Player : MonoBehaviour
void Update()
{
if (_state.IsPaused) return;
if (!_references.Controller.enabled) return;
float deltaTime = Time.deltaTime;
@@ -232,6 +259,29 @@ public class Player : MonoBehaviour
#endregion
#region Public Methods
/// <summary>
/// Teleport player to position.
/// </summary>
public void Teleport(Vector3 position)
{
_references.Controller.enabled = false;
_state.Velocity = _impulseForce = _persistentForce = _platformVelocity = Vector3.zero;
_state.Ground = null;
transform.position = position;
_references.Controller.enabled = true;
}
/// <summary>
/// Sets the pause state of the player.
/// </summary>
public void Pause(bool paused)
{
_state.IsPaused = paused;
}
/// <summary>
/// Stuns for a specified duration (0 = infinite).
/// </summary>
@@ -240,8 +290,11 @@ public class Player : MonoBehaviour
if (_state.CurrentState == PlayerState.Eliminated)
return;
_references.Controller.enabled = false;
_state.Velocity = _impulseForce = _persistentForce = _platformVelocity = Vector3.zero;
_state.Ground = null;
_state.CurrentState = PlayerState.Stunned;
_state.Velocity = Vector3.zero;
if (duration > 0)
Invoke(nameof(RecoverFromStun), duration);
@@ -261,17 +314,35 @@ public class Player : MonoBehaviour
/// </summary>
public void Eliminate()
{
_state.CurrentState = PlayerState.Eliminated;
_state.Velocity = Vector3.zero;
_references.Controller.enabled = false;
_state.Velocity = _impulseForce = _persistentForce = _platformVelocity = Vector3.zero;
_state.Ground = null;
_state.CurrentState = PlayerState.Eliminated;
}
/// <summary>
/// Sets the pause state of the player.
/// Set the player loser.
/// </summary>
public void Pause(bool paused)
public void Loose()
{
_state.IsPaused = paused;
_references.Controller.enabled = false;
_state.Velocity = _impulseForce = _persistentForce = _platformVelocity = Vector3.zero;
_state.Ground = null;
_state.CurrentState = PlayerState.Loser;
}
/// <summary>
/// Set the player winner.
/// </summary>
public void Win()
{
_references.Controller.enabled = false;
_state.Velocity = _impulseForce = _persistentForce = _platformVelocity = Vector3.zero;
_state.Ground = null;
_state.CurrentState = PlayerState.Winner;
}
#endregion
@@ -432,7 +503,7 @@ public class Player : MonoBehaviour
impulseForce.y = _impulseForce.y;
_impulseForce = impulseForce;
// Decay inherited platform velocity reset when back on ground
// Decay inherited platform velocity: reset when back on ground
if (_state.IsGrounded)
{
_platformVelocity = Vector3.zero;

View File

@@ -6,6 +6,8 @@ public class PlayerVisual : MonoBehaviour
[System.Serializable]
private class Customization
{
public int HeadID;
public int BodyID;
[ColorUsage(false, true)] public Color[] Colors;
}
@@ -16,6 +18,8 @@ public class PlayerVisual : MonoBehaviour
public Animator Anim;
public Renderer[] Renderers;
public Material[] Materials;
public GameObject[] HeadAccessories;
public GameObject[] BodyAccessories;
}
[System.Serializable]
@@ -52,6 +56,13 @@ public class PlayerVisual : MonoBehaviour
{
float hueShift = Random.Range(0f, 360f);
// Accessories
_customization.HeadID = Random.Range(0, _references.HeadAccessories.Length + 1);
_customization.BodyID = Random.Range(0, _references.BodyAccessories.Length + 1);
// Colors
_customization.Colors = new Color[_references.Materials.Length];
for (int i = 0; i < _customization.Colors.Length; i++)
@@ -72,6 +83,16 @@ public class PlayerVisual : MonoBehaviour
private void SetCustom()
{
// Accessories
for (int i = 0; i < _references.HeadAccessories.Length; i++)
_references.HeadAccessories[i].SetActive(i == _customization.HeadID);
for (int i = 0; i < _references.BodyAccessories.Length; i++)
_references.BodyAccessories[i].SetActive(i == _customization.BodyID);
// Colors
foreach (Renderer rend in _references.Renderers)
{
foreach (Material mat in rend.materials)