This commit is contained in:
2026-06-14 23:55:20 +07:00
parent d731f962a3
commit 132def45c7
16 changed files with 380 additions and 77 deletions

View File

@@ -4,34 +4,49 @@ 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 : "Interact";
public virtual string InteractionPrompt => interactionData != null ? interactionData.promptText : "Tương tác";
// public virtual void OnInteract(PlayerStateMachine player)
// {
// if (Time.time < lastInteractTime + (interactionData != null ? interactionData.interactionCooldown : 0f))
// return;
//
// lastInteractTime = Time.time;
//
// // Play sound if assigned
// if (interactionData != null && interactionData.interactionSound != null)
// {
// AudioSource.PlayClipAtPoint(interactionData.interactionSound, transform.position);
// }
//
// // Spawn VFX if assigned
// if (interactionData != null && interactionData.interactionVFX != null)
// {
// Instantiate(interactionData.interactionVFX, transform.position, Quaternion.identity);
// }
//
// PerformInteraction(player);
// }
//
// protected abstract void PerformInteraction(PlayerStateMachine player);
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

@@ -51,7 +51,6 @@ namespace OnlyScove.Scripts
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
// Điều này giúp hệ thống của bạn chiếm quyền điều khiển hoàn toàn
var conflictingScript = Object.FindFirstObjectByType<CameraDoorScript.CameraOpenDoor>();
if (conflictingScript != null)
{
@@ -60,31 +59,24 @@ namespace OnlyScove.Scripts
}
}
// protected override void PerformInteraction(PlayerStateMachine player)
// {
// Debug.Log($"[Interaction] PerformInteraction CALLED on {gameObject.name}!");
//
// // 1. Ưu tiên script của Door Pack (Wood Door Script)
// if (woodDoorScript != null)
// {
// Debug.Log($"[Interaction] Calling woodDoorScript.OpenDoor() on {gameObject.name}. Previous state: {woodDoorScript.open}");
// woodDoorScript.OpenDoor();
// isOpen = woodDoorScript.open;
// Debug.Log($"[Interaction] New state: {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);
// Debug.Log($"[Interaction] Triggered Animator: {boolParameterName} = {isOpen}");
// }
// else
// {
// Debug.LogError($"[Interaction] FAILED: No woodDoorScript or animator found on {gameObject.name}");
// }
// }
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

@@ -44,14 +44,14 @@ namespace OnlyScove.Scripts
UpdateLightState();
}
// protected override void PerformInteraction(PlayerStateMachine player)
// {
// 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")}");
// }
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()
{