feat(): 美术配合上拉杆 按钮 控制台 压力板

This commit is contained in:
2025-10-29 12:01:33 +08:00
parent faae67fc3f
commit 639f33daff
15 changed files with 741 additions and 1093 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -9,7 +10,14 @@ namespace Script.Gameplay.Facility
public class ButtonInteractController : BaseFacilityController
{
[SerializeField] private float signalDuration = 1.0f; // 信号持续时间(秒)
[SerializeField] private GameObject buttonPressPoint;
private bool isPressing = false;
private Vector3 buttonInitialPosition;
private void Awake()
{
buttonInitialPosition = buttonPressPoint.transform.position;
}
public override string GetInteractPrompt()
{
@@ -27,14 +35,15 @@ namespace Script.Gameplay.Facility
{
SendSignal(true, this.gameObject);
isPressing = true;
// 按钮下的动画或效果可以在这里添加
transform.localScale = new Vector3(0.3f, 0.3f, 0.1f);
// 按钮下的动画或效果可以在这里添加
buttonPressPoint.transform.position = new Vector3(0, 0, 0);
yield return new WaitForSeconds(signalDuration);
SendSignal(false, this.gameObject);
isPressing = false;
// 按钮弹起的动画或效果可以在这里添加
transform.localScale = new Vector3(0.3f, 0.3f, 0.15f);
buttonPressPoint.transform.position = buttonInitialPosition;
}
}
}

View File

@@ -9,6 +9,7 @@ namespace Script.Gameplay.Facility
public enum SendSignalMode
{
Toggle, // 切换true/false交替发送
//Hold, // 按住, 触发发送true/false, 结束不发送信号
Pulse // 脉冲, 发送true持续一段时间后发送false
}
@@ -19,6 +20,8 @@ namespace Script.Gameplay.Facility
[SerializeField] private List<MonoBehaviour> controlTarget;
[SerializeField] private bool IsBeActive = false;
[SerializeField] private float signalDuration = 1.0f; // 信号持续时间(秒)
[SerializeField] private GameObject pressButtonPrefab;
private bool isPressing = false;
private List<ISignalReceiver> controlTargetSignalReceiver = new List<ISignalReceiver>();
private bool lastSendSignal = false;
@@ -47,51 +50,69 @@ namespace Script.Gameplay.Facility
public override void Interact(GameObject interactor)
{
if(sendSignalMode== SendSignalMode.Toggle)
if (!IsBeActive) return;
if (sendSignalMode == SendSignalMode.Toggle)
{
SendToggleSignal();
}
else if(sendSignalMode== SendSignalMode.Pulse)
else if (sendSignalMode == SendSignalMode.Pulse)
{
SendPulseSignal();
}
}
private void UpdateAnimation()
{
if (pressButtonPrefab != null)
{
if (isPressing)
{
pressButtonPrefab.transform.localPosition = new Vector3(0, 0f, 0);
}
else
{
pressButtonPrefab.transform.localPosition = new Vector3(0, 0f, 0.75f);
}
}
}
private void SendToggleSignal()
{
if (IsBeActive && controlTargetSignalReceiver != null)
if (controlTargetSignalReceiver != null)
{
var signal = !lastSendSignal;
foreach (var receiver in controlTargetSignalReceiver)
{
{
receiver.OnSignalReceived(signal, this.gameObject);
}
lastSendSignal = signal;
isPressing = signal;
UpdateAnimation();
}
}
private void SendPulseSignal()
{
if (IsBeActive)
if (isPressing) return;
foreach (var receiver in controlTargetSignalReceiver)
{
if(isPressing) return;
foreach (var receiver in controlTargetSignalReceiver)
{
StartCoroutine(SendSignalCoroutine(receiver));
}
StartCoroutine(SendSignalCoroutine(receiver));
}
}
private IEnumerator SendSignalCoroutine(ISignalReceiver receiver)
{
receiver.OnSignalReceived(true, this.gameObject);
isPressing = true;
// 按钮压下的动画或效果可以在这里添加
UpdateAnimation();
yield return new WaitForSeconds(signalDuration);
receiver.OnSignalReceived(false, this.gameObject);
isPressing = false;
// 按钮弹起的动画或效果可以在这里添加
UpdateAnimation();
}
}
}

View File

@@ -8,6 +8,7 @@ namespace Script.Gameplay.Facility
public class LeverInteractController : BaseFacilityController
{
private bool isPulled = false;
[SerializeField] private GameObject rotationPrefab;
public override string GetInteractPrompt()
{
@@ -28,12 +29,12 @@ namespace Script.Gameplay.Facility
if (isPulled)
{
// 旋转拉杆到下拉位置
transform.rotation = Quaternion.Euler(0f, 0f, 45f);
rotationPrefab.transform.rotation = Quaternion.Euler(0f, 0f, 45f);
}
else
{
// 旋转拉杆回到初始位置
transform.rotation = Quaternion.Euler(0f, 0f, 0f);
rotationPrefab.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
}
}
}

View File

@@ -10,6 +10,7 @@ namespace Script.Gameplay.Facility
[SerializeField] private Vector3 plateSize = new Vector3(1, 0.2f, 1);
[SerializeField] private Vector3 plateOffset = Vector3.up * 0.1f;
[SerializeField] private GameObject pressTopPrefab;
private bool lastState = false;
private bool hasObject = false;
@@ -24,10 +25,13 @@ namespace Script.Gameplay.Facility
if (hasObject)
{
// 被压下动画
pressTopPrefab.transform.localPosition = new Vector3(0,0,0.1f);
}
else
{
// 弹起动画
pressTopPrefab.transform.localPosition = new Vector3(0,0,1);
}
}
}