refactor(Facility): 使用继承让所有机关都拥有了独自的 可交互 可编辑 可连接设定。大面积重构
This commit is contained in:
62
Assets/Script/Gameplay/Facility/MovingPlatformController.cs
Normal file
62
Assets/Script/Gameplay/Facility/MovingPlatformController.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
using Script.Gameplay.Connect;
|
||||
using Script.Gameplay.Interface;
|
||||
|
||||
namespace Script.Gameplay.Facility
|
||||
{
|
||||
public class MovingPlatformController : BaseFacilityController
|
||||
{
|
||||
[SerializeField] private GameObject startPositionObject;
|
||||
[SerializeField] private GameObject targetPositionObject;
|
||||
[SerializeField] public float moveSpeed = 2f;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSignalReceived(bool active, GameObject sender)
|
||||
{
|
||||
base.OnSignalReceived(active, sender);
|
||||
if (active)
|
||||
{
|
||||
isMoving = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isMoving = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 可选:如果需要编辑激活状态,可以重写属性
|
||||
public override bool IsEnableEdit
|
||||
{
|
||||
get => base.IsEnableEdit;
|
||||
set
|
||||
{
|
||||
base.IsEnableEdit = value;
|
||||
isMoving = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user