2025-10-20 19:40:55 +08:00
|
|
|
|
using System.Collections.Generic;
|
2025-10-20 09:54:58 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Script.Gameplay.Interface;
|
|
|
|
|
using Script.Gameplay.Connect;
|
|
|
|
|
|
|
|
|
|
namespace Script.Gameplay.Facility
|
|
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
|
public class PressurePlateController : MonoBehaviour, IEditableComponent, IConnectable, ISignalSender
|
2025-10-20 09:54:58 +08:00
|
|
|
|
{
|
|
|
|
|
[SerializeField] private bool isActive = true;
|
|
|
|
|
[SerializeField] private LayerMask detectLayer = ~0; // 检测所有层,可在Inspector中指定
|
|
|
|
|
[SerializeField] private Vector3 plateSize = new Vector3(1, 0.2f, 1);
|
|
|
|
|
[SerializeField] private Vector3 plateOffset = Vector3.up * 0.1f;
|
|
|
|
|
|
|
|
|
|
private bool lastState = false;
|
|
|
|
|
|
|
|
|
|
private void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
if (!isActive) return;
|
2025-10-20 19:40:55 +08:00
|
|
|
|
bool hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity,
|
|
|
|
|
detectLayer);
|
2025-10-20 09:54:58 +08:00
|
|
|
|
if (hasObject != lastState)
|
|
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
|
SendSignal(hasObject);
|
2025-10-20 09:54:58 +08:00
|
|
|
|
lastState = hasObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region EditableComponent
|
|
|
|
|
|
|
|
|
|
public bool IsActive
|
|
|
|
|
{
|
|
|
|
|
get => isActive;
|
|
|
|
|
set => isActive = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ComponentName { get; set; } = "PressurePlate";
|
|
|
|
|
public LockLevel LockLevel => LockLevel.Red;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Connectable
|
|
|
|
|
|
2025-10-20 19:40:55 +08:00
|
|
|
|
public void OnGazeEnter()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnGazeExit()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-20 09:54:58 +08:00
|
|
|
|
public Vector3 GetPosition() => transform.position;
|
2025-10-20 19:40:55 +08:00
|
|
|
|
|
|
|
|
|
public GameObject GetGameObject()
|
|
|
|
|
{
|
|
|
|
|
return gameObject;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-20 09:54:58 +08:00
|
|
|
|
public string GetConnectableName() => gameObject.name;
|
2025-10-20 19:40:55 +08:00
|
|
|
|
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
|
2025-10-20 09:54:58 +08:00
|
|
|
|
|
2025-10-20 19:40:55 +08:00
|
|
|
|
public void SignalActive(bool active, GameObject sender)
|
2025-10-20 09:54:58 +08:00
|
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
|
//
|
2025-10-20 09:54:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-10-20 19:40:55 +08:00
|
|
|
|
public void SendSignal(bool active)
|
2025-10-20 09:54:58 +08:00
|
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
|
if (ConnectionLines != null)
|
2025-10-20 09:54:58 +08:00
|
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
|
foreach (var line in ConnectionLines)
|
|
|
|
|
{
|
|
|
|
|
line.SignalActive(active, this.gameObject);
|
|
|
|
|
}
|
2025-10-20 09:54:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
private void OnDrawGizmosSelected()
|
|
|
|
|
{
|
|
|
|
|
Gizmos.color = Color.yellow;
|
|
|
|
|
Gizmos.DrawWireCube(transform.position + plateOffset, plateSize);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2025-10-20 19:40:55 +08:00
|
|
|
|
}
|