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

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

View File

@@ -60,11 +60,11 @@ namespace Script.Gameplay.Connect
{
if (sender == _pointA.GetGameObject())
{
_pointB.SignalActive(active, sender);
_pointB.OnSignalReceived(active, sender);
}
else if (sender == _pointB.GetGameObject())
{
_pointA.SignalActive(active, sender);
_pointA.OnSignalReceived(active, sender);
}
}
}

View File

@@ -3,14 +3,14 @@ using System.Collections.Generic;
namespace Script.Gameplay.Connect
{
public interface IConnectable
public interface IConnectable : ISignalReceiver
{
public bool IsEnablePlayerConnect { get; set; }
void OnGazeEnter(); // 玩家开始注视时触发
void OnGazeExit(); // 玩家停止注视时触发
Vector3 GetPosition(); // 获取连接点位置
GameObject GetGameObject(); // 获取连接点物体
string GetConnectableName(); // 获取连接点名称
public List<ConnectionLine> ConnectionLines { get; set; }
void SignalActive(bool active, GameObject sender); // 被激活
}
}

View File

@@ -0,0 +1,8 @@
using UnityEngine;
namespace Script.Gameplay.Connect
{
public interface ISignalReceiver
{
public void OnSignalReceived(bool active, GameObject sender);
}
}

View File

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

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

View File

@@ -1,16 +0,0 @@
using UnityEngine;
using Script.Gameplay.Player;
using System.Collections.Generic;
// using Script.Gameplay.Facility;
namespace Script.Gameplay.Interface
{
// public interface IEditable
// {
// void OnGazeEnter(PlayerEditController editor); // 玩家开始注视时触发
// void OnGazeExit(PlayerEditController editor); // 玩家停止注视时触发
// void BeginEdit();
// void EndEdit();
// List<IEditableComponent> GetEditableComponents();
// }
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 8a22b94dcb1d4eb78b7b07ebd8967dc6
timeCreated: 1760629255

View File

@@ -110,7 +110,8 @@ namespace Script.Gameplay.Player
public void SetPointA(IConnectable target)
{
if (target == null) return;
if(!IsEnableConnecting) return;
if (!IsEnableConnecting) return;
if (!target.IsEnablePlayerConnect) return;
outTarget = target;
OnSetPointA?.Invoke(outTarget);
}
@@ -118,7 +119,9 @@ namespace Script.Gameplay.Player
public void SetPointB(IConnectable target)
{
if (target == null) return;
if(!IsEnableConnecting) return;
if (!IsEnableConnecting) return;
if (!target.IsEnablePlayerConnect) return;
inputTarget = target;
OnSetPointB?.Invoke(inputTarget);
}

View File

@@ -24,7 +24,7 @@ namespace UI
private void OnClickButton()
{
_component.IsEditableActive = !_component.IsEditableActive;
_component.IsComponentActive = !_component.IsComponentActive;
RefreshUI();
}
@@ -33,7 +33,7 @@ namespace UI
if (_component != null)
{
componentName.text = _component.ComponentName;
componentState.text = _component.IsEditableActive ? "Active" : "Inactive";
componentState.text = _component.IsComponentActive ? "Active" : "Inactive";
}
}
}