This commit is contained in:
2026-06-18 03:04:52 +07:00
parent e545e719c6
commit 81a6798e96
2986 changed files with 4229 additions and 605733 deletions

View File

@@ -1,52 +0,0 @@
using UnityEngine;
namespace OnlyScove.Scripts
{
public abstract class BaseInteractable : MonoBehaviour, IInteractable
{
[Header("Interaction Settings")]
[SerializeField] protected ObjectInteraction interactionData;
private float lastInteractTime;
public virtual string InteractionPrompt => interactionData != null ? interactionData.promptText : "Tương tác";
public virtual void OnInteract(GameObject interactor)
{
// Kiểm tra Cooldown
float cooldown = interactionData != null ? interactionData.interactionCooldown : 0.5f;
if (Time.time < lastInteractTime + cooldown)
return;
lastInteractTime = Time.time;
// Phát âm thanh nếu có
if (interactionData != null && interactionData.interactionSound != null)
{
AudioSource.PlayClipAtPoint(interactionData.interactionSound, transform.position);
}
// Tạo hiệu ứng VFX nếu có
if (interactionData != null && interactionData.interactionVFX != null)
{
Instantiate(interactionData.interactionVFX, transform.position, Quaternion.identity);
}
// Gọi logic tương tác cụ thể của từng loại vật thể
PerformInteraction(interactor);
}
public virtual void OnHoverEnter()
{
// Sẽ thêm logic Highlight ở Giai đoạn 4
}
public virtual void OnHoverExit()
{
// Sẽ xóa logic Highlight ở Giai đoạn 4
}
// Logic cụ thể bắt buộc các lớp con (Cửa, Cần gạt...) phải triển khai
protected abstract void PerformInteraction(GameObject interactor);
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 77496ebe7c1d9c74ebbe6c390d147e04

View File

@@ -1,82 +0,0 @@
using UnityEngine;
using DoorScript; // Namespace của gói Wood Door Pack
namespace OnlyScove.Scripts
{
public class DoorInteractable : BaseInteractable
{
[Header("Door Component (Optional)")]
[SerializeField] private Door woodDoorScript;
[Header("Animator (Optional)")]
[SerializeField] private Animator animator;
[SerializeField] private string boolParameterName = "IsOpen";
private bool isOpen = false;
// Ghi đè Prompt để hiện trạng thái Mở/Đóng tùy vào cửa đang như thế nào
public override string InteractionPrompt
{
get
{
bool currentOpen = woodDoorScript != null ? woodDoorScript.open : isOpen;
return (currentOpen ? "Đóng " : "Mở ") + (interactionData != null ? interactionData.promptText : "Cửa");
}
}
private void Awake()
{
Debug.Log($"[DoorInteractable] Initializing on {gameObject.name}");
// 1. Tìm Door script (Tìm mọi nơi: bản thân, con, cha)
if (woodDoorScript == null) woodDoorScript = GetComponent<Door>();
if (woodDoorScript == null) woodDoorScript = GetComponentInChildren<Door>(true);
if (woodDoorScript == null) woodDoorScript = GetComponentInParent<Door>();
if (woodDoorScript != null)
{
Debug.Log($"[DoorInteractable] SUCCESS: Found Door script on {woodDoorScript.gameObject.name}");
// Đảm bảo có AudioSource
var source = woodDoorScript.GetComponent<AudioSource>();
if (source == null) source = woodDoorScript.gameObject.AddComponent<AudioSource>();
woodDoorScript.asource = source;
isOpen = woodDoorScript.open;
}
// 2. Tìm Animator (Tìm mọi nơi)
if (animator == null) animator = GetComponent<Animator>();
if (animator == null) animator = GetComponentInChildren<Animator>(true);
if (animator == null) animator = GetComponentInParent<Animator>();
// 3. TỰ ĐỘNG TẮT SCRIPT XUNG ĐỘT (CameraOpenDoor) nếu nó đang tồn tại trên Camera
var conflictingScript = Object.FindFirstObjectByType<CameraDoorScript.CameraOpenDoor>();
if (conflictingScript != null)
{
Debug.Log("[DoorInteractable] Disabling conflicting CameraOpenDoor script to take full control.");
conflictingScript.enabled = false;
}
}
protected override void PerformInteraction(GameObject interactor)
{
Debug.Log($"[Interaction] PerformInteraction CALLED on {gameObject.name}!");
// 1. Ưu tiên script của Door Pack (Wood Door Script)
if (woodDoorScript != null)
{
woodDoorScript.OpenDoor();
isOpen = woodDoorScript.open;
return;
}
// 2. Nếu không có script Pack mới dùng Animator
if (animator != null)
{
isOpen = !isOpen;
animator.SetBool(boolParameterName, isOpen);
}
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: d41bcdbf11a6d6c4bb61a32e85d1635f

View File

@@ -1,81 +0,0 @@
using UnityEngine;
using System.Collections.Generic;
namespace OnlyScove.Scripts
{
public class LampInteractable : BaseInteractable
{
[Header("Light Settings")] [SerializeField]
private List<Light> targetLights = new List<Light>(); // Cho phép gán nhiều đèn
[SerializeField] private bool isOn = true;
[Header("Emission Settings (Optional)")] [SerializeField]
private MeshRenderer lampRenderer;
[SerializeField] private int materialIndex = 0;
[SerializeField] private string emissionColorProperty = "_EmissionColor";
private Material lampMaterial;
private Color originalEmissionColor;
public override string InteractionPrompt
{
get
{
string action = isOn ? "Tắt " : "Bật ";
string name = interactionData != null ? interactionData.promptText : "Đèn";
return action + name;
}
}
private void Start()
{
// Khởi tạo Material (tạo bản thực thi riêng để không lỗi Shader)
if (lampRenderer != null && materialIndex < lampRenderer.materials.Length)
{
lampMaterial = lampRenderer.materials[materialIndex];
if (lampMaterial.HasProperty(emissionColorProperty))
{
originalEmissionColor = lampMaterial.GetColor(emissionColorProperty);
}
}
UpdateLightState();
}
protected override void PerformInteraction(GameObject interactor)
{
isOn = !isOn;
UpdateLightState();
// Log cực mạnh để bạn kiểm tra Console
Debug.LogWarning($"<color=yellow>[Lamp]</color> Đèn đã chuyển sang: {(isOn ? "BẬT" : "TẮT")}");
}
private void UpdateLightState()
{
// Bật/Tắt tất cả các đèn trong danh sách
foreach (var light in targetLights)
{
if (light != null) light.enabled = isOn;
}
// Bật/Tắt hiệu ứng phát sáng của vật liệu
if (lampMaterial != null)
{
if (isOn)
{
lampMaterial.SetColor(emissionColorProperty, originalEmissionColor);
lampMaterial.EnableKeyword("_EMISSION");
}
else
{
// Tắt hẳn màu phát sáng
lampMaterial.SetColor(emissionColorProperty, Color.black);
lampMaterial.DisableKeyword("_EMISSION");
}
}
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 8ad2ce50b06995b49b7380826f67114d