57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace Ashwild.Cooking
|
|
{
|
|
/// <summary>
|
|
/// One cooking spot on a CookingStation: a pure visual anchor. It only shows or clears the
|
|
/// food model snapped to its Transform. All cooking state and timing now live on the
|
|
/// (server-authoritative) station, which drives this slot from replicated state.
|
|
/// </summary>
|
|
[DisallowMultipleComponent]
|
|
public class CookingSlot : MonoBehaviour
|
|
{
|
|
#region State
|
|
|
|
/// <summary>
|
|
/// The food model currently shown on this slot, if any.
|
|
/// </summary>
|
|
private GameObject visual;
|
|
|
|
#endregion
|
|
|
|
#region Public API
|
|
|
|
/// <summary>
|
|
/// Shows a fresh model instance snapped to this slot, replacing any previous one. Its
|
|
/// colliders are disabled so the food never steals the interaction ray from the station.
|
|
/// A null prefab simply clears the slot.
|
|
/// </summary>
|
|
public void ShowModel(GameObject prefab)
|
|
{
|
|
ClearModel();
|
|
if (prefab == null) return;
|
|
|
|
visual = Instantiate(prefab, transform);
|
|
visual.transform.localPosition = Vector3.zero;
|
|
visual.transform.localRotation = Quaternion.identity;
|
|
|
|
Collider[] cols = visual.GetComponentsInChildren<Collider>();
|
|
for (int i = 0; i < cols.Length; i++) cols[i].enabled = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes the current model instance if one is shown.
|
|
/// </summary>
|
|
public void ClearModel()
|
|
{
|
|
if (visual != null)
|
|
{
|
|
Destroy(visual);
|
|
visual = null;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|