코드 리팩토링
재사용성 및 확장성을 고려하여 코드 전반을 리팩토링함
This commit is contained in:
63
Assets/Scripts/Items/IUsableItem.cs
Normal file
63
Assets/Scripts/Items/IUsableItem.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for items that can be used/activated by the player.
|
||||
/// </summary>
|
||||
public interface IUsableItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Check if the item can be used.
|
||||
/// </summary>
|
||||
/// <param name="user">The GameObject using the item (player)</param>
|
||||
/// <param name="target">Optional target for the use action</param>
|
||||
/// <returns>True if the item can be used</returns>
|
||||
bool CanUse(GameObject user, GameObject target);
|
||||
|
||||
/// <summary>
|
||||
/// Use the item.
|
||||
/// </summary>
|
||||
/// <param name="user">The GameObject using the item (player)</param>
|
||||
/// <param name="target">Optional target for the use action</param>
|
||||
void Use(GameObject user, GameObject target);
|
||||
|
||||
/// <summary>
|
||||
/// Get the action descriptor for using this item.
|
||||
/// </summary>
|
||||
ActionDescriptor GetUseAction();
|
||||
|
||||
/// <summary>
|
||||
/// Whether using this item consumes it (reduces stack count).
|
||||
/// </summary>
|
||||
bool IsConsumable { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for items that can be equipped on the player.
|
||||
/// </summary>
|
||||
public interface IEquippableItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the equipment prefab to spawn.
|
||||
/// </summary>
|
||||
GameObject GetEquipmentPrefab();
|
||||
|
||||
/// <summary>
|
||||
/// Get position offset for equipment placement.
|
||||
/// </summary>
|
||||
Vector3 GetPositionOffset();
|
||||
|
||||
/// <summary>
|
||||
/// Get rotation offset for equipment placement.
|
||||
/// </summary>
|
||||
Vector3 GetRotationOffset();
|
||||
|
||||
/// <summary>
|
||||
/// Get the name of the attachment point on the character.
|
||||
/// </summary>
|
||||
string GetAttachmentPointName();
|
||||
|
||||
/// <summary>
|
||||
/// Find the attachment point transform on a user.
|
||||
/// </summary>
|
||||
Transform FindAttachmentPoint(GameObject user);
|
||||
}
|
||||
2
Assets/Scripts/Items/IUsableItem.cs.meta
Normal file
2
Assets/Scripts/Items/IUsableItem.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 686008e086e9d2247b33d5828e0efa5f
|
||||
67
Assets/Scripts/Items/ItemBehavior.cs
Normal file
67
Assets/Scripts/Items/ItemBehavior.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for item behaviors. Allows different items to have
|
||||
/// completely different use effects without modifying ItemData.
|
||||
/// This is the Strategy pattern for item actions.
|
||||
/// </summary>
|
||||
public abstract class ItemBehavior : ScriptableObject
|
||||
{
|
||||
[Header("Basic Settings")]
|
||||
[SerializeField] protected string behaviorName = "Use";
|
||||
[SerializeField] protected float duration = 0.5f;
|
||||
[SerializeField] protected string animTrigger = "Use";
|
||||
[SerializeField] protected float animSpeed = 1f;
|
||||
[SerializeField] protected float impactDelay = 0.2f;
|
||||
[SerializeField] protected bool canRepeat = false;
|
||||
|
||||
[Header("Effects")]
|
||||
[SerializeField] protected AudioClip useSound;
|
||||
[SerializeField] protected GameObject useEffect;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this behavior consumes the item when used.
|
||||
/// </summary>
|
||||
public virtual bool IsConsumable => false;
|
||||
|
||||
/// <summary>
|
||||
/// Check if this behavior can be used with the given user and target.
|
||||
/// </summary>
|
||||
/// <param name="user">The player/entity using the item</param>
|
||||
/// <param name="target">Optional target of the use</param>
|
||||
/// <returns>True if the behavior can be executed</returns>
|
||||
public abstract bool CanUse(GameObject user, GameObject target);
|
||||
|
||||
/// <summary>
|
||||
/// Execute the behavior's effect.
|
||||
/// </summary>
|
||||
/// <param name="user">The player/entity using the item</param>
|
||||
/// <param name="target">Optional target of the use</param>
|
||||
public abstract void Use(GameObject user, GameObject target);
|
||||
|
||||
/// <summary>
|
||||
/// Get the action descriptor for this behavior.
|
||||
/// </summary>
|
||||
public virtual ActionDescriptor GetActionDescriptor()
|
||||
{
|
||||
return new ActionDescriptor
|
||||
{
|
||||
ActionName = behaviorName,
|
||||
Duration = duration,
|
||||
AnimTrigger = animTrigger,
|
||||
AnimSpeed = animSpeed,
|
||||
ImpactDelay = impactDelay,
|
||||
CanRepeat = canRepeat,
|
||||
SoundEffect = useSound,
|
||||
ParticleEffect = useEffect
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a description of why the behavior cannot be used.
|
||||
/// </summary>
|
||||
public virtual string GetBlockedReason(GameObject user, GameObject target)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Items/ItemBehavior.cs.meta
Normal file
2
Assets/Scripts/Items/ItemBehavior.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73a8d5e271a199f4598ae20f5b20a466
|
||||
Reference in New Issue
Block a user