refactor(Connect): 重构连接体系,实现一个物体拥有多个连接线

This commit is contained in:
2025-10-20 19:40:55 +08:00
parent bb2c5aa436
commit 0a1aa83425
11 changed files with 187 additions and 140 deletions

View File

@@ -1,11 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Script.Gameplay.Interface;
using Script.Gameplay.Connect;
namespace Script.Gameplay.Facility
{
public class ButtonInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable
public class ButtonInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable, ISignalSender
{
#region Interactable
@@ -20,7 +21,7 @@ namespace Script.Gameplay.Facility
public void Interact(GameObject interactor)
{
if (!Interactable) return;
StartCoroutine(SendSignalCoroutine(interactor));
StartCoroutine(SendSignalCoroutine());
Debug.Log("Button pressed");
}
@@ -34,14 +35,15 @@ namespace Script.Gameplay.Facility
// 可选:取消高亮
}
private IEnumerator SendSignalCoroutine(GameObject sender)
private IEnumerator SendSignalCoroutine()
{
SendSignal(true, sender);
SendSignal(true);
Interactable = false;
// 按钮压下的动画或效果可以在这里添加
yield return new WaitForSeconds(signalDuration);
SendSignal(false, sender);
SendSignal(false);
Interactable = true;
// 按钮弹起的动画或效果可以在这里添加
}
@@ -81,27 +83,30 @@ namespace Script.Gameplay.Facility
return transform.position;
}
public GameObject GetGameObject()
{
return gameObject;
}
public string GetConnectableName()
{
return gameObject.name;
}
public ConnectionLine OutputConnectionLine { get; set; }
public ConnectionLine InputConnectionLine { get; set; }
public bool IsConnectedOutput { get; set; }
public bool IsConnectedInput { get; set; }
public void ReceiveSignal(bool active, GameObject sender)
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
public void SignalActive(bool active, GameObject sender)
{
// 按钮通常不响应输入信号,可留空或自定义逻辑
// 按钮通常不接收信号,因此这里可以留空
}
public void SendSignal(bool active, GameObject sender)
public void SendSignal(bool active)
{
if (OutputConnectionLine != null)
if (ConnectionLines != null)
{
OutputConnectionLine.ReceiveSignal(active);
foreach (var line in ConnectionLines)
{
line.SignalActive(active, this.gameObject);
}
}
}