코드 리팩토링

재사용성 및 확장성을 고려하여 코드 전반을 리팩토링함
This commit is contained in:
2026-01-21 01:45:15 +09:00
parent b4ac8f600f
commit db5db4b106
45 changed files with 2775 additions and 248 deletions

View File

@@ -1,6 +1,172 @@
using UnityEngine;
/// <summary>
/// Types of interactions available in the game.
/// </summary>
public enum InteractionType
{
Generic,
Pickup,
Use,
Talk,
Enter,
Build,
Open,
Activate
}
/// <summary>
/// Contains preview information about an interaction for UI display.
/// </summary>
[System.Serializable]
public struct InteractionPreview
{
/// <summary>
/// The action verb (e.g., "Pick up", "Enter", "Use").
/// </summary>
public string ActionVerb;
/// <summary>
/// The name of the target object (e.g., "Iron Ore", "Tunnel").
/// </summary>
public string TargetName;
/// <summary>
/// Optional icon to display in UI.
/// </summary>
public Sprite Icon;
/// <summary>
/// The type of interaction.
/// </summary>
public InteractionType Type;
/// <summary>
/// Whether this interaction requires holding the button.
/// </summary>
public bool RequiresHold;
/// <summary>
/// Duration to hold if RequiresHold is true.
/// </summary>
public float HoldDuration;
/// <summary>
/// Input hint to display (e.g., "[F]", "[E]").
/// </summary>
public string InputHint;
/// <summary>
/// Create a simple interaction preview.
/// </summary>
public static InteractionPreview Simple(string actionVerb, string targetName,
InteractionType type = InteractionType.Generic)
{
return new InteractionPreview
{
ActionVerb = actionVerb,
TargetName = targetName,
Type = type,
RequiresHold = false,
HoldDuration = 0f,
InputHint = "[F]"
};
}
/// <summary>
/// Create a pickup interaction preview.
/// </summary>
public static InteractionPreview Pickup(string itemName, Sprite icon = null)
{
return new InteractionPreview
{
ActionVerb = "Pick up",
TargetName = itemName,
Icon = icon,
Type = InteractionType.Pickup,
RequiresHold = false,
InputHint = "[F]"
};
}
/// <summary>
/// Create an enter/use interaction preview.
/// </summary>
public static InteractionPreview Enter(string targetName)
{
return new InteractionPreview
{
ActionVerb = "Enter",
TargetName = targetName,
Type = InteractionType.Enter,
RequiresHold = false,
InputHint = "[F]"
};
}
/// <summary>
/// Create a hold-to-interact preview.
/// </summary>
public static InteractionPreview Hold(string actionVerb, string targetName, float duration,
InteractionType type = InteractionType.Use)
{
return new InteractionPreview
{
ActionVerb = actionVerb,
TargetName = targetName,
Type = type,
RequiresHold = true,
HoldDuration = duration,
InputHint = "[Hold F]"
};
}
/// <summary>
/// Get the full display string (e.g., "[F] Pick up Iron Ore").
/// </summary>
public string GetDisplayString()
{
return $"{InputHint} {ActionVerb} {TargetName}";
}
}
/// <summary>
/// Interface for objects that can be interacted with by the player.
/// </summary>
public interface IInteractable
{
/// <summary>
/// Perform the interaction.
/// </summary>
/// <param name="interactor">The GameObject performing the interaction (usually the player)</param>
void Interact(GameObject interactor);
}
/// <summary>
/// Get preview information about this interaction for UI display.
/// Default implementation returns a generic preview.
/// </summary>
InteractionPreview GetInteractionPreview()
{
return InteractionPreview.Simple("Interact", "Object");
}
/// <summary>
/// Check if this object can currently be interacted with.
/// Default implementation always returns true.
/// </summary>
/// <param name="interactor">The GameObject attempting to interact</param>
/// <returns>True if interaction is possible</returns>
bool CanInteract(GameObject interactor)
{
return true;
}
/// <summary>
/// Get the world position of this interactable for distance calculations.
/// Default implementation returns zero vector (override in implementation).
/// </summary>
Vector3 GetInteractionPoint()
{
return Vector3.zero;
}
}