Merge branch 'Debug/0903playtest修复' into 'develop'
Debug/0903playtest修复 See merge request aibis-dream/aibis-dream!548
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using AibisDream.Framework;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class MouseFollowAndZoom : MonoBehaviour
|
||||
[RequireComponent(typeof(EventTriggerEx))]
|
||||
public class MouseFollowAndZoom : MonoBehaviour, IInteraction
|
||||
{
|
||||
public GameObject targetIndicator; // UI 目标框
|
||||
public TMP_Text targetNameText; // 显示目标名称的文本
|
||||
@@ -13,6 +15,16 @@ namespace AibisDream
|
||||
private EyeTarget currentTarget; // 当前目标
|
||||
private bool isActive = false;
|
||||
private bool isLocked = false;
|
||||
|
||||
// 交互状态管理
|
||||
[Header("交互状态")]
|
||||
[SerializeField] private bool _isInteractionActive = true; // 是否激活交互
|
||||
[SerializeField] private bool _isInteractionAvailable = true; // 是否可用交互
|
||||
[SerializeField] private float _dialogEndCooldown = 0.1f; // 对话结束后的冷却时间
|
||||
|
||||
// 内部状态
|
||||
private float _lastDialogEndTime = -1f; // 上次对话结束的时间
|
||||
private bool _isDialogCooldownActive = false; // 是否在对话冷却期间
|
||||
|
||||
public Camera viewCamera;
|
||||
public float parallaxEffectMultiplier = 0.1f;
|
||||
@@ -32,6 +44,17 @@ namespace AibisDream
|
||||
{
|
||||
isLocked = value;
|
||||
}
|
||||
|
||||
// 交互状态控制方法
|
||||
public void SetInteractionActive(bool value)
|
||||
{
|
||||
_isInteractionActive = value;
|
||||
}
|
||||
|
||||
public void SetInteractionAvailable(bool value)
|
||||
{
|
||||
_isInteractionAvailable = value;
|
||||
}
|
||||
|
||||
|
||||
void Start()
|
||||
@@ -43,6 +66,9 @@ namespace AibisDream
|
||||
{
|
||||
Debug.LogError("EyeManager instance not found in the scene.");
|
||||
}
|
||||
|
||||
// 注册对话事件以处理对话结束后的冷却
|
||||
RegisterDialogEvents();
|
||||
}
|
||||
|
||||
void Update()
|
||||
@@ -52,6 +78,9 @@ namespace AibisDream
|
||||
targetIndicator.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查对话结束冷却
|
||||
UpdateDialogCooldown();
|
||||
|
||||
HandleTargetIndicator(); // 显示指示器
|
||||
if (isLocked) return;
|
||||
@@ -108,8 +137,8 @@ namespace AibisDream
|
||||
{
|
||||
currentTarget = hit.collider.GetComponent<EyeTarget>(); // 更新当前目标
|
||||
|
||||
// 处理鼠标点击事件
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
// 处理鼠标点击事件 - 只有在交互可用且不在对话冷却期时才处理
|
||||
if (Input.GetMouseButtonDown(0) && _isInteractionActive && _isInteractionAvailable && !_isDialogCooldownActive)
|
||||
{
|
||||
Debug.Log("点击目标触发了");
|
||||
if (currentTarget != null)
|
||||
@@ -130,7 +159,7 @@ namespace AibisDream
|
||||
|
||||
void HandleTargetIndicator()
|
||||
{
|
||||
if (currentTarget == null)
|
||||
if (currentTarget == null || !_isInteractionActive)
|
||||
{
|
||||
targetIndicator.SetActive(false); // 隐藏指示器
|
||||
return;
|
||||
@@ -183,5 +212,73 @@ namespace AibisDream
|
||||
Gizmos.DrawLine(topRight, new Vector3(bottomLeft.x, topRight.y, 0));
|
||||
Gizmos.DrawLine(topRight, new Vector3(topRight.x, bottomLeft.y, 0));
|
||||
}
|
||||
|
||||
#region 对话冷却处理
|
||||
|
||||
/// <summary>
|
||||
/// 注册对话事件
|
||||
/// </summary>
|
||||
private void RegisterDialogEvents()
|
||||
{
|
||||
// 监听对话结束事件
|
||||
DialogController.OnDialogueComplete += OnDialogueComplete;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对话结束时的处理
|
||||
/// </summary>
|
||||
private void OnDialogueComplete()
|
||||
{
|
||||
_lastDialogEndTime = Time.time;
|
||||
_isDialogCooldownActive = true;
|
||||
Debug.Log($"[交互冷却] 对话结束,开始 {_dialogEndCooldown} 秒冷却期");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新对话冷却状态
|
||||
/// </summary>
|
||||
private void UpdateDialogCooldown()
|
||||
{
|
||||
if (_isDialogCooldownActive && Time.time - _lastDialogEndTime >= _dialogEndCooldown)
|
||||
{
|
||||
_isDialogCooldownActive = false;
|
||||
Debug.Log("[交互冷却] 冷却期结束,交互恢复正常");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁时取消事件注册
|
||||
/// </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (DialogController.Instance != null)
|
||||
{
|
||||
DialogController.OnDialogueComplete -= OnDialogueComplete;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IInteraction 接口实现
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否激活,激活就正常显示鼠标,否则就显示禁用标志
|
||||
/// </summary>
|
||||
public bool IsActive => _isInteractionActive && !_isDialogCooldownActive;
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否可用,可用就正常显示鼠标,否则就保持原有标志不变
|
||||
/// </summary>
|
||||
public bool IsAvailable => _isInteractionAvailable && !_isDialogCooldownActive;
|
||||
|
||||
/// <summary>
|
||||
/// 返回GameObject
|
||||
/// </summary>
|
||||
public GameObject GetGameObject()
|
||||
{
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user