Первый коммит с LFS.

This commit is contained in:
vladislove committed 2026-01-11 17:04:23 +03:00
1 parent 4fcb1e2f24
commit 179816dc4b
5084 files changed
+3714098 -1

No files matched your search

@@ -0,0 +1,103 @@
using System.Collections;
using UnityEngine;
/// <summary>
/// A generic component for objects that can be "cleaned" or "removed"
/// by fading them out. Requires a specific item in the inventory.
/// </summary>
public class FadableObject : MonoBehaviour, IInteractable
{
[Header("Settings")]
[Tooltip("The item required in the inventory to interact with this object.")]
[SerializeField] private ItemData requiredItem;
[Tooltip("How long it takes for the object to fade out completely.")]
[SerializeField] private float fadeDuration = 1.5f;
private bool isFading = false;
private Renderer _renderer;
private void Start()
{
_renderer = GetComponent<Renderer>();
if (_renderer == null)
{
_renderer = GetComponentInChildren<Renderer>();
}
if (requiredItem == null)
{
Debug.LogError($"FadableObject on '{gameObject.name}' is missing a 'requiredItem'.", this);
}
}
public void Interact()
{
if (isFading) return;
// Check if the player has the required item
if (InventorySystem.Instance.HasItem(requiredItem))
{
// We don't check for a specific quest here.
// We just notify the InteractionHandler, and the active quest will decide if it's relevant.
StartCoroutine(FadeOutRoutine());
}
else
{
Debug.Log($"A '{requiredItem?.itemName}' is needed to clean this!");
}
}
private IEnumerator FadeOutRoutine()
{
isFading = true;
// Notify the quest system that an interaction happened.
InteractionHandler.Instance.NotifyInteraction(gameObject);
// Trigger the appropriate animation based on the required item.
// This is a simple but effective way to manage different tool animations.
if (requiredItem.itemName.ToLower().Contains("broom"))
{
PlayerHandsController.Instance?.PlaySweepAnimation();
}
else if (requiredItem.itemName.ToLower().Contains("rag"))
{
PlayerHandsController.Instance?.PlayWipeAnimation();
}
// Fade-out logic
if (_renderer != null)
{
Material mat = _renderer.material;
Color startColor = mat.color;
float timer = 0f;
while (timer < fadeDuration)
{
timer += Time.deltaTime;
float alpha = Mathf.Lerp(startColor.a, 0f, timer / fadeDuration);
mat.color = new Color(startColor.r, startColor.g, startColor.b, alpha);
yield return null;
}
}
else
{
yield return new WaitForSeconds(fadeDuration);
}
Debug.Log($"Object '{gameObject.name}' faded out and destroyed.");
Destroy(gameObject);
}
public string GetDescription()
{
if (isFading) return "";
// Provide a dynamic description
if (requiredItem != null)
{
if (requiredItem.itemName.ToLower().Contains("broom")) return "Sweep";
if (requiredItem.itemName.ToLower().Contains("rag")) return "Wipe";
}
return "Clean";
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1619763fbc3892a769f87a37f1883a79
@@ -0,0 +1,16 @@
using UnityEngine;
using System.Collections.Generic;
public interface IQuest
{
string QuestName { get; }
string Description { get; }
int CurrentStep { get; }
int TotalSteps { get; }
bool IsCompleted { get; }
event System.Action<string>
OnQuestStepChanged;
void StartQuest();
void CompleteQuest();
void AdvanceQuestStep();
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e856f540eff0ff3ca992f9150b0bb6b3
@@ -0,0 +1,34 @@
using UnityEngine;
/// <summary>
/// A simple component that makes an object interactable
/// and just notifies the InteractionHandler that it has been interacted with.
/// Ideal for objects that don't have complex logic but need to be recognized
/// by the quest system (e.g., a dumpster).
/// </summary>
public class NotifyInteractionObject : MonoBehaviour, IInteractable
{
[SerializeField]
private string description = "Interact";
public void Interact()
{
// Check if InteractionHandler exists
if (InteractionHandler.Instance != null)
{
// Notify the system that this object (gameObject) has been interacted with.
// The QuestManager, subscribed to this event, will receive the notification.
InteractionHandler.Instance.NotifyInteraction(gameObject);
Debug.Log($"Interaction notified for {gameObject.name}");
}
else
{
Debug.LogError("InteractionHandler.Instance is not found in the scene.");
}
}
public string GetDescription()
{
return description;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 661e0d1c241c4ed0ab7688ebb0292308
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3751add09ea346e99574f83336b33773
timeCreated: 1764607784
@@ -0,0 +1,30 @@
using UnityEngine;
public class PickupBagAction : MonoBehaviour, IInteractable
{
[Header("Settings")]
public ItemData bagItemData; // Reference to the bag's ScriptableObject
public void Interact()
{
// 1. Try to add the item to the inventory
bool added = InventorySystem.Instance.AddItem(bagItemData);
if (added)
{
// 2. Notify the quest system that we interacted with this object
// The quest itself will decide what to do next (e.g., show the bag in hand)
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.NotifyInteraction(gameObject);
}
}
// If the item was not added (already exists or no space), do nothing.
// A message about this is logged from the InventorySystem.
}
public string GetDescription()
{
return "Pick up trash bags";
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eae795e938db451ebcd0e939e9f3366b
timeCreated: 1764526904
@@ -0,0 +1,16 @@
using UnityEngine;
namespace Quest_Environment.Q1
{
public class TrashBin :MonoBehaviour,IInteractable
{
public void Interact()
{
}
public string GetDescription()
{
return "Положить в мусорку";
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 12f55188f40241dd84d50be74a4eb8ac
timeCreated: 1764607809
@@ -0,0 +1,61 @@
using Quests;
using UnityEngine;
public class TrashPile : MonoBehaviour, IInteractable
{
[Header("Settings")]
public ItemData requiredBagItem; // Ссылка на ItemData мешка (для проверки в инвентаре)
public void Interact()
{
// 1. Проверяем, что сейчас активен именно квест по сбору мусора
if (QuestManager.Instance?.currentQuest is Q1CollectGarbageQuest garbageQuest)
{
// 2. Проверяем, есть ли у игрока мешок
if (InventorySystem.Instance.HasItem(requiredBagItem))
{
// 3. Проверяем, не полон ли мешок
if (garbageQuest.IsBagFull())
{
Debug.Log("Мешок полон! Сначала выбросьте его в контейнер.");
}
else
{
// Если все проверки пройдены, уведомляем систему квестов
InteractionHandler.Instance.NotifyInteraction(gameObject);
// Уничтожаем объект мусора
Destroy(gameObject);
}
}
else
{
Debug.Log("Нужен мешок для мусора!");
}
}
// Если активен другой квест, ничего не делаем.
}
public string GetDescription()
{
// Даем описание, только если активен квест по сбору мусора
if (QuestManager.Instance?.currentQuest is Q1CollectGarbageQuest garbageQuest)
{
// Проверяем, есть ли у игрока мешок
if (!InventorySystem.Instance.HasItem(requiredBagItem))
{
return "Нужен мешок для мусора"; // Подсказка, если нет мешка
}
// Проверяем, не полон ли мешок
if (garbageQuest.IsBagFull())
{
return "Мешок полон!";
}
return "Собрать мусор"; // Стандартное описание
}
// Если квест неактивен, возвращаем пустую строку
return "";
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3d20c394d52e426d964b8cf9d1de6b83
timeCreated: 1764526435
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a18989bdc07f4b54b795f6e9f37fccaf
timeCreated: 1764782534
@@ -0,0 +1,86 @@
using System.Collections;
using UnityEngine;
namespace Quest_Environment.Q2
{
public class DirtSpot : MonoBehaviour, IInteractable
{
[Header("Settings")]
public ItemData requiredBroomItem;
[SerializeField] private float cleanDuration = 1.5f;
private bool isCleaning = false;
private Renderer _renderer;
private void Start()
{
_renderer = GetComponent<Renderer>();
if (_renderer == null)
{
_renderer = GetComponentInChildren<Renderer>();
}
}
public void Interact()
{
if (isCleaning) return;
bool hasBroom = InventorySystem.Instance.HasItem(requiredBroomItem);
if (hasBroom)
{
if (QuestManager.Instance != null && QuestManager.Instance.currentQuest is Q2_SweepDirtQuest)
{
StartCoroutine(CleanRoutine());
}
else
{
Debug.Log("It's dirty here, but I have no reason to clean it right now.");
}
}
else
{
Debug.Log("A broom is needed to clean this!");
}
}
private IEnumerator CleanRoutine()
{
isCleaning = true;
// --- TRIGGER ANIMATION ---
PlayerHandsController.Instance?.PlaySweepAnimation();
// -------------------------
InteractionHandler.Instance.NotifyInteraction(gameObject);
if (_renderer != null)
{
Material mat = _renderer.material;
Color startColor = mat.color;
float timer = 0f;
while (timer < cleanDuration)
{
timer += Time.deltaTime;
float alpha = Mathf.Lerp(startColor.a, 0f, timer / cleanDuration);
mat.color = new Color(startColor.r, startColor.g, startColor.b, alpha);
yield return null;
}
}
else
{
yield return new WaitForSeconds(cleanDuration);
}
Debug.Log("Dirt cleaned!");
Destroy(gameObject);
}
public string GetDescription()
{
if (isCleaning) return "";
return "Sweep";
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 684169532f6d4bb586538dd24ed55a1b
timeCreated: 1764782543
@@ -0,0 +1,41 @@
using UnityEngine;
namespace Quest_Environment.Q2
{
public class PickupBroomAction : MonoBehaviour, IInteractable
{
[Header("Settings")]
public ItemData broomItemData;
public void Interact()
{
// Check if the current quest is the correct one for this item
if (!(QuestManager.Instance?.currentQuest is Q2_SweepDirtQuest))
{
Debug.Log("I have no reason to pick this up right now.");
return; // Do nothing if it's not the right quest
}
bool added = InventorySystem.Instance.AddItem(broomItemData);
if (added)
{
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.NotifyInteraction(gameObject);
}
Destroy(gameObject);
}
}
public string GetDescription()
{
// Only show the description if the correct quest is active
if (QuestManager.Instance?.currentQuest is Q2_SweepDirtQuest)
{
return "Take the broom";
}
return ""; // Return empty string to hide the prompt
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 89b798cd1bc445fe999ee96661e67ec0
timeCreated: 1764782752
@@ -0,0 +1,144 @@
using UnityEngine;
using Player;
namespace Quest_Environment.Q2
{
public class Q2_SweepDirtQuest : MonoBehaviour, IQuest
{
[Header("Quest Settings")]
[SerializeField] private string questName = "Room Cleaning";
[SerializeField] private int dirtPilesTotal = 5;
[SerializeField] private ItemData broomItem;
[Header("Target Tags")]
[SerializeField] private string broomGiverTag = "BroomLocation";
[SerializeField] private string dirtTag = "Dirt";
[Header("Audio Settings")]
[SerializeField] private AudioClip pickupBroomSound;
[SerializeField] private AudioClip cleanDirtSound;
private PlayerController _playerController;
private enum Stage
{
NotStarted,
FindBroom,
SweepDirt,
Completed
}
private Stage currentStage = Stage.NotStarted;
private int cleanedDirtCount = 0;
public string QuestName => questName;
public string Description { get; private set; }
public int CurrentStep => cleanedDirtCount;
public int TotalSteps => dirtPilesTotal;
public bool IsCompleted => currentStage == Stage.Completed;
public event System.Action<string> OnQuestStepChanged;
public void StartQuest()
{
if (broomItem == null) Debug.LogError($"[Q2] Broom ItemData is missing!");
currentStage = Stage.FindBroom;
cleanedDirtCount = 0;
PlayerHandsController.Instance?.HideHands();
_playerController = FindObjectOfType<PlayerController>();
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.onObjectInteracted += HandleInteraction;
}
UpdateQuestState();
}
private void OnDestroy()
{
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.onObjectInteracted -= HandleInteraction;
}
}
private void HandleInteraction(GameObject obj)
{
if (currentStage == Stage.Completed || obj == null) return;
switch (currentStage)
{
case Stage.FindBroom:
if (obj.CompareTag(broomGiverTag))
{
currentStage = Stage.SweepDirt;
_playerController?.PlayOneShotSound(pickupBroomSound);
PlayerHandsController.Instance?.ShowBroom(true);
UpdateQuestState();
}
break;
case Stage.SweepDirt:
if (obj.CompareTag(dirtTag))
{
cleanedDirtCount++;
_playerController?.PlayOneShotSound(cleanDirtSound);
QuestManager.Instance.StepCompleted();
if (cleanedDirtCount >= dirtPilesTotal)
{
FinishQuest();
}
else
{
UpdateQuestState();
}
}
break;
}
}
private void UpdateQuestState()
{
switch (currentStage)
{
case Stage.FindBroom:
Description = "Find a broom.";
break;
case Stage.SweepDirt:
Description = "Sweep the floors in the rooms.";
break;
case Stage.Completed:
Description = "The floor is clean!";
break;
}
OnQuestStepChanged?.Invoke(Description);
}
private void FinishQuest()
{
currentStage = Stage.Completed;
// Hide the broom and remove it from inventory
PlayerHandsController.Instance?.ShowBroom(false);
if (broomItem != null)
{
InventorySystem.Instance.RemoveItem(broomItem);
}
UpdateQuestState();
QuestManager.Instance.CompleteQuest();
}
public void AdvanceQuestStep() { }
public void CompleteQuest()
{
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.onObjectInteracted -= HandleInteraction;
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0b4fa2d4dfc4b6c0fa009fa452a1b5d7
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a26f32de43b8f9d6abb4c6faa954b06b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
using UnityEngine;
namespace Quest_Environment.Q3
{
public class PickupRagAction : MonoBehaviour, IInteractable
{
[Header("Settings")]
public ItemData ragItemData;
public void Interact()
{
if (!(QuestManager.Instance?.currentQuest is Q3_WipeSurfacesQuest))
{
Debug.Log("I have no reason to pick this up right now.");
return;
}
bool added = InventorySystem.Instance.AddItem(ragItemData);
if (added)
{
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.NotifyInteraction(gameObject);
}
Destroy(gameObject);
}
}
public string GetDescription()
{
if (QuestManager.Instance?.currentQuest is Q3_WipeSurfacesQuest)
{
return "Take the rag";
}
return "";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7d76b6445428c35d38032c814918904f
@@ -0,0 +1,144 @@
using UnityEngine;
using Player;
namespace Quest_Environment.Q3
{
public class Q3_WipeSurfacesQuest : MonoBehaviour, IQuest
{
[Header("Quest Settings")]
[SerializeField] private string questName = "Surface Wiping";
[SerializeField] private int surfacesToWipeTotal = 3;
[SerializeField] private ItemData ragItem;
[Header("Target Tags")]
[SerializeField] private string ragGiverTag = "RagLocation";
[SerializeField] private string surfaceTag = "WipeableSurface";
[Header("Audio Settings")]
[SerializeField] private AudioClip pickupRagSound;
[SerializeField] private AudioClip wipeSurfaceSound;
private PlayerController _playerController;
private enum Stage
{
NotStarted,
FindRag,
WipeSurfaces,
Completed
}
private Stage currentStage = Stage.NotStarted;
private int wipedSurfacesCount = 0;
public string QuestName => questName;
public string Description { get; private set; }
public int CurrentStep => wipedSurfacesCount;
public int TotalSteps => surfacesToWipeTotal;
public bool IsCompleted => currentStage == Stage.Completed;
public event System.Action<string> OnQuestStepChanged;
public void StartQuest()
{
if (ragItem == null) Debug.LogError($"[Q3] Rag ItemData is missing!");
currentStage = Stage.FindRag;
wipedSurfacesCount = 0;
PlayerHandsController.Instance?.HideHands();
_playerController = FindObjectOfType<PlayerController>();
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.onObjectInteracted += HandleInteraction;
}
UpdateQuestState();
}
private void OnDestroy()
{
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.onObjectInteracted -= HandleInteraction;
}
}
private void HandleInteraction(GameObject obj)
{
if (currentStage == Stage.Completed || obj == null) return;
switch (currentStage)
{
case Stage.FindRag:
if (obj.CompareTag(ragGiverTag))
{
currentStage = Stage.WipeSurfaces;
_playerController?.PlayOneShotSound(pickupRagSound);
PlayerHandsController.Instance?.ShowRag(true);
UpdateQuestState();
}
break;
case Stage.WipeSurfaces:
if (obj.CompareTag(surfaceTag))
{
wipedSurfacesCount++;
_playerController?.PlayOneShotSound(wipeSurfaceSound);
QuestManager.Instance.StepCompleted();
if (wipedSurfacesCount >= surfacesToWipeTotal)
{
FinishQuest();
}
else
{
UpdateQuestState();
}
}
break;
}
}
private void UpdateQuestState()
{
switch (currentStage)
{
case Stage.FindRag:
Description = "Find a rag.";
break;
case Stage.WipeSurfaces:
Description = "Wipe the dirty surfaces.";
break;
case Stage.Completed:
Description = "Everything is clean!";
break;
}
OnQuestStepChanged?.Invoke(Description);
}
private void FinishQuest()
{
currentStage = Stage.Completed;
// Hide the rag and remove it from inventory
PlayerHandsController.Instance?.ShowRag(false);
if (ragItem != null)
{
InventorySystem.Instance.RemoveItem(ragItem);
}
UpdateQuestState();
QuestManager.Instance.CompleteQuest();
}
public void AdvanceQuestStep() { }
public void CompleteQuest()
{
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.onObjectInteracted -= HandleInteraction;
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: eb2201aaa904246a1934c0d3e6804e7a
@@ -0,0 +1,75 @@
using System.Collections;
using UnityEngine;
namespace Quest_Environment.Q3
{
public class WipeableSurface : MonoBehaviour, IInteractable
{
[Header("Settings")]
public ItemData requiredRagItem;
[SerializeField] private float wipeDuration = 1.0f;
[Header("Object References")]
[Tooltip("The clean version of the surface to be activated.")]
[SerializeField] private GameObject cleanSurfaceObject;
[Tooltip("The dirty version of the surface to be deactivated.")]
[SerializeField] private GameObject dirtySurfaceObject;
private bool isWiping = false;
private void Start()
{
// Ensure the clean version is hidden at the start
if (cleanSurfaceObject != null) cleanSurfaceObject.SetActive(false);
}
public void Interact()
{
if (isWiping) return;
bool hasRag = InventorySystem.Instance.HasItem(requiredRagItem);
if (hasRag)
{
if (QuestManager.Instance != null && QuestManager.Instance.currentQuest is Q3_WipeSurfacesQuest)
{
StartCoroutine(WipeRoutine());
}
else
{
Debug.Log("This is dirty, but I have no reason to clean it right now.");
}
}
else
{
Debug.Log("A rag is needed to clean this!");
}
}
private IEnumerator WipeRoutine()
{
isWiping = true;
PlayerHandsController.Instance?.PlayWipeAnimation();
InteractionHandler.Instance.NotifyInteraction(gameObject);
// Wait for the animation to finish
yield return new WaitForSeconds(wipeDuration);
if (dirtySurfaceObject != null) dirtySurfaceObject.SetActive(false);
if (cleanSurfaceObject != null) cleanSurfaceObject.SetActive(true);
Debug.Log("Surface wiped clean!");
// We don't destroy the parent object, just disable this script
// to prevent further interaction.
this.enabled = false;
}
public string GetDescription()
{
if (isWiping || !this.enabled) return "";
return "Wipe surface";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0b03ffff37f14870a99dcbcc6b88f3ce
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9fbcdb85dcc14fe6920c2d097cf58197
timeCreated: 1764886783
@@ -0,0 +1,99 @@
using UnityEngine;
namespace Quest_Environment.Q4
{
[RequireComponent(typeof(Collider))]
public class FurniturePlacementZone : MonoBehaviour, IInteractable
{
[Tooltip("The ID of the furniture that belongs in this zone.")]
[SerializeField] private string targetFurnitureId;
[Tooltip("The furniture object to show when placed.")]
[SerializeField] private GameObject placedFurniturePrefab;
[Tooltip("The GameObject with an Outline component that acts as a visual indicator.")]
[SerializeField] private GameObject zoneIndicator;
private bool _isOccupied = false;
private Outline _indicatorOutline; // *** НОВОЕ ПОЛЕ для хранения компонента
void Start()
{
// *** ИЗМЕНЕНИЕ: Находим и кэшируем компонент Outline
if (zoneIndicator != null)
{
_indicatorOutline = zoneIndicator.GetComponent<Outline>();
}
ResetZone();
}
public void Interact()
{
if (QuestManager.Instance?.currentQuest is Q4_PlaceFurnitureQuest furnitureQuest)
{
if (!_isOccupied && furnitureQuest.HeldFurnitureId == targetFurnitureId)
{
InteractionHandler.Instance.NotifyInteraction(gameObject);
}
}
}
public string GetDescription()
{
if (QuestManager.Instance?.currentQuest is Q4_PlaceFurnitureQuest furnitureQuest)
{
if (!_isOccupied && furnitureQuest.HeldFurnitureId == targetFurnitureId)
{
return $"Поставить {targetFurnitureId}";
}
}
return "";
}
public void PlaceItem()
{
_isOccupied = true;
if (placedFurniturePrefab != null) placedFurniturePrefab.SetActive(true);
// *** ИЗМЕНЕНИЕ: Выключаем Outline через компонент
if (_indicatorOutline != null)
{
_indicatorOutline.enabled = false;
}
}
public void ResetZone()
{
_isOccupied = false;
if (placedFurniturePrefab != null) placedFurniturePrefab.SetActive(false);
// *** ИЗМЕНЕНИЕ: Выключаем Outline через компонент
if (_indicatorOutline != null)
{
_indicatorOutline.enabled = false;
}
}
void Update()
{
// Если у нас нет компонента подсветки или зона уже занята, ничего не делаем
if (_indicatorOutline == null || _isOccupied)
{
return;
}
bool shouldBeActive = false;
if (QuestManager.Instance?.currentQuest is Q4_PlaceFurnitureQuest furnitureQuest)
{
if (furnitureQuest.HeldFurnitureId == targetFurnitureId)
{
shouldBeActive = true;
}
}
// *** ИЗМЕНЕНИЕ: Включаем/выключаем сам компонент, а не весь GameObject
if (_indicatorOutline.enabled != shouldBeActive)
{
_indicatorOutline.enabled = shouldBeActive;
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5a6c0505d876d3b9087aca44c7e5e5db
@@ -0,0 +1,36 @@
using UnityEngine;
namespace Quest_Environment.Q4
{
[RequireComponent(typeof(Outline))]
public class MovableFurniture : MonoBehaviour, IInteractable
{
[Tooltip("A unique ID for this piece of furniture (e.g., 'Chair', 'Lamp').")]
[SerializeField] private string furnitureId;
public void Interact()
{
// Проверяем, что сейчас идет квест с мебелью, прежде чем что-то делать
if (QuestManager.Instance?.currentQuest is Q4_PlaceFurnitureQuest)
{
InteractionHandler.Instance.NotifyInteraction(gameObject);
}
}
public string GetDescription()
{
// Описание будет только если активен квест по расстановке мебели
if (QuestManager.Instance?.currentQuest is Q4_PlaceFurnitureQuest furnitureQuest)
{
// И если игрок ничего не "держит" в руках
if (furnitureQuest.HeldFurnitureId == null)
{
return $"Подобрать {furnitureId}";
}
}
// В противном случае возвращаем пустую строку, и подсветки не будет
return "";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 21362de71083aec96a3b66b617e67ee1
@@ -0,0 +1,136 @@
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
namespace Quest_Environment.Q4
{
public class Q4_PlaceFurnitureQuest : MonoBehaviour, IQuest
{
[System.Serializable]
public class FurnitureTask
{
public string furnitureId;
[Tooltip("The object that can be picked up.")]
public GameObject pickupObject;
[Tooltip("The zone where the object should be placed.")]
public FurniturePlacementZone placementZone;
[HideInInspector] public bool isPlaced;
}
[Header("Quest Settings")]
[SerializeField] private string questName = "Tidy Up the Room";
[SerializeField] private List<FurnitureTask> furnitureTasks;
private string _heldFurnitureId = null;
private int _placedCount = 0;
public string QuestName => questName;
public string Description { get; private set; }
public int CurrentStep => _placedCount;
public int TotalSteps => furnitureTasks.Count;
public bool IsCompleted => _placedCount >= TotalSteps;
public string HeldFurnitureId => _heldFurnitureId;
public event System.Action<string> OnQuestStepChanged;
public void StartQuest()
{
_placedCount = 0;
_heldFurnitureId = null;
foreach (var task in furnitureTasks)
{
task.isPlaced = false;
if (task.placementZone != null) task.placementZone.ResetZone();
if (task.pickupObject != null) task.pickupObject.SetActive(true);
}
PlayerHandsController.Instance?.HideHands();
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.onObjectInteracted += HandleInteraction;
}
UpdateQuestState();
}
void OnDestroy()
{
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.onObjectInteracted -= HandleInteraction;
}
}
private void HandleInteraction(GameObject interactedObject)
{
if (IsCompleted) return;
if (_heldFurnitureId == null)
{
var task = furnitureTasks.FirstOrDefault(t => !t.isPlaced && t.pickupObject == interactedObject);
if (task != null)
{
_heldFurnitureId = task.furnitureId;
task.pickupObject.SetActive(false);
UpdateQuestState();
return;
}
}
else
{
var task = furnitureTasks.FirstOrDefault(t => t.furnitureId == _heldFurnitureId && t.placementZone.gameObject == interactedObject);
if (task != null)
{
task.isPlaced = true;
task.placementZone.PlaceItem();
_heldFurnitureId = null;
_placedCount++;
QuestManager.Instance.StepCompleted();
if (IsCompleted)
{
FinishQuest();
}
else
{
UpdateQuestState();
}
return;
}
}
}
private void UpdateQuestState()
{
if (IsCompleted)
{
Description = "Everything is in its place!";
}
else if (_heldFurnitureId != null)
{
Description = $"Place the {_heldFurnitureId}.";
}
else
{
Description = $"Arrange the furniture: {_placedCount} / {TotalSteps}";
}
OnQuestStepChanged?.Invoke(Description);
}
private void FinishQuest()
{
UpdateQuestState();
QuestManager.Instance.CompleteQuest();
}
public void AdvanceQuestStep() { }
public void CompleteQuest()
{
if (InteractionHandler.Instance != null)
{
InteractionHandler.Instance.onObjectInteracted -= HandleInteraction;
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 016d18b175bddbe869252563f50f76c7
+31
View File
@@ -0,0 +1,31 @@
using UnityEngine;
using System.Collections.Generic;
[CreateAssetMenu(fileName = "NewQuest", menuName = "Quest System/Quest")]
public class Quest : ScriptableObject
{
[Header("General Info")]
public string questTitle = "Название Квеста";
public bool isCompleted = false;
[Header("Steps")]
public List<QuestStepData> steps = new List<QuestStepData>();
}
[System.Serializable]
public class QuestStepData
{
[Header("Step Info")]
public string stepDescription = "Описание текущей задачи";
[Tooltip("Префаб, который будет создан в сцене для управления логикой этого шага.")]
public GameObject stepPrefab;
[Tooltip("Список конкретных объектов в сцене, с которыми нужно взаимодействовать.")]
public GameObject[] targetObjects;
public bool isCompleted = false;
[Tooltip("ID жуткого события, которое вызывается после завершения этого шага.")]
public string spookyEventID = "";
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 89a79b6cc5da45a18e916924bceac2ec
timeCreated: 1764499632
@@ -0,0 +1,112 @@
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
public class QuestManager : MonoBehaviour
{
public static QuestManager Instance;
[SerializeField] private List<GameObject> questPrefabs;
private List<IQuest> allQuests = new List<IQuest>();
private IQuest _currentQuest;
public IQuest currentQuest => _currentQuest;
public bool isStarted;
public event System.Action<IQuest> OnQuestStarted;
public event System.Action<IQuest> OnQuestCompleted;
public event System.Action<string> OnQuestStepChanged;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
foreach (var qObj in questPrefabs)
{
var q = qObj.GetComponent<IQuest>();
if (q != null) allQuests.Add(q);
}
}
else
{
Destroy(gameObject);
}
}
void Start()
{
if (isStarted) StartFirstQuest();
}
public void StartFirstQuest()
{
if (allQuests.Count > 0) StartQuest(allQuests[0]);
}
public void StartQuest(IQuest quest)
{
if (_currentQuest != null && !_currentQuest.IsCompleted)
{
Debug.Log($"[QuestManager] Quest '{_currentQuest.QuestName}' is not completed yet.");
return;
}
_currentQuest = quest;
_currentQuest.OnQuestStepChanged += HandleQuestStepChanged;
_currentQuest.StartQuest();
Debug.Log($"[QuestManager] Started quest: {quest.QuestName}");
OnQuestStarted?.Invoke(_currentQuest);
HandleQuestStepChanged(_currentQuest.Description);
}
public void CompleteQuest()
{
if (_currentQuest != null)
{
Debug.Log($"[QuestManager] Quest '{_currentQuest.QuestName}' COMPLETED!");
_currentQuest.OnQuestStepChanged -= HandleQuestStepChanged;
_currentQuest.CompleteQuest();
OnQuestCompleted?.Invoke(_currentQuest);
var completedQuest = _currentQuest;
_currentQuest = null;
int completedIndex = allQuests.IndexOf(completedQuest);
if (completedIndex >= 0 && completedIndex + 1 < allQuests.Count)
{
StartQuest(allQuests[completedIndex + 1]);
}
else
{
Debug.Log("[QuestManager] All quests completed!");
}
}
}
public void AdvanceCurrentQuestStep()
{
if (_currentQuest != null)
{
_currentQuest.AdvanceQuestStep();
}
}
public void StepCompleted()
{
if (_currentQuest != null)
{
_currentQuest.AdvanceQuestStep();
}
}
private void HandleQuestStepChanged(string description)
{
OnQuestStepChanged?.Invoke(description);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 44faba98ac5c4c9da043cc53a39b1c6a
timeCreated: 1764499686
@@ -0,0 +1,88 @@
using UnityEngine;
using TMPro; // Необходимо для работы с TextMeshPro
/// <summary>
/// Управляет отображением информации о квесте в UI.
/// Подписывается на события QuestManager и обновляет текстовые поля.
/// </summary>
public class QuestUIController : MonoBehaviour
{
[Header("UI Элементы")]
[Tooltip("Родительский объект всего UI квеста, чтобы его можно было скрывать и показывать.")]
[SerializeField] private GameObject questUIPanel;
[Tooltip("Текстовое поле для описания задания. Например: 'Соберите мусор'.")]
[SerializeField] private TextMeshProUGUI taskDescriptionText;
[Tooltip("Текстовое поле для отображения прогресса. Например: '1 / 3'.")]
[SerializeField] private TextMeshProUGUI taskProgressText;
void Start()
{
// Проверяем, найден ли QuestManager
if (QuestManager.Instance == null)
{
Debug.LogError("QuestUIController не может найти QuestManager.Instance! UI не будет работать.");
// Выключаем панель, чтобы не было видно пустого UI
if(questUIPanel != null) questUIPanel.SetActive(false);
return;
}
// Подписываемся на события QuestManager
QuestManager.Instance.OnQuestStarted += HandleQuestStarted;
QuestManager.Instance.OnQuestCompleted += HandleQuestCompleted;
QuestManager.Instance.OnQuestStepChanged += UpdateQuestDescription;
// Изначально скрываем UI
if(questUIPanel != null) questUIPanel.SetActive(false);
}
private void OnDestroy()
{
// Отписываемся от событий, чтобы избежать ошибок
if (QuestManager.Instance != null)
{
QuestManager.Instance.OnQuestStarted -= HandleQuestStarted;
QuestManager.Instance.OnQuestCompleted -= HandleQuestCompleted;
QuestManager.Instance.OnQuestStepChanged -= UpdateQuestDescription;
}
}
private void HandleQuestStarted(IQuest quest)
{
if(questUIPanel != null) questUIPanel.SetActive(true);
UpdateQuestDescription(quest.Description);
}
private void HandleQuestCompleted(IQuest quest)
{
// Когда квест завершен, просто скрываем панель.
// Можно добавить анимацию или сообщение "Квест выполнен!"
if(questUIPanel != null) questUIPanel.SetActive(false);
}
private void UpdateQuestDescription(string description)
{
if (taskDescriptionText != null)
{
taskDescriptionText.text = description;
}
// Обновляем прогресс, если квест активен
if (QuestManager.Instance.currentQuest != null && !QuestManager.Instance.currentQuest.IsCompleted)
{
if (taskProgressText != null)
{
taskProgressText.text = $"{QuestManager.Instance.currentQuest.CurrentStep} / {QuestManager.Instance.currentQuest.TotalSteps}";
}
}
else
{
if (taskProgressText != null)
{
taskProgressText.text = ""; // Очищаем прогресс, если квеста нет
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6cacb6ef727cdd942b2c045e8aad601c