готово ко 2 кт
This commit is contained in:
1 parent
0f9a539460
commit
5bd4118b23
7 files changed
+796
-21
No files matched your search
@@ -67,6 +67,7 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Time.timeScale == 0f) return;
|
||||
HandleMouseLook();
|
||||
HandleCameraAndBobbing();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
@@ -20,20 +21,22 @@ namespace _Project.Scripts.PlayerUtils
|
||||
[Header("Визуал Сферы Зоны Вселения")]
|
||||
[Tooltip("Если true — сфера рисуется вокруг врага (показывая зону, куда надо войти). Если false — вокруг игрока.")]
|
||||
[SerializeField] private bool centerSphereOnTarget = true;
|
||||
[SerializeField] private Color zoneReadyColor = new Color(0.1f, 0.95f, 1f, 0.10f); // Враг в зоне (можно жать E)
|
||||
[SerializeField] private Color zoneOutOfRangeColor = new Color(1f, 0.35f, 0.35f, 0.06f); // Навёлся, но далеко
|
||||
[SerializeField] private Color zoneReadyColor = new Color(0.1f, 0.95f, 1f, 0.10f);
|
||||
[SerializeField] private Color zoneOutOfRangeColor = new Color(1f, 0.35f, 0.35f, 0.06f);
|
||||
|
||||
[Header("Замедление времени в форме Духа")]
|
||||
[SerializeField, Range(0.1f, 1f)] private float spiritTimeScale = 0.45f;
|
||||
|
||||
// Ивент окончательной смерти игрока (когда убили в форме Духа)
|
||||
public event Action OnPlayerDied;
|
||||
|
||||
public BodyProfile CurrentProfile { get; private set; }
|
||||
public bool IsInSpiritForm => CurrentProfile != null && CurrentProfile.bodyClass == BodyClass.Spirit;
|
||||
public bool IsDead { get; private set; }
|
||||
public float CurrentHealth { get; private set; }
|
||||
public float MaxHealth => CurrentProfile != null ? CurrentProfile.maxHealth : 25f;
|
||||
|
||||
// Враг, на которого наведён прицел (на любом расстоянии до maxAimLookDistance)
|
||||
public EnemyAI AimedEnemy { get; private set; }
|
||||
// Находится ли этот враг внутри сферы вселения (possessRange)
|
||||
public bool IsTargetInPossessZone { get; private set; }
|
||||
|
||||
public float PlayerTimeMultiplier =>
|
||||
@@ -43,11 +46,9 @@ namespace _Project.Scripts.PlayerUtils
|
||||
private bool _isTransitioning;
|
||||
private float _invulnerableTimer;
|
||||
|
||||
// Полупрозрачная сфера зоны вселения
|
||||
private GameObject _zoneSphere;
|
||||
private Renderer _zoneRenderer;
|
||||
private Material _zoneMaterial;
|
||||
private float _currentZoneAlpha;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -68,7 +69,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
_zoneSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
_zoneSphere.name = "PossessionZoneSphere";
|
||||
|
||||
// Убираем коллайдер, это чисто визуальная голограмма зоны
|
||||
var col = _zoneSphere.GetComponent<Collider>();
|
||||
if (col != null) Destroy(col);
|
||||
|
||||
@@ -76,7 +76,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
_zoneRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||
_zoneRenderer.receiveShadows = false;
|
||||
|
||||
// Используем прозрачный шейдер, который рисуется поверх и мягко подсвечивает площадь
|
||||
Shader shader = Shader.Find("Sprites/Default");
|
||||
_zoneMaterial = new Material(shader);
|
||||
_zoneMaterial.color = Color.clear;
|
||||
@@ -87,7 +86,9 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (IsDead) return;
|
||||
if (_invulnerableTimer > 0f) _invulnerableTimer -= Time.unscaledDeltaTime;
|
||||
|
||||
if (_isTransitioning)
|
||||
{
|
||||
if (_zoneSphere != null) _zoneSphere.SetActive(false);
|
||||
@@ -127,11 +128,9 @@ namespace _Project.Scripts.PlayerUtils
|
||||
{
|
||||
if (!_zoneSphere.activeSelf) _zoneSphere.SetActive(true);
|
||||
|
||||
// Диаметр сферы = 2 * радиус (possessRange)
|
||||
float diameter = possessRange * 2f;
|
||||
_zoneSphere.transform.localScale = new Vector3(diameter, diameter, diameter);
|
||||
|
||||
// Центр сферы: либо на враге, либо на игроке
|
||||
Vector3 center = centerSphereOnTarget ? AimedEnemy.transform.position : transform.position;
|
||||
_zoneSphere.transform.position = center;
|
||||
|
||||
@@ -152,12 +151,10 @@ namespace _Project.Scripts.PlayerUtils
|
||||
{
|
||||
if (Keyboard.current == null) return;
|
||||
|
||||
// Клавиша E — Вселиться, если враг под прицелом И находится внутри сферы!
|
||||
if (Keyboard.current.eKey.wasPressedThisFrame && AimedEnemy != null && IsTargetInPossessZone)
|
||||
{
|
||||
StartCoroutine(PossessRoutine(AimedEnemy));
|
||||
}
|
||||
// Клавиша Q — Покинуть тело
|
||||
else if (Keyboard.current.qKey.wasPressedThisFrame && !IsInSpiritForm)
|
||||
{
|
||||
EnterSpiritForm(true);
|
||||
@@ -199,6 +196,8 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
public void EnterSpiritForm(bool ejectImpulse)
|
||||
{
|
||||
if (IsDead) return;
|
||||
|
||||
ApplyProfile(spiritProfile, spiritProfile.maxHealth);
|
||||
_invulnerableTimer = 0.5f;
|
||||
|
||||
@@ -225,7 +224,7 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
public void TakeDamage(float amount)
|
||||
{
|
||||
if (_invulnerableTimer > 0f || _isTransitioning) return;
|
||||
if (IsDead || _invulnerableTimer > 0f || _isTransitioning) return;
|
||||
|
||||
CurrentHealth -= amount;
|
||||
|
||||
@@ -233,18 +232,38 @@ namespace _Project.Scripts.PlayerUtils
|
||||
{
|
||||
if (!IsInSpiritForm)
|
||||
{
|
||||
// Тело уничтожено — выбрасывает обратно в Духа
|
||||
Debug.Log("Носитель уничтожен! Выброс в форму Духа!");
|
||||
EnterSpiritForm(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentHealth = 0f;
|
||||
Debug.Log("ДУХ УНИЧТОЖЕН! ИГРА ОКОНЧЕНА.");
|
||||
EnterSpiritForm(false);
|
||||
// Убили самого Духа — проигрыш!
|
||||
Die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Die()
|
||||
{
|
||||
if (IsDead) return;
|
||||
IsDead = true;
|
||||
CurrentHealth = 0f;
|
||||
|
||||
if (_zoneSphere != null) _zoneSphere.SetActive(false);
|
||||
|
||||
// Останавливаем время и отключаем управление персонажа
|
||||
Time.timeScale = 0f;
|
||||
Player.Instance.Controls.Player.Disable();
|
||||
|
||||
// Освобождаем курсор мыши для клика по кнопкам панели проигрыша
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
|
||||
Debug.Log("ДУХ РАЗВЕЯН! Игрок погиб.");
|
||||
OnPlayerDied?.Invoke();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_zoneSphere != null) Destroy(_zoneSphere);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace _Project.Scripts.PlayerUtils
|
||||
{
|
||||
@@ -7,20 +9,81 @@ namespace _Project.Scripts.PlayerUtils
|
||||
[Header("Настройки Интерфейса")]
|
||||
[SerializeField] private bool showHUD = true;
|
||||
|
||||
[Header("Панель проигрыша (Canvas UI)")]
|
||||
[Tooltip("Перетащи сюда панель поражения из Canvas. Если пусто — отрисуется встроенная панель проигрыша.")]
|
||||
[SerializeField] private GameObject losePanel;
|
||||
|
||||
private PlayerMovement movement;
|
||||
private PlayerPossession possession;
|
||||
private bool isGameOver = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
movement = Player.Instance.Movement;
|
||||
possession = Player.Instance.Possession;
|
||||
|
||||
if (losePanel != null)
|
||||
{
|
||||
losePanel.SetActive(false);
|
||||
}
|
||||
|
||||
if (possession != null)
|
||||
{
|
||||
possession.OnPlayerDied += HandlePlayerDied;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (possession != null)
|
||||
{
|
||||
possession.OnPlayerDied -= HandlePlayerDied;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePlayerDied()
|
||||
{
|
||||
isGameOver = true;
|
||||
|
||||
if (losePanel != null)
|
||||
{
|
||||
losePanel.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Быстрый перезапуск по клавише R после смерти
|
||||
if (isGameOver && Keyboard.current != null && Keyboard.current.rKey.wasPressedThisFrame)
|
||||
{
|
||||
RestartLevel();
|
||||
}
|
||||
}
|
||||
|
||||
// Этот метод также можно повесить на кнопку (Button -> OnClick) на твоём Canvas!
|
||||
public void RestartLevel()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
Time.fixedDeltaTime = 0.02f;
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
// 1. Если игрок погиб, а кастомная Canvas-панель не назначена — рисуем экран проигрыша
|
||||
if (isGameOver)
|
||||
{
|
||||
if (losePanel == null)
|
||||
{
|
||||
DrawFallbackLoseScreen();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Обычный боевой HUD
|
||||
if (!showHUD || movement == null) return;
|
||||
|
||||
float speed = movement.CurrentSpeed;
|
||||
float speed = movement.CurrentSpeed;
|
||||
float csUnits = speed * 38.5f;
|
||||
|
||||
GUIStyle style = new GUIStyle { fontSize = 22, fontStyle = FontStyle.Bold };
|
||||
@@ -56,5 +119,40 @@ namespace _Project.Scripts.PlayerUtils
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawFallbackLoseScreen()
|
||||
{
|
||||
// Полупрозрачное тёмно-красное/чёрное затемнение на весь экран
|
||||
Color prevColor = GUI.color;
|
||||
GUI.color = new Color(0.08f, 0.01f, 0.02f, 0.85f);
|
||||
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), Texture2D.whiteTexture);
|
||||
GUI.color = prevColor;
|
||||
|
||||
GUIStyle titleStyle = new GUIStyle
|
||||
{
|
||||
fontSize = 48,
|
||||
fontStyle = FontStyle.Bold,
|
||||
alignment = TextAnchor.MiddleCenter
|
||||
};
|
||||
titleStyle.normal.textColor = new Color(1f, 0.2f, 0.25f);
|
||||
|
||||
GUIStyle subStyle = new GUIStyle
|
||||
{
|
||||
fontSize = 22,
|
||||
alignment = TextAnchor.MiddleCenter
|
||||
};
|
||||
subStyle.normal.textColor = new Color(0.85f, 0.85f, 0.85f);
|
||||
|
||||
float cx = Screen.width / 2f;
|
||||
float cy = Screen.height / 2f;
|
||||
|
||||
GUI.Label(new Rect(cx - 300f, cy - 110f, 600f, 60f), "ДУХ МЩЕНИЯ РАЗВЕЯН", titleStyle);
|
||||
GUI.Label(new Rect(cx - 300f, cy - 45f, 600f, 40f), "Вы потеряли последнюю связь с этим миром.", subStyle);
|
||||
|
||||
if (GUI.Button(new Rect(cx - 150f, cy + 25f, 300f, 50f), "ПЕРЕЗАПУСТИТЬ ЭТАЖ [R]"))
|
||||
{
|
||||
RestartLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user