多轮审查和修复
This commit is contained in:
46
Assets/Scripts/Input/ConflictDetector.cs
Normal file
46
Assets/Scripts/Input/ConflictDetector.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace BaseGames.Input
|
||||
{
|
||||
/// <summary>
|
||||
/// 输入冲突检测器(架构 04_InputModule §6)。
|
||||
/// 扫描给定 Action 集合,返回所有绑定了相同按键路径的 Action 名称。
|
||||
/// 挂载在与 RebindPanel 同一 GameObject 上(或作为子组件)。
|
||||
/// </summary>
|
||||
public class ConflictDetector : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回存在冲突的 Action 名称集合。
|
||||
/// 两个 Action 绑定了同一 effectivePath → 互为冲突。
|
||||
/// </summary>
|
||||
/// <param name="actions">待扫描的 Action 序列(通常来自 Gameplay Map)。</param>
|
||||
public HashSet<string> FindConflicts(IEnumerable<InputAction> actions)
|
||||
{
|
||||
var pathToActions = new Dictionary<string, List<string>>();
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
foreach (var binding in action.bindings)
|
||||
{
|
||||
// 跳过复合绑定父项(如 WASD 组合中的 "2DVector")
|
||||
if (binding.isComposite || string.IsNullOrEmpty(binding.effectivePath))
|
||||
continue;
|
||||
|
||||
if (!pathToActions.TryGetValue(binding.effectivePath, out var list))
|
||||
pathToActions[binding.effectivePath] = list = new List<string>();
|
||||
list.Add(action.name);
|
||||
}
|
||||
}
|
||||
|
||||
var conflicted = new HashSet<string>();
|
||||
foreach (var kv in pathToActions)
|
||||
if (kv.Value.Count > 1)
|
||||
foreach (var name in kv.Value)
|
||||
conflicted.Add(name);
|
||||
|
||||
return conflicted;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user