2025-10-23 09:26:47 +08:00
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Script.Gameplay.Facility
|
|
|
|
|
{
|
|
|
|
|
public class TransportController : BaseFacilityController
|
|
|
|
|
{
|
|
|
|
|
[Header("传送器设置")]
|
|
|
|
|
[SerializeField] private Transform destinationPoint;
|
|
|
|
|
[SerializeField] private string playerTag = "Player";
|
|
|
|
|
[SerializeField] private float transportDelay = 0.1f;
|
|
|
|
|
|
|
|
|
|
[Header("检测区域参数")]
|
|
|
|
|
[SerializeField] private float detectRadius = 1.0f;
|
|
|
|
|
[SerializeField] private float detectHeight = 2.0f;
|
|
|
|
|
[SerializeField] private LayerMask playerLayer;
|
|
|
|
|
|
2025-10-30 15:51:48 +08:00
|
|
|
[SerializeField] private GameObject particleEffect;
|
2025-10-23 09:26:47 +08:00
|
|
|
private bool canTransport = false;
|
|
|
|
|
private bool isTransporting = false;
|
|
|
|
|
private Collider[] hits;
|
|
|
|
|
|
2025-10-30 15:51:48 +08:00
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
particleEffect.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-23 09:26:47 +08:00
|
|
|
// 接收信号,决定是否允许传送
|
|
|
|
|
public override void OnSignalReceived(bool active, GameObject sender)
|
|
|
|
|
{
|
|
|
|
|
base.OnSignalReceived(active, sender);
|
|
|
|
|
canTransport = active;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
private void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
if (!isOpenInEditor || !canTransport || destinationPoint == null) return;
|
|
|
|
|
hits = Physics.OverlapCapsule(
|
|
|
|
|
GetCapsuleStart(), GetCapsuleEnd(), detectRadius, playerLayer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
if (!isOpenInEditor || !canTransport || destinationPoint == null || hits == null) return;
|
2025-10-30 15:51:48 +08:00
|
|
|
if (canTransport)
|
|
|
|
|
{
|
|
|
|
|
particleEffect.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
particleEffect.SetActive(false);
|
|
|
|
|
}
|
2025-10-23 09:26:47 +08:00
|
|
|
foreach (var hit in hits)
|
|
|
|
|
{
|
|
|
|
|
if (hit.CompareTag(playerTag) && !isTransporting)
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(TransportPlayer(hit.gameObject));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector3 GetCapsuleStart()
|
|
|
|
|
{
|
|
|
|
|
return transform.position + Vector3.up * 0.1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector3 GetCapsuleEnd()
|
|
|
|
|
{
|
|
|
|
|
return transform.position + Vector3.up * detectHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private System.Collections.IEnumerator TransportPlayer(GameObject player)
|
|
|
|
|
{
|
|
|
|
|
isTransporting = true;
|
|
|
|
|
yield return new WaitForSeconds(transportDelay);
|
|
|
|
|
player.transform.position = destinationPoint.position;
|
|
|
|
|
isTransporting = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
private void OnDrawGizmosSelected()
|
|
|
|
|
{
|
|
|
|
|
Gizmos.color = Color.cyan;
|
|
|
|
|
Vector3 start = GetCapsuleStart();
|
|
|
|
|
Vector3 end = GetCapsuleEnd();
|
|
|
|
|
Gizmos.DrawWireSphere(start, detectRadius);
|
|
|
|
|
Gizmos.DrawWireSphere(end, detectRadius);
|
|
|
|
|
Gizmos.DrawLine(start + Vector3.forward * detectRadius, end + Vector3.forward * detectRadius);
|
|
|
|
|
Gizmos.DrawLine(start - Vector3.forward * detectRadius, end - Vector3.forward * detectRadius);
|
|
|
|
|
Gizmos.DrawLine(start + Vector3.right * detectRadius, end + Vector3.right * detectRadius);
|
|
|
|
|
Gizmos.DrawLine(start - Vector3.right * detectRadius, end - Vector3.right * detectRadius);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|