feat(PressurePlate):实现压力板
This commit is contained in:
75
Assets/Script/Gameplay/Facility/PressurePlateController.cs
Normal file
75
Assets/Script/Gameplay/Facility/PressurePlateController.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using Script.Gameplay.Interface;
|
||||
using Script.Gameplay.Connect;
|
||||
|
||||
namespace Script.Gameplay.Facility
|
||||
{
|
||||
public class PressurePlateController : MonoBehaviour, IEditableComponent, IConnectable
|
||||
{
|
||||
[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);
|
||||
if (hasObject != lastState)
|
||||
{
|
||||
SendSignal(hasObject, gameObject);
|
||||
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() { }
|
||||
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 SendSignal(bool active, GameObject sender)
|
||||
{
|
||||
if (OutputConnectionLine != null)
|
||||
{
|
||||
OutputConnectionLine.ReceiveSignal(active);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireCube(transform.position + plateOffset, plateSize);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2557c7d42f7a4d8896712ab2ae980b6f
|
||||
timeCreated: 1760924285
|
Reference in New Issue
Block a user