feat(Console MovePlateform): 实现控制台和移动平台

This commit is contained in:
2025-10-22 11:32:53 +08:00
parent 3d014cd2c2
commit 3cdd41ea49
27 changed files with 936 additions and 46 deletions

View File

@@ -0,0 +1,70 @@
using System.Collections.Generic;
using Script.Gameplay.Connect;
using Script.Gameplay.Interface;
using UnityEngine;
public class BaseFacilityController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable, ISignalSender
{
public bool IsEnablePlayerConnect { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
public List<ConnectionLine> ConnectionLines { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
public bool IsEnableActive { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
public bool IsEnableEdit { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
bool IEditableComponent.IsComponentActive { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
string IEditableComponent.ComponentName { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
LockLevel IEditableComponent.LockLevel => throw new System.NotImplementedException();
public string GetConnectableName()
{
throw new System.NotImplementedException();
}
public GameObject GetGameObject()
{
throw new System.NotImplementedException();
}
public string GetInteractPrompt()
{
throw new System.NotImplementedException();
}
public Vector3 GetPosition()
{
throw new System.NotImplementedException();
}
public void Interact(GameObject interactor)
{
throw new System.NotImplementedException();
}
public void OnGazeEnter(GameObject editor)
{
throw new System.NotImplementedException();
}
public void OnGazeEnter()
{
throw new System.NotImplementedException();
}
public void OnGazeExit(GameObject editor)
{
throw new System.NotImplementedException();
}
public void OnGazeExit()
{
throw new System.NotImplementedException();
}
public void OnSignalReceived(bool active, GameObject sender)
{
throw new System.NotImplementedException();
}
public void SendSignal(bool active)
{
throw new System.NotImplementedException();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8e9f3dfa12a48a74ab978e8c7c8cb0af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -6,7 +6,8 @@ using Script.Gameplay.Connect;
namespace Script.Gameplay.Edit
{
public class ButtonInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable, ISignalSender
public class ButtonInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable,
ISignalSender
{
#region Interactable
@@ -40,7 +41,7 @@ namespace Script.Gameplay.Edit
SendSignal(true);
Interactable = false;
// 按钮压下的动画或效果可以在这里添加
yield return new WaitForSeconds(signalDuration);
SendSignal(false);
Interactable = true;
@@ -53,7 +54,7 @@ namespace Script.Gameplay.Edit
[SerializeField] private bool isActive = true;
public bool IsEditableActive
public bool IsComponentActive
{
get => isActive;
set
@@ -70,6 +71,8 @@ namespace Script.Gameplay.Edit
#region Connectable
public bool IsEnablePlayerConnect { get; set; } = true;
public void OnGazeEnter()
{
}
@@ -94,11 +97,12 @@ namespace Script.Gameplay.Edit
}
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
public void SignalActive(bool active, GameObject sender)
public void OnSignalReceived(bool active, GameObject sender)
{
// 按钮通常不接收信号,因此这里可以留空
}
public void SendSignal(bool active)
{
if (ConnectionLines != null)
@@ -112,5 +116,4 @@ namespace Script.Gameplay.Edit
#endregion
}
}
}

View File

@@ -8,7 +8,7 @@ namespace Script.Gameplay.Edit
{
[SerializeField] private bool isActive = true;
public bool IsEditableActive
public bool IsComponentActive
{
get => isActive;
set

View File

@@ -0,0 +1,109 @@
using System.Collections.Generic;
using Script.Gameplay.Connect;
using Script.Gameplay.Interface;
using UnityEngine;
namespace Script.Gameplay.Edit
{
public class ConsoleController : MonoBehaviour, IConnectable, IEditableComponent, IInteractable
{
[SerializeField] private int needSignalCount = 1;
private int currentSignalCount;
[SerializeField] private MonoBehaviour controlTarget;
public ISignalReceiver controlTargetSignalReceiver;
[SerializeField] private bool IsActive;
private bool lastSendSignal = false;
public bool IsComponentActive { get; set; }
private string componentName = "Console";
public string ComponentName
{
get => string.IsNullOrEmpty(componentName) ? gameObject.name : componentName;
set => componentName = value;
}
public LockLevel LockLevel { get; set; }
public bool IsEnablePlayerConnect { get; set; } = true;
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
void Awake()
{
controlTargetSignalReceiver = controlTarget as ISignalReceiver;
if (controlTargetSignalReceiver == null)
{
Debug.LogError("Control target does not implement ISignalReceiver");
}
}
public void OnGazeEnter()
{
// no-op
}
public void OnGazeExit()
{
// no-op
}
public Vector3 GetPosition()
{
return this.gameObject.transform.position;
}
public GameObject GetGameObject()
{
return gameObject;
}
public string GetConnectableName()
{
return gameObject.name;
}
public void OnSignalReceived(bool active, GameObject sender)
{
if (active)
{
currentSignalCount++;
}
else
{
currentSignalCount--;
}
if (currentSignalCount >= needSignalCount)
{
IsActive = true;
}
else
{
IsActive = false;
}
}
public string GetInteractPrompt()
{
return "Interact to Active";
}
public void Interact(GameObject interactor)
{
if (IsActive && controlTargetSignalReceiver != null)
{
var signal = !lastSendSignal;
controlTargetSignalReceiver.OnSignalReceived(signal, this.gameObject);
lastSendSignal = signal;
}
}
public void OnGazeEnter(GameObject editor)
{
// no-op
}
public void OnGazeExit(GameObject editor)
{
// no-op
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cc0b1376aefb4cccb530717966b48bf5
timeCreated: 1761039706

View File

@@ -64,7 +64,7 @@ namespace Script.Gameplay.Edit
private bool isActive = true;
public bool IsEditableActive
public bool IsComponentActive
{
get => isActive;
set
@@ -82,6 +82,8 @@ namespace Script.Gameplay.Edit
#region Connectable
public bool IsEnablePlayerConnect { get; set; } = true;
public void OnGazeEnter()
{
}
@@ -106,7 +108,7 @@ namespace Script.Gameplay.Edit
}
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
public void SignalActive(bool active, GameObject sender)
public void OnSignalReceived(bool active, GameObject sender)
{
Interact(sender);
}

View File

@@ -21,12 +21,13 @@ namespace Script.Gameplay.Edit
// 不可交互
// 可编辑
public bool IsEditableActive { get; set; } = true;
public bool IsComponentActive { get; set; } = true;
public string ComponentName { get; set; } = "Emitter";
public LockLevel LockLevel => LockLevel.Red;
// 可连线
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
public bool IsEnablePlayerConnect { get; set; } = true;
public void OnGazeEnter() { }
public void OnGazeExit() { }
public Vector3 GetPosition() => transform.position;
@@ -34,9 +35,9 @@ namespace Script.Gameplay.Edit
public string GetConnectableName() => gameObject.name;
// 接收信号
public void SignalActive(bool active, GameObject sender)
public void OnSignalReceived(bool active, GameObject sender)
{
if(!IsEditableActive) return;
if(!IsComponentActive) return;
if (active)
{
if (emitCoroutine == null)

View File

@@ -42,7 +42,7 @@ namespace Script.Gameplay.Edit
[SerializeField] private bool isActive = true;
public bool IsEditableActive
public bool IsComponentActive
{
get => isActive;
set
@@ -59,6 +59,8 @@ namespace Script.Gameplay.Edit
#region Connectable
public bool IsEnablePlayerConnect { get; set; } = true;
public void OnGazeEnter()
{
}
@@ -76,7 +78,7 @@ namespace Script.Gameplay.Edit
public string GetConnectableName() => gameObject.name;
public List<ConnectionLine> ConnectionLines { get; set; }= new List<ConnectionLine>();
public void SignalActive(bool active, GameObject sender)
public void OnSignalReceived(bool active, GameObject sender)
{
//
}

View File

@@ -0,0 +1,66 @@
using UnityEngine;
using Script.Gameplay.Connect;
using Script.Gameplay.Interface;
namespace Script.Gameplay.Edit
{
public class MovingPlatformController : MonoBehaviour, IEditableComponent, ISignalReceiver
{
[SerializeField] private GameObject startPositionObject;
[SerializeField] private GameObject targetPositionObject;
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 void OnSignalReceived(bool active, GameObject sender)
{
if (active)
{
isMoving = true;
}
else
{
isMoving = false;
}
}
// IEditableComponent
private bool isEditable = true;
public bool IsComponentActive
{
get => isEditable;
set
{
isEditable = value;
isMoving = value;
}
}
public string ComponentName { get; set; } = "MovingPlatform";
public LockLevel LockLevel => LockLevel.Red;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 115d4e847c444833bc8dce4a03a78e55
timeCreated: 1761038093

View File

@@ -31,6 +31,7 @@ namespace Script.Gameplay.Edit
// 不可编辑,不可交互
// 可连接,可发信号
public bool IsEnablePlayerConnect { get; set; } = true;
public void OnGazeEnter() { }
public void OnGazeExit() { }
public Vector3 GetPosition() => transform.position;
@@ -38,7 +39,7 @@ namespace Script.Gameplay.Edit
public string GetConnectableName() => gameObject.name;
// 接收信号
public void SignalActive(bool active, GameObject sender)
public void OnSignalReceived(bool active, GameObject sender)
{
if (active)
{

View File

@@ -28,7 +28,7 @@ namespace Script.Gameplay.Edit
#region EditableComponent
public bool IsEditableActive
public bool IsComponentActive
{
get => isActive;
set => isActive = value;
@@ -41,6 +41,8 @@ namespace Script.Gameplay.Edit
#region Connectable
public bool IsEnablePlayerConnect { get; set; } = true;
public void OnGazeEnter()
{
}
@@ -59,7 +61,7 @@ namespace Script.Gameplay.Edit
public string GetConnectableName() => gameObject.name;
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
public void SignalActive(bool active, GameObject sender)
public void OnSignalReceived(bool active, GameObject sender)
{
//
}

View File

@@ -8,7 +8,7 @@ namespace Script.Gameplay.Edit
{
[SerializeField] private bool isActive = true;
public bool IsEditableActive
public bool IsComponentActive
{
get => isActive;
set