refactor(Connect): 重构连接体系,实现一个物体拥有多个连接线
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Script.Gameplay.Interface;
|
||||
using Script.Gameplay.Connect;
|
||||
|
||||
namespace Script.Gameplay.Facility
|
||||
{
|
||||
public class PressurePlateController : MonoBehaviour, IEditableComponent, IConnectable
|
||||
public class PressurePlateController : MonoBehaviour, IEditableComponent, IConnectable, ISignalSender
|
||||
{
|
||||
[SerializeField] private bool isActive = true;
|
||||
[SerializeField] private LayerMask detectLayer = ~0; // 检测所有层,可在Inspector中指定
|
||||
@@ -16,10 +17,11 @@ namespace Script.Gameplay.Facility
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!isActive) return;
|
||||
bool hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity, detectLayer);
|
||||
bool hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity,
|
||||
detectLayer);
|
||||
if (hasObject != lastState)
|
||||
{
|
||||
SendSignal(hasObject, gameObject);
|
||||
SendSignal(hasObject);
|
||||
lastState = hasObject;
|
||||
}
|
||||
}
|
||||
@@ -39,25 +41,37 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,5 +85,4 @@ namespace Script.Gameplay.Facility
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user