Files
Cielonos/Assets/Scripts/MainGame/Characters/Player/PlayerInteractionSubcontroller.cs
2026-05-10 11:47:55 -04:00

49 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using Cielonos.Core.Interaction;
using UnityEngine;
namespace Cielonos.MainGame.Characters
{
public class PlayerInteractionSubcontroller : SubcontrollerBase<Player>
{
public Player player => owner;
public List<InteractionChoice> currentChoices = new List<InteractionChoice>();
/// <summary>
/// 当前激活的可交互对象(最近一次进入触发区的对象)。
/// MechanicalTableUI、LogisticsCenterUI 等通过此字段获取驱动它们的场景对象。
/// </summary>
public InteractableObjectBase currentInteractable { get; private set; }
public override void Initialize()
{
base.Initialize();
player.operationSc.OnInteract += () => ExecuteChoice(0);
}
/// <summary>由 InteractionTrigger 在进入触发区时调用,记录当前激活对象。</summary>
public void SetCurrentInteractable(InteractableObjectBase interactable)
{
currentInteractable = interactable;
}
/// <summary>由 InteractionTrigger 在退出触发区时调用,清除当前激活对象。</summary>
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();
}
}
}