Первый коммит с LFS.
This commit is contained in:
1 parent
4fcb1e2f24
commit
179816dc4b
5084 files changed
+3714098
-1
No files matched your search
@@ -0,0 +1,37 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class EventTriggerOnCollision : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Тег объекта, который должен активировать триггер.")] [SerializeField]
|
||||
private string _targetTag;
|
||||
|
||||
[Tooltip("Событие, которое будет вызвано при входе в триггер.")]
|
||||
[SerializeField] private GameEvent _eventToRaise;
|
||||
|
||||
[Tooltip("Если true, событие будет срабатывать только один раз.")]
|
||||
[SerializeField] private bool _triggerOnce = true;
|
||||
|
||||
private bool _hasBeenTriggered = false;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (_hasBeenTriggered && _triggerOnce)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (other.CompareTag(_targetTag))
|
||||
{
|
||||
_eventToRaise.Raise();
|
||||
_hasBeenTriggered = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
// Убедимся, что коллайдер на объекте является триггером
|
||||
GetComponent<Collider>().isTrigger = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f783bdc6f8b240a187af9a15648ae9db
|
||||
timeCreated: 1764803977
|
||||
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class EventTriggerOnStay : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Тег объекта, который должен активировать триггер.")]
|
||||
[SerializeField] private string _targetTag = "Player";
|
||||
|
||||
[Tooltip("Событие, которое будет вызвано.")]
|
||||
[SerializeField] private GameEvent _eventToRaise;
|
||||
|
||||
[Tooltip("Время в секундах, которое объект должен провести в триггере для срабатывания.")]
|
||||
[SerializeField] private float _timeToStay = 2.0f;
|
||||
|
||||
[Tooltip("Если true, событие будет срабатывать только один раз.")]
|
||||
[SerializeField] private bool _triggerOnce = true;
|
||||
|
||||
private bool _hasBeenTriggered = false;
|
||||
private Coroutine _timerCoroutine;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if ((_hasBeenTriggered && _triggerOnce) || !other.CompareTag(_targetTag))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Запускаем корутину-таймер
|
||||
_timerCoroutine = StartCoroutine(TimerCoroutine());
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.CompareTag(_targetTag) && _timerCoroutine != null)
|
||||
{
|
||||
// Если игрок покинул зону, останавливаем таймер
|
||||
StopCoroutine(_timerCoroutine);
|
||||
_timerCoroutine = null;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator TimerCoroutine()
|
||||
{
|
||||
yield return new WaitForSeconds(_timeToStay);
|
||||
|
||||
_eventToRaise.Raise();
|
||||
_hasBeenTriggered = true;
|
||||
_timerCoroutine = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b01c76c4d8fd47d993f1f642f964c911
|
||||
timeCreated: 1764807553
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(menuName = "Game Event", fileName = "New Game Event")]
|
||||
public class GameEvent : ScriptableObject
|
||||
{
|
||||
private readonly List<GameEventListener> _listeners = new List<GameEventListener>();
|
||||
|
||||
public void Raise()
|
||||
{
|
||||
// Проходимся по списку в обратном порядке, на случай если слушатель удалится во время вызова
|
||||
for (int i = _listeners.Count - 1; i >= 0; i--)
|
||||
{
|
||||
_listeners[i].OnEventRaised();
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterListener(GameEventListener listener)
|
||||
{
|
||||
if (!_listeners.Contains(listener))
|
||||
{
|
||||
_listeners.Add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnregisterListener(GameEventListener listener)
|
||||
{
|
||||
if (_listeners.Contains(listener))
|
||||
{
|
||||
_listeners.Remove(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9817517fd364cf9b2e31ce10da6443c
|
||||
timeCreated: 1764803840
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class GameEventListener : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Событие, на которое нужно отреагировать.")]
|
||||
[SerializeField] private GameEvent _event;
|
||||
|
||||
[Tooltip("Действия, которые выполнятся при срабатывании события.")]
|
||||
[SerializeField] private UnityEvent _response;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_event.RegisterListener(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_event.UnregisterListener(this);
|
||||
}
|
||||
|
||||
public void OnEventRaised()
|
||||
{
|
||||
_response.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba281a10cc184e2eb5600908e4c425a2
|
||||
timeCreated: 1764803903
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d2b0107be8f4f6782c92dc020428da4
|
||||
timeCreated: 1764805688
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class KnifeController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Rigidbody[] _knives;
|
||||
[SerializeField] private AudioSource _audioSource;
|
||||
[SerializeField] private AudioClip _fallSound;
|
||||
|
||||
public void DropKnives()
|
||||
{
|
||||
if (_audioSource != null && _fallSound != null)
|
||||
{
|
||||
_audioSource.PlayOneShot(_fallSound);
|
||||
}
|
||||
|
||||
foreach (var knifeRb in _knives)
|
||||
{
|
||||
if (knifeRb != null)
|
||||
{
|
||||
knifeRb.isKinematic = false;
|
||||
knifeRb.useGravity = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Опционально: отключаем этот компонент, чтобы ножи не упали снова
|
||||
// enabled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51ff3fcabb344f16a61de20a3d1f9821
|
||||
timeCreated: 1764805699
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c476224bbdb84a2f9245eec6d91b3c04
|
||||
timeCreated: 1764807553
|
||||
@@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class TVController : MonoBehaviour
|
||||
{
|
||||
[Header("Компоненты")]
|
||||
[Tooltip("Renderer объекта, представляющего экран телевизора.")]
|
||||
[SerializeField] private Renderer _tvScreenRenderer;
|
||||
[SerializeField] private AudioSource _audioSource;
|
||||
|
||||
[Header("Настройки")]
|
||||
[Tooltip("Звук, который проигрывается при включенном телевизоре.")]
|
||||
[SerializeField] private AudioClip _tvSound;
|
||||
|
||||
[Tooltip("Через сколько секунд после включения телевизор выключится.")]
|
||||
[SerializeField] private float _onDuration = 5.0f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Убедимся, что экран и звук выключены на старте
|
||||
if (_tvScreenRenderer != null)
|
||||
{
|
||||
_tvScreenRenderer.enabled = false;
|
||||
}
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// Публичный метод для включения телевизора
|
||||
public void TurnOnAndOffAfterDelay()
|
||||
{
|
||||
StartCoroutine(TVActivationCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator TVActivationCoroutine()
|
||||
{
|
||||
// Фаза включения
|
||||
Debug.Log("Телевизор включается...");
|
||||
_tvScreenRenderer.enabled = true;
|
||||
_audioSource.PlayOneShot(_tvSound);
|
||||
|
||||
// Ожидание
|
||||
yield return new WaitForSeconds(_onDuration);
|
||||
|
||||
// Фаза выключения
|
||||
Debug.Log("Телевизор выключается...");
|
||||
_tvScreenRenderer.enabled = false;
|
||||
// Звук остановится сам, так как он OneShot. Если звук зациклен, нужно использовать _audioSource.Stop().
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65c7178ad67848738b96cee7ef3e5f35
|
||||
timeCreated: 1764807553
|
||||
Reference in new issue
Block a user