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,10 +1,11 @@
using System.Collections.Generic;
using UnityEngine;
using Script.Gameplay.Interface;
using Script.Gameplay.Connect;
namespace Script.Gameplay.Facility
{
public class LeverInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable
public class LeverInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable, ISignalSender
{
#region Interactable
@@ -20,7 +21,7 @@ namespace Script.Gameplay.Facility
{
if (!Interactable) return;
isPulled = !isPulled;
SendSignal(isPulled, interactor);
SendSignal(isPulled);
// 可选:拉杆动画
Debug.Log(isPulled ? "Lever pulled down" : "Lever reset");
}
@@ -58,29 +59,39 @@ namespace Script.Gameplay.Facility
#region Connectable
public void OnGazeEnter() { }
public void OnGazeExit() { }
public Vector3 GetPosition() => transform.position;
public string GetConnectableName() => 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 void OnGazeEnter()
{
// 拉杆通常不响应输入信号
}
public void SendSignal(bool active, GameObject sender)
public void OnGazeExit()
{
if (OutputConnectionLine != null)
}
public Vector3 GetPosition() => transform.position;
public GameObject GetGameObject()
{
return gameObject;
}
public string GetConnectableName() => gameObject.name;
public List<ConnectionLine> ConnectionLines { get; set; }= new List<ConnectionLine>();
public void SignalActive(bool active, GameObject sender)
{
//
}
public void SendSignal(bool active)
{
if (ConnectionLines != null)
{
OutputConnectionLine.ReceiveSignal(active);
foreach (var line in ConnectionLines)
{
line.SignalActive(active, this.gameObject);
}
}
}
#endregion
}
}
}