66public interface IInputProvider
77{
88 bool TryGetPosition ( out Vector3 position ) ;
9+ bool IsUIBlockingInput ( ) ;
910}
1011
1112public interface IInputUpProvider
@@ -41,8 +42,13 @@ public bool TryGetPosition(out Vector3 position)
4142 return false ;
4243 }
4344
45+ public bool IsUIBlockingInput ( )
46+ {
47+ return IsPointerOverIgnoredUI ( ) ;
48+ }
49+ 4450 /// <summary>
45- /// "IgnoreLookAt" 태그가 달린 UI 클릭 여부 체크
51+ /// UI 클릭 여부 체크
4652 /// </summary>
4753 private bool IsPointerOverIgnoredUI ( )
4854 {
@@ -62,8 +68,14 @@ private bool IsPointerOverIgnoredUI()
6268
6369 foreach ( var result in results )
6470 {
65- if ( result . gameObject . CompareTag ( "IgnoreLookAt" ) )
71+ // UI 요소인지 확인
72+ if ( result . gameObject . layer == LayerMask . NameToLayer ( "UI" ) ||
73+ result . gameObject . GetComponent < Canvas > ( ) != null ||
74+ result . gameObject . GetComponent < UnityEngine . UI . Graphic > ( ) != null ||
75+ result . gameObject . GetComponent < UnityEngine . UI . Selectable > ( ) != null )
76+ {
6677 return true ;
78+ }
6779 }
6880 return false ;
6981 }
@@ -100,15 +112,100 @@ public class ScreenTapManager : Singleton<ScreenTapManager>
100112
101113 private CubismRaycaster _raycaster = null ;
102114
115+ [ Header ( "디버그 설정" ) ]
116+ [ SerializeField ] private bool _enableDebugLog = false ;
117+ [ SerializeField ] private bool _enableDebugRay = false ;
118+ [ SerializeField ] private Color _debugRayColor = Color . red ;
119+ [ SerializeField ] private float _debugRayDuration = 2f ;
120+ 121+ private Vector3 _lastTapPosition = Vector3 . zero ;
122+ private bool _hasTapped = false ;
123+ 103124 public void Initialize ( Camera cam )
104125 {
105- _camera = cam ; // 항상 업데이트
126+ _camera = cam ;
106127 if ( _inputProvider == null )
107128 _inputProvider = new DefaultInputProvider ( ) ;
108129 if ( _inputUpProvider == null )
109130 _inputUpProvider = new DefaultInputUpProvider ( ) ;
110131 }
111132
133+ private void Update ( )
134+ {
135+ UpdateTapDebug ( ) ;
136+ }
137+ 138+ private void UpdateTapDebug ( )
139+ {
140+ if ( _inputProvider . TryGetPosition ( out var currentPosition ) )
141+ {
142+ if ( ! _hasTapped )
143+ {
144+ _lastTapPosition = currentPosition ;
145+ _hasTapped = true ;
146+ LogTapDebug ( currentPosition , "탭 시작" ) ;
147+ DrawDebugRay ( currentPosition ) ;
148+ }
149+ }
150+ else
151+ {
152+ if ( _hasTapped && _enableDebugLog && _inputProvider is DefaultInputProvider defaultProvider )
153+ {
154+ if ( defaultProvider . IsUIBlockingInput ( ) )
155+ {
156+ Debug . Log ( "[ScreenTapManager] UI가 입력을 차단했습니다." ) ;
157+ }
158+ }
159+ _hasTapped = false ;
160+ }
161+ }
162+ 163+ private void LogTapDebug ( Vector3 screenPosition , string action )
164+ {
165+ if ( ! _enableDebugLog ) return ;
166+ 167+ var worldPosition = _camera != null ? _camera . ScreenToWorldPoint ( screenPosition ) : Vector3 . zero ;
168+ var viewportPosition = _camera != null ? _camera . ScreenToViewportPoint ( screenPosition ) : Vector3 . zero ;
169+ 170+ Debug . Log ( $ "[ScreenTapManager] { action } - 스크린: { screenPosition } , 월드: { worldPosition } , 뷰포트: { viewportPosition } ") ;
171+ }
172+ 173+ private void DrawDebugRay ( Vector3 screenPosition )
174+ {
175+ if ( ! _enableDebugRay || _camera == null ) return ;
176+ 177+ var ray = _camera . ScreenPointToRay ( screenPosition ) ;
178+ Debug . DrawRay ( ray . origin , ray . direction * 100f , _debugRayColor , _debugRayDuration ) ;
179+ }
180+ 181+ public Vector3 GetLastTapPosition ( )
182+ {
183+ return _lastTapPosition ;
184+ }
185+ 186+ public bool HasTapped ( )
187+ {
188+ return _hasTapped ;
189+ }
190+ 191+ public void SetDebugEnabled ( bool enableLog , bool enableRay )
192+ {
193+ _enableDebugLog = enableLog ;
194+ _enableDebugRay = enableRay ;
195+ }
196+ 197+ private void OnDrawGizmos ( )
198+ {
199+ if ( ! _enableDebugRay || _camera == null || ! _hasTapped ) return ;
200+ 201+ Gizmos . color = _debugRayColor ;
202+ var worldPosition = _camera . ScreenToWorldPoint ( _lastTapPosition ) ;
203+ Gizmos . DrawWireSphere ( worldPosition , 0.1f ) ;
204+ 205+ var ray = _camera . ScreenPointToRay ( _lastTapPosition ) ;
206+ Gizmos . DrawRay ( ray . origin , ray . direction * 10f ) ;
207+ }
208+ 112209 /// <summary>
113210 /// 씬 전환 시 Camera를 업데이트한다.
114211 /// </summary>
@@ -140,6 +237,10 @@ public bool TryGetLookDirection(out Vector3 lookDir)
140237 if ( _inputProvider . TryGetPosition ( out var screenPos ) )
141238 {
142239 lookDir = ConvertScreenToLookDirection ( screenPos ) ;
240+ if ( _enableDebugLog )
241+ {
242+ Debug . Log ( $ "[ScreenTapManager] LookAt 방향: { lookDir } ") ;
243+ }
143244 return true ;
144245 }
145246 lookDir = Vector3 . zero ;
@@ -193,16 +294,37 @@ public bool TryGetTapUpPosition(out CubismRaycastHit[] hitResults)
193294 return false ;
194295 }
195296
297+ LogTapDebug ( screenPosition , "탭 종료" ) ;
298+ DrawDebugRay ( screenPosition ) ;
299+ 196300 var results = new CubismRaycastHit [ 4 ] ;
197301 var ray = _camera . ScreenPointToRay ( screenPosition ) ;
198302 var hitCount = _raycaster . Raycast ( ray , results ) ;
199303
200304 if ( hitCount > 0 )
201305 {
202306 hitResults = results ;
307+ if ( _enableDebugLog )
308+ {
309+ Debug . Log ( $ "[ScreenTapManager] Raycast 히트: { hitCount } 개 오브젝트") ;
310+ for ( int i = 0 ; i < hitCount ; i ++ )
311+ {
312+ var drawable = results [ i ] . Drawable ;
313+ var worldPos = results [ i ] . WorldPosition ;
314+ var localPos = results [ i ] . LocalPosition ;
315+ var distance = results [ i ] . Distance ;
316+ 317+ Debug . Log ( $ "[ScreenTapManager] 히트 { i } : Drawable={ drawable . name } , 월드위치={ worldPos } , 로컬위치={ localPos } , 거리={ distance : F2} ") ;
318+ }
319+ }
203320 return true ;
204321 }
205322
323+ if ( _enableDebugLog )
324+ {
325+ Debug . Log ( "[ScreenTapManager] Raycast 히트 없음" ) ;
326+ }
327+ 206328 return false ;
207329 }
208330 #endregion
0 commit comments