using System; using System.Collections.Generic; using Cielonos.Core.Interaction; using UnityEngine; namespace Cielonos.MainGame.Characters { public class PlayerInteractionSubcontroller : SubcontrollerBase { public Player player => owner; public List currentChoices = new List(); /// /// 当前激活的可交互对象(最近一次进入触发区的对象)。 /// MechanicalTableUI、LogisticsCenterUI 等通过此字段获取驱动它们的场景对象。 /// public InteractableObjectBase currentInteractable { get; private set; } public override void Initialize() { base.Initialize(); player.operationSc.OnInteract += () => ExecuteChoice(0); } /// 由 InteractionTrigger 在进入触发区时调用,记录当前激活对象。 public void SetCurrentInteractable(InteractableObjectBase interactable) { currentInteractable = interactable; } /// 由 InteractionTrigger 在退出触发区时调用,清除当前激活对象。 public void RemoveCurrentInteractable(InteractableObjectBase interactable) { if (currentInteractable == interactable) currentInteractable = null; } public void ExecuteChoice(int index = 0) { if (index < 0 || index >= currentChoices.Count) { Debug.LogWarning("Invalid interaction choice index."); return; } var choice = currentChoices[index]; choice.action?.Invoke(); } } }