From ba13759542ef37387230d15b323ec4258537072e Mon Sep 17 00:00:00 2001 From: Steven Lai <40339137+HalfADog@users.noreply.github.com> Date: Tue, 6 May 2025 09:42:03 +0800 Subject: [PATCH] Update EasyInteractive.cs --- EasyInteractive/Runtime/EasyInteractive.cs | 44 ++++++++++++---------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/EasyInteractive/Runtime/EasyInteractive.cs b/EasyInteractive/Runtime/EasyInteractive.cs index a4c80f6..7565527 100644 --- a/EasyInteractive/Runtime/EasyInteractive.cs +++ b/EasyInteractive/Runtime/EasyInteractive.cs @@ -42,6 +42,7 @@ namespace HalfDog.EasyInteractive //当前激活的交互情景 private IInteractCase _currentActiveInteractCase; private bool _inUpdate; + private float _dragThreshold = 8f; public bool InUpdate { @@ -67,27 +68,30 @@ namespace HalfDog.EasyInteractive this.EnableMonoUpdater(); _interactRelationMapper = new Dictionary>(); //加载所有的交互情景 - Assembly assembly = typeof(EasyInteractive).Assembly; - List types = assembly.GetTypes().Where(type => typeof(IInteractCase).IsAssignableFrom(type) && !type.IsAbstract).ToList(); - for (int i = 0; i < types.Count; i++) + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var assembly in assemblies) { - InteractCaseAttribute attribute = types[i].GetCustomAttribute(); - if (attribute != null) { - IInteractCase ic = Activator.CreateInstance(types[i], attribute.interactSubject, attribute.interactTarget) as IInteractCase; - _allInteractCase.Add(types[i],ic); - ic.enable = attribute.enableExecuteOnLoad; - _executingInteractCases.Add(ic); - //记录下交互对象之间的关系 - List list; - if (_interactRelationMapper.TryGetValue(attribute.interactSubject, out list)) - list.Add(attribute.interactTarget); - else - _interactRelationMapper.Add(attribute.interactSubject,new List { attribute.interactTarget }); + List types = assembly.GetTypes().Where(type => typeof(IInteractCase).IsAssignableFrom(type) && !type.IsAbstract).ToList(); + for (int i = 0; i < types.Count; i++) + { + InteractCaseAttribute attribute = types[i].GetCustomAttribute(); + if (attribute != null) { + IInteractCase ic = Activator.CreateInstance(types[i], attribute.interactSubject, attribute.interactTarget) as IInteractCase; + _allInteractCase.Add(types[i],ic); + ic.enable = attribute.enableExecuteOnLoad; + _executingInteractCases.Add(ic); + //记录下交互对象之间的关系 + List list; + if (_interactRelationMapper.TryGetValue(attribute.interactSubject, out list)) + list.Add(attribute.interactTarget); + else + _interactRelationMapper.Add(attribute.interactSubject,new List { attribute.interactTarget }); - if (_interactRelationMapper.TryGetValue(attribute.interactTarget, out list)) - list.Add(attribute.interactSubject); - else - _interactRelationMapper.Add(attribute.interactTarget, new List { attribute.interactSubject }); + if (_interactRelationMapper.TryGetValue(attribute.interactTarget, out list)) + list.Add(attribute.interactSubject); + else + _interactRelationMapper.Add(attribute.interactTarget, new List { attribute.interactSubject }); + } } } } @@ -204,7 +208,7 @@ namespace HalfDog.EasyInteractive //如果鼠标按下并且移动了一定距离则开始拖拽 if (currentDraged == null && mouseBtnPressed && _possibleDragTarget != null) { - if (Vector3.Distance(_mouseDownPosition, Input.mousePosition) > 16f && _readyDrag == _possibleDragTarget) + if (Vector3.Distance(_mouseDownPosition, Input.mousePosition) > _dragThreshold && _readyDrag == _possibleDragTarget) { //拖拽与被选中的不能是同一个 if (_readyDrag == currentSelected)