first commit
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(BoxCollider))]
|
||||
public class Note : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string noteTitle = "Записка";
|
||||
[SerializeField] private string noteContent = "Текст записки.";
|
||||
[SerializeField] private Renderer noteRenderer;
|
||||
[SerializeField] private Material defaultMaterial;
|
||||
[SerializeField] private Material highlightMaterial;
|
||||
|
||||
private bool playerInRange;
|
||||
private bool collected;
|
||||
|
||||
public void Configure(
|
||||
string title,
|
||||
string content,
|
||||
Renderer targetRenderer,
|
||||
Material baseMaterial,
|
||||
Material selectedMaterial)
|
||||
{
|
||||
noteTitle = title;
|
||||
noteContent = content;
|
||||
noteRenderer = targetRenderer;
|
||||
defaultMaterial = baseMaterial;
|
||||
highlightMaterial = selectedMaterial;
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
var boxCollider = GetComponent<BoxCollider>();
|
||||
boxCollider.isTrigger = true;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var boxCollider = GetComponent<BoxCollider>();
|
||||
boxCollider.isTrigger = true;
|
||||
|
||||
if (noteRenderer == null)
|
||||
{
|
||||
noteRenderer = GetComponentInChildren<Renderer>();
|
||||
}
|
||||
|
||||
if (defaultMaterial == null && noteRenderer != null)
|
||||
{
|
||||
defaultMaterial = noteRenderer.sharedMaterial;
|
||||
}
|
||||
|
||||
SetHighlighted(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (collected || !playerInRange || GameUIState.IsAnyBlockingUIOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.E))
|
||||
{
|
||||
CollectNote();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (collected || !other.CompareTag("Player"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
playerInRange = true;
|
||||
SetHighlighted(true);
|
||||
InteractionPromptUI.Instance?.ShowPrompt(this, "Нажмите E");
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (!other.CompareTag("Player"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
playerInRange = false;
|
||||
SetHighlighted(false);
|
||||
InteractionPromptUI.Instance?.HidePrompt(this);
|
||||
}
|
||||
|
||||
private void CollectNote()
|
||||
{
|
||||
collected = true;
|
||||
playerInRange = false;
|
||||
|
||||
Inventory.Instance?.AddNote(new NoteData(noteTitle, noteContent));
|
||||
NoteUI.Instance?.ShowNote(noteTitle, noteContent);
|
||||
QuestManager.Instance?.NoteCollected();
|
||||
InteractionPromptUI.Instance?.HidePrompt(this);
|
||||
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void SetHighlighted(bool highlighted)
|
||||
{
|
||||
if (noteRenderer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var targetMaterial = highlighted && highlightMaterial != null ? highlightMaterial : defaultMaterial;
|
||||
|
||||
if (targetMaterial != null)
|
||||
{
|
||||
noteRenderer.material = targetMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user