refactor():重构编辑系统,不再需要添加额外的脚本作为可编辑的入口了

This commit is contained in:
2025-10-21 16:40:41 +08:00
parent 1ce3d1a0d8
commit 93b83b3af3
37 changed files with 186 additions and 199 deletions

View File

@@ -0,0 +1,88 @@
using System.Collections.Generic;
using UnityEngine;
using Script.Gameplay.Interface;
using Script.Gameplay.Connect;
namespace Script.Gameplay.Edit
{
public class PressurePlateController : MonoBehaviour, IEditableComponent, IConnectable, ISignalSender
{
[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);
lastState = hasObject;
}
}
#region EditableComponent
public bool IsEditableActive
{
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 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)
{
foreach (var line in ConnectionLines)
{
line.SignalActive(active, this.gameObject);
}
}
}
#endregion
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireCube(transform.position + plateOffset, plateSize);
}
#endif
}
}