Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69a4a6c

Browse files
committed
feat: 스크린텝 디버그 추가
1 parent e50adbf commit 69a4a6c

File tree

2 files changed

+130
-3
lines changed

2 files changed

+130
-3
lines changed

‎Assets/App/Scenes/Live2d Sence.unity‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ MonoBehaviour:
148148
m_Script: {fileID: 11500000, guid: 220500989a5e4164381615ebdf1a6e33, type: 3}
149149
m_Name:
150150
m_EditorClassIdentifier:
151+
_enableDebugLog: 1
152+
_enableDebugRay: 1
153+
_debugRayColor: {r: 1, g: 0, b: 0, a: 1}
154+
_debugRayDuration: 2
151155
--- !u!4 &194973789
152156
Transform:
153157
m_ObjectHideFlags: 0
@@ -768,6 +772,7 @@ MonoBehaviour:
768772
_dependencyManager: {fileID: 0}
769773
_autoInitializeOnStart: 1
770774
_createManagersIfNotExist: 1
775+
_autoUpdateCameraOnSceneChange: 1
771776
_camera: {fileID: 0}
772777
--- !u!1 &2028963604
773778
GameObject:

‎Assets/Core/Input/ScreenTapManager.cs‎

Lines changed: 125 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public interface IInputProvider
77
{
88
bool TryGetPosition(out Vector3 position);
9+
bool IsUIBlockingInput();
910
}
1011

1112
public 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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /