2025-10-29 12:01:33 +08:00
|
|
|
using System;
|
2025-10-22 17:34:58 +08:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Script.Gameplay.Interface;
|
|
|
|
|
using Script.Gameplay.Connect;
|
|
|
|
|
|
|
|
|
|
namespace Script.Gameplay.Facility
|
|
|
|
|
{
|
|
|
|
|
public class ButtonInteractController : BaseFacilityController
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] private float signalDuration = 1.0f; // 信号持续时间(秒)
|
2025-10-29 12:01:33 +08:00
|
|
|
[SerializeField] private GameObject buttonPressPoint;
|
2025-10-22 19:38:22 +08:00
|
|
|
private bool isPressing = false;
|
2025-10-29 12:01:33 +08:00
|
|
|
private Vector3 buttonInitialPosition;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
buttonInitialPosition = buttonPressPoint.transform.position;
|
|
|
|
|
}
|
2025-10-22 17:34:58 +08:00
|
|
|
|
|
|
|
|
public override string GetInteractPrompt()
|
|
|
|
|
{
|
|
|
|
|
return "按F按下按钮";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Interact(GameObject interactor)
|
|
|
|
|
{
|
2025-10-22 19:38:22 +08:00
|
|
|
if (isPressing) return;
|
2025-10-22 17:34:58 +08:00
|
|
|
StartCoroutine(SendSignalCoroutine());
|
2025-10-22 19:38:22 +08:00
|
|
|
//Debug.Log("Button pressed");
|
2025-10-22 17:34:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerator SendSignalCoroutine()
|
|
|
|
|
{
|
|
|
|
|
SendSignal(true, this.gameObject);
|
2025-10-22 19:38:22 +08:00
|
|
|
isPressing = true;
|
2025-10-29 12:01:33 +08:00
|
|
|
// 按钮按下的动画或效果可以在这里添加
|
|
|
|
|
buttonPressPoint.transform.position = new Vector3(0, 0, 0);
|
2025-10-22 19:38:22 +08:00
|
|
|
|
2025-10-22 17:34:58 +08:00
|
|
|
yield return new WaitForSeconds(signalDuration);
|
|
|
|
|
SendSignal(false, this.gameObject);
|
2025-10-22 19:38:22 +08:00
|
|
|
isPressing = false;
|
2025-10-22 17:34:58 +08:00
|
|
|
// 按钮弹起的动画或效果可以在这里添加
|
2025-10-29 12:01:33 +08:00
|
|
|
buttonPressPoint.transform.position = buttonInitialPosition;
|
|
|
|
|
|
2025-10-22 17:34:58 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|