update tùm lum tùm la

This commit is contained in:
2026-04-01 02:41:07 +07:00
parent 6ebf140ff6
commit a50209b05c
754 changed files with 136616 additions and 55 deletions

View File

@@ -0,0 +1,37 @@
using UnityEngine;
namespace OnlyScove.Scripts
{
public abstract class BaseInteractable : MonoBehaviour, IInteractable
{
[SerializeField] protected ObjectInteraction interactionData;
private float lastInteractTime;
public virtual string InteractionPrompt => interactionData != null ? interactionData.promptText : "Interact";
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);
}
}

View File

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

View File

@@ -0,0 +1,90 @@
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
// Đ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)
{
Debug.Log("[DoorInteractable] Disabling conflicting CameraOpenDoor script to take full control.");
conflictingScript.enabled = false;
}
}
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}");
}
}
}
}

View File

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

View File

@@ -0,0 +1,28 @@
using UnityEngine;
namespace OnlyScove.Scripts
{
public class HealthInteractable : BaseInteractable
{
[SerializeField] private float healAmount = 25f;
[SerializeField] private bool destroyOnInteract = true;
protected override void PerformInteraction(PlayerStateMachine player)
{
if (player.TryGetComponent(out Health health))
{
health.Heal(healAmount);
Debug.Log($"[Healing] Restored {healAmount} health.");
if (destroyOnInteract)
{
Destroy(gameObject);
}
}
else
{
Debug.LogWarning("[Healing] Player has no Health component!");
}
}
}
}

View File

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

View File

@@ -0,0 +1,25 @@
using UnityEngine;
namespace OnlyScove.Scripts
{
public class LampInteractable : BaseInteractable
{
[SerializeField] private Light targetLight;
[SerializeField] private bool isOn = true;
private void Start()
{
if (targetLight != null)
targetLight.enabled = isOn;
}
protected override void PerformInteraction(PlayerStateMachine player)
{
isOn = !isOn;
if (targetLight != null)
targetLight.enabled = isOn;
Debug.Log($"[Lamp] Toggled {(isOn ? "ON" : "OFF")}");
}
}
}

View File

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