Files
2025TapTapGameJam/Assets/Script/Gameplay/Facility/PressurePlateController.cs

88 lines
2.3 KiB
C#
Raw Normal View History

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
{
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;
bool hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity,
detectLayer);
2025-10-20 09:54:58 +08:00
if (hasObject != lastState)
{
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
public void OnGazeEnter()
{
}
public void OnGazeExit()
{
}
2025-10-20 09:54:58 +08:00
public Vector3 GetPosition() => transform.position;
public GameObject GetGameObject()
{
return gameObject;
}
2025-10-20 09:54:58 +08:00
public string GetConnectableName() => gameObject.name;
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
2025-10-20 09:54:58 +08:00
public void SignalActive(bool active, GameObject sender)
2025-10-20 09:54:58 +08:00
{
//
2025-10-20 09:54:58 +08:00
}
public void SendSignal(bool active)
2025-10-20 09:54:58 +08:00
{
if (ConnectionLines != null)
2025-10-20 09:54:58 +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
}
}