feat(GazeReminder): 实现更多提示
This commit is contained in:
@@ -76,6 +76,9 @@ namespace Script.Gameplay.Connect
|
||||
_pointB.ConnectionLines.Remove(this);
|
||||
}
|
||||
|
||||
public int NeedSignalCount { get; set; }
|
||||
public int CurrentNeedSignalCount { get; set; }
|
||||
|
||||
public void OnSignalReceived(bool active, GameObject sender)
|
||||
{
|
||||
SendSignal(active,this.gameObject);
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace Script.Gameplay.Facility
|
||||
[SerializeField] protected bool isEnableInteract = true;
|
||||
[SerializeField] protected bool isEnableEdit = true;
|
||||
[SerializeField] protected bool isEnableConnect = true;
|
||||
[SerializeField] protected string componentName;
|
||||
[SerializeField] protected int needSignalCount = 1;
|
||||
[SerializeField] protected bool isOpenInEditor = true;
|
||||
protected int CurrentSignalCount = 0;
|
||||
[SerializeField] protected int needSignalCount = 1;
|
||||
[SerializeField] protected int currentSignalCount = 0;
|
||||
[SerializeField] protected string componentName;
|
||||
|
||||
public virtual bool IsEnableInteract
|
||||
{
|
||||
@@ -44,6 +44,17 @@ namespace Script.Gameplay.Facility
|
||||
get => isEnableConnect;
|
||||
set => isEnableConnect = value;
|
||||
}
|
||||
public virtual int NeedSignalCount
|
||||
{
|
||||
get => needSignalCount;
|
||||
set => needSignalCount = value;
|
||||
}
|
||||
|
||||
public virtual int CurrentNeedSignalCount
|
||||
{
|
||||
get => currentSignalCount;
|
||||
set => currentSignalCount = value;
|
||||
}
|
||||
|
||||
public string ComponentName
|
||||
{
|
||||
@@ -96,14 +107,14 @@ namespace Script.Gameplay.Facility
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
CurrentSignalCount++;
|
||||
CurrentNeedSignalCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentSignalCount = Mathf.Max(0, CurrentSignalCount - 1);
|
||||
CurrentNeedSignalCount = Mathf.Max(0, CurrentNeedSignalCount- 1);
|
||||
}
|
||||
|
||||
if (CurrentSignalCount < needSignalCount)
|
||||
if (CurrentNeedSignalCount < NeedSignalCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace Script.Gameplay.Facility
|
||||
|
||||
public override void OnSignalReceived(bool active, GameObject sender)
|
||||
{
|
||||
base.OnSignalReceived(active, sender);
|
||||
Interact(sender);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ namespace Script.Gameplay.Interface
|
||||
{
|
||||
public interface ISignalReceiver
|
||||
{
|
||||
public int NeedSignalCount { get; set; }
|
||||
public int CurrentNeedSignalCount { get; set; }
|
||||
public void OnSignalReceived(bool active, GameObject sender);
|
||||
}
|
||||
}
|
||||
@@ -43,11 +43,11 @@ namespace Script.Gameplay.Player
|
||||
{
|
||||
if (currentTarget != null)
|
||||
{
|
||||
OnGazeEnter?.Invoke((currentTarget as MonoBehaviour)?.gameObject);
|
||||
OnGazeEnterConnectable?.Invoke((currentTarget as MonoBehaviour)?.gameObject);
|
||||
}
|
||||
if (previousTarget != null)
|
||||
{
|
||||
OnGazeExit?.Invoke((previousTarget as MonoBehaviour)?.gameObject);
|
||||
OnGazeExitConnectable?.Invoke((previousTarget as MonoBehaviour)?.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,8 +60,8 @@ namespace Script.Gameplay.Player
|
||||
private IConnectable inputTarget;
|
||||
public event Action<IConnectable> OnSetPointA;
|
||||
public event Action<IConnectable> OnSetPointB;
|
||||
public event Action<GameObject> OnGazeEnter;
|
||||
public event Action<GameObject> OnGazeExit;
|
||||
public event Action<GameObject> OnGazeEnterConnectable;
|
||||
public event Action<GameObject> OnGazeExitConnectable;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using UnityEngine;
|
||||
using Script.Gameplay.Interface;
|
||||
using Script.Gameplay.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Script.Gameplay.Global;
|
||||
|
||||
namespace Script.Gameplay.Player
|
||||
@@ -12,11 +13,34 @@ namespace Script.Gameplay.Player
|
||||
[SerializeField] private FirstPersonRaycaster raycaster; // 新增:第一人称射线检测器
|
||||
public bool IsEnableEditing = true; // 是否启用编辑功能
|
||||
private bool isEditing = false; // 当前是否处于编辑状态
|
||||
public event Action<GameObject> OnGazeEnterEditableComponent;
|
||||
public event Action<GameObject> OnGazeExitEditableComponent;
|
||||
public event Action<GameObject> OnBeginEditTarget;
|
||||
public event Action<GameObject> OnEndEditTarget;
|
||||
|
||||
private GameObject previousTarget; // 上一次注视的对象(用于注视进入/离开事件)
|
||||
private GameObject currentTarget; // 射线命中的当前可编辑对象(用于按键交互)
|
||||
private GameObject previousGazedTarget; // 上一次注视的对象(用于注视进入/离开事件)
|
||||
|
||||
public GameObject CurrentTarget
|
||||
{
|
||||
get => currentTarget;
|
||||
set
|
||||
{
|
||||
previousTarget = currentTarget;
|
||||
currentTarget = value;
|
||||
if (previousTarget != currentTarget)
|
||||
{
|
||||
if (currentTarget != null)
|
||||
{
|
||||
OnGazeEnterEditableComponent?.Invoke((currentTarget)?.gameObject);
|
||||
}
|
||||
if (previousTarget != null)
|
||||
{
|
||||
OnGazeExitEditableComponent?.Invoke((previousTarget)?.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private InputManager inputManager;
|
||||
|
||||
@@ -53,23 +77,7 @@ namespace Script.Gameplay.Player
|
||||
hitEditable = lookAtObj;
|
||||
}
|
||||
}
|
||||
currentTarget = hitEditable;
|
||||
|
||||
// // 如果命中对象与之前注视的不一样,触发进入/离开事件
|
||||
// if (hitEditable != previousGazedTarget)
|
||||
// {
|
||||
// if (previousGazedTarget != null)
|
||||
// {
|
||||
// // previousGazedTarget.OnGazeExit(this);
|
||||
// }
|
||||
//
|
||||
// if (hitEditable != null)
|
||||
// {
|
||||
// // hitEditable.OnGazeEnter(this);
|
||||
// }
|
||||
//
|
||||
// previousGazedTarget = hitEditable;
|
||||
// }
|
||||
CurrentTarget = hitEditable;
|
||||
}
|
||||
|
||||
private void EditTarget()
|
||||
@@ -77,7 +85,7 @@ namespace Script.Gameplay.Player
|
||||
if (isEditing)
|
||||
{
|
||||
isEditing = false;
|
||||
OnEndEditTarget?.Invoke(currentTarget);
|
||||
OnEndEditTarget?.Invoke(CurrentTarget);
|
||||
inputManager.SetCursorState(false, CursorLockMode.Locked);
|
||||
inputManager.SetInputForLook(true);
|
||||
inputManager.SetInputForMove(true);
|
||||
@@ -88,10 +96,10 @@ namespace Script.Gameplay.Player
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentTarget == null) return;
|
||||
if (CurrentTarget == null) return;
|
||||
if (!IsEnableEditing) return;
|
||||
isEditing = true;
|
||||
OnBeginEditTarget?.Invoke(currentTarget);
|
||||
OnBeginEditTarget?.Invoke(CurrentTarget);
|
||||
inputManager.SetCursorState(true, CursorLockMode.Confined);
|
||||
inputManager.SetInputForLook(false);
|
||||
inputManager.SetInputForMove(false);
|
||||
|
||||
@@ -3,6 +3,7 @@ using UnityEngine;
|
||||
using Script.Gameplay.Player;
|
||||
using TMPro;
|
||||
using System.Collections.Generic;
|
||||
using Script.Gameplay.Interface;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
@@ -11,11 +12,19 @@ namespace UI
|
||||
[SerializeField] private GameObject reminderInteractPrefab;
|
||||
[SerializeField] private GameObject reminderReadPrefab;
|
||||
[SerializeField] private GameObject reminderConnectPrefab;
|
||||
[SerializeField] private GameObject reminderSetPointPrefab;
|
||||
[SerializeField] private GameObject reminderSetLeftPointPrefab;
|
||||
[SerializeField] private GameObject reminderSetRightPointPrefab;
|
||||
[SerializeField] private GameObject reminderDeleteLinePrefab;
|
||||
[SerializeField] private GameObject reminderEditPrefab;
|
||||
[Header("Connect Status UI")]
|
||||
[SerializeField] private GameObject ConnectStatus;
|
||||
[SerializeField] private TMP_Text NeedCountText;
|
||||
[SerializeField] private TMP_Text CurrentCountText;
|
||||
|
||||
private PlayerInteractorController playerInteractorController;
|
||||
private PlayerConnectController playerConnectController;
|
||||
private PlayerDialogueController playerDialogueController;
|
||||
private PlayerEditController playerEditController;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
@@ -23,6 +32,14 @@ namespace UI
|
||||
ControllerLocator.Instance.TryGetWait<PlayerInteractorController>(OnGetInteractorController);
|
||||
ControllerLocator.Instance.TryGetWait<PlayerConnectController>(OnGetConnectController);
|
||||
ControllerLocator.Instance.TryGetWait<PlayerDialogueController>(OnGetDialogueController);
|
||||
ControllerLocator.Instance.TryGetWait<PlayerEditController>(OnGetEditController);
|
||||
}
|
||||
|
||||
private void OnGetEditController(PlayerEditController obj)
|
||||
{
|
||||
playerEditController = obj;
|
||||
playerEditController.OnGazeEnterEditableComponent += (obj) => reminderEditPrefab.SetActive(true);
|
||||
playerEditController.OnGazeExitEditableComponent += (obj) => reminderEditPrefab.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnGetInteractorController(PlayerInteractorController controller)
|
||||
@@ -35,17 +52,32 @@ namespace UI
|
||||
private void OnGetConnectController(PlayerConnectController controller)
|
||||
{
|
||||
playerConnectController = controller;
|
||||
playerConnectController.OnGazeEnter += (obj) =>
|
||||
playerConnectController.OnGazeEnterConnectable += (obj) =>
|
||||
{
|
||||
reminderConnectPrefab.SetActive(true);
|
||||
reminderSetPointPrefab.SetActive(true);
|
||||
reminderSetLeftPointPrefab.SetActive(true);
|
||||
reminderSetRightPointPrefab.SetActive(true);
|
||||
reminderDeleteLinePrefab.SetActive(true);
|
||||
// 更新连接状态UI
|
||||
ISignalReceiver connectableComponent = obj.GetComponent<ISignalReceiver>();
|
||||
if (connectableComponent != null)
|
||||
{
|
||||
ConnectStatus.SetActive(true);
|
||||
NeedCountText.text = connectableComponent.NeedSignalCount.ToString();
|
||||
CurrentCountText.text = connectableComponent.CurrentNeedSignalCount.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectStatus.SetActive(false);
|
||||
}
|
||||
};
|
||||
playerConnectController.OnGazeExit += (obj) =>
|
||||
playerConnectController.OnGazeExitConnectable += (obj) =>
|
||||
{
|
||||
reminderConnectPrefab.SetActive(false);
|
||||
reminderSetPointPrefab.SetActive(false);
|
||||
reminderSetLeftPointPrefab.SetActive(false);
|
||||
reminderSetRightPointPrefab.SetActive(false);
|
||||
reminderDeleteLinePrefab.SetActive(false);
|
||||
ConnectStatus.SetActive(false);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace UI
|
||||
private void OnGet(PlayerWatchModeController watchModeCtrl)
|
||||
{
|
||||
watchModeController = watchModeCtrl;
|
||||
modeText.text = "Watch Mode: " + watchModeController.CurrentWatchMode;
|
||||
watchModeController.OnEnterWatchMode += mode => modeText.text = "Watch Mode: " + mode;
|
||||
modeText.text = "Mode: " + watchModeController.CurrentWatchMode;
|
||||
watchModeController.OnEnterWatchMode += mode => modeText.text = "Mode: " + mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user