feat(Lever):实现拉杆

This commit is contained in:
2025-10-20 10:01:40 +08:00
parent bb16550a0f
commit 3593a9f0e8
5 changed files with 383 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
using UnityEngine;
using Script.Gameplay.Interface;
using Script.Gameplay.Connect;
namespace Script.Gameplay.Facility
{
public class LeverInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable
{
#region Interactable
public bool Interactable = true;
private bool isPulled = false;
public string GetInteractPrompt()
{
return "按F拉动拉杆";
}
public void Interact(GameObject interactor)
{
if (!Interactable) return;
isPulled = !isPulled;
SendSignal(isPulled, interactor);
// 可选:拉杆动画
Debug.Log(isPulled ? "Lever pulled down" : "Lever reset");
}
public void OnGazeEnter(GameObject editor)
{
// 可选:高亮拉杆
}
public void OnGazeExit(GameObject editor)
{
// 可选:取消高亮
}
#endregion
#region EditableComponent
[SerializeField] private bool isActive = true;
public bool IsActive
{
get => isActive;
set
{
isActive = value;
Interactable = isActive;
}
}
public string ComponentName { get; set; } = "Lever";
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
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6b9b9a895b0d40edb9a6d7213afbb256
timeCreated: 1760925436