Files
2026-06-22 16:18:34 +02:00

49 lines
1.5 KiB
C#

using UnityEngine;
namespace Ashwild.Player
{
/// <summary>
/// Snaps a held-item prefab to a fixed local pose inside the hand holder. Added by
/// composition next to a behaviour (tool, consumable) or alone on a decorative
/// item — it carries no use logic, only how the model sits in the hand. Applied in
/// Awake because Instantiate into the holder overrides the prefab's local transform.
/// </summary>
[DisallowMultipleComponent]
public class HeldItemOffset : MonoBehaviour
{
#region Serialized Fields
[Header("Local Pose In Hand")]
/// <summary>
/// Local position the model takes once equipped in the holder.
/// </summary>
[SerializeField] private Vector3 positionOffset;
/// <summary>
/// Local euler rotation the model takes once equipped in the holder.
/// </summary>
[SerializeField] private Vector3 rotationOffset;
/// <summary>
/// Local scale the model takes once equipped (defaults to no scaling).
/// </summary>
[SerializeField] private Vector3 scale = Vector3.one;
#endregion
#region Unity Lifecycle
/// <summary>
/// Forces the authored local pose right after the prefab is spawned in the hand.
/// </summary>
private void Awake()
{
transform.localPosition = positionOffset;
transform.localRotation = Quaternion.Euler(rotationOffset);
transform.localScale = scale;
}
#endregion
}
}