2025-10-22 11:32:53 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
using Script.Gameplay.Connect;
|
|
|
|
|
using Script.Gameplay.Interface;
|
|
|
|
|
|
2025-10-22 17:34:58 +08:00
|
|
|
namespace Script.Gameplay.Facility
|
2025-10-22 11:32:53 +08:00
|
|
|
{
|
2025-10-22 17:34:58 +08:00
|
|
|
public class MovingPlatformController : BaseFacilityController
|
2025-10-22 11:32:53 +08:00
|
|
|
{
|
|
|
|
|
[SerializeField] private GameObject startPositionObject;
|
|
|
|
|
[SerializeField] private GameObject targetPositionObject;
|
2025-10-22 17:34:58 +08:00
|
|
|
[SerializeField] public float moveSpeed = 2f;
|
2025-10-22 11:32:53 +08:00
|
|
|
private Vector3 startPosition;
|
|
|
|
|
private Vector3 targetPosition;
|
|
|
|
|
|
|
|
|
|
private bool isMoving = false;
|
|
|
|
|
private bool forward = true;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
startPosition = startPositionObject.transform.position;
|
|
|
|
|
targetPosition = targetPositionObject.transform.position;
|
|
|
|
|
transform.position = startPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
if (!isMoving) return;
|
|
|
|
|
|
|
|
|
|
Vector3 destination = forward ? targetPosition : startPosition;
|
|
|
|
|
transform.position = Vector3.MoveTowards(transform.position, destination, moveSpeed * Time.deltaTime);
|
|
|
|
|
|
|
|
|
|
if (Vector3.Distance(transform.position, destination) < 0.01f)
|
|
|
|
|
{
|
|
|
|
|
forward = !forward;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-22 17:34:58 +08:00
|
|
|
public override void OnSignalReceived(bool active, GameObject sender)
|
2025-10-22 11:32:53 +08:00
|
|
|
{
|
2025-10-22 17:34:58 +08:00
|
|
|
base.OnSignalReceived(active, sender);
|
2025-10-22 11:32:53 +08:00
|
|
|
if (active)
|
|
|
|
|
{
|
|
|
|
|
isMoving = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
isMoving = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-22 17:34:58 +08:00
|
|
|
// 可选:如果需要编辑激活状态,可以重写属性
|
|
|
|
|
public override bool IsEnableEdit
|
2025-10-22 11:32:53 +08:00
|
|
|
{
|
2025-10-22 17:34:58 +08:00
|
|
|
get => base.IsEnableEdit;
|
2025-10-22 11:32:53 +08:00
|
|
|
set
|
|
|
|
|
{
|
2025-10-22 17:34:58 +08:00
|
|
|
base.IsEnableEdit = value;
|
2025-10-22 11:32:53 +08:00
|
|
|
isMoving = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|