[Lunar Console] Unity6 - New Input에서 Swipe Down 안되는 버그 수정(우회)
Unity3D/Plugins / 2025. 8. 25. 16:11
[파일]
using UnityEngine;
#if UNITY_ANDROID || UNITY_IOS
using LunarConsolePlugin;
#endif
/// <summary>
/// 모바일 기기에서 멀티터치를 통해 LunarConsole을 활성화하는 도우미 클래스
/// </summary>
public class LunarConsoleAssist : MonoBehaviour
{
[Header("Touch Settings")]
[SerializeField, Range(2, 5)]
private int requiredFingers = 3;
[SerializeField, Range(0.1f, 2.0f)]
private float requiredHoldTime = 0.3f;
[Header("Debug")]
[SerializeField]
private bool enableDebugLog = false;
private float currentHoldTimer;
private bool isConsoleShown;
// 성능 최적화를 위한 캐싱
private Touch[] cachedTouches;
private void Awake()
{
// 필요한 경우에만 초기화
#if !(UNITY_ANDROID || UNITY_IOS) || UNITY_EDITOR
if (enableDebugLog)
Debug.LogWarning("[LunarConsoleAssist] This component only works on Android/iOS devices.");
#endif
}
private void Update()
{
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
HandleTouchInput();
#endif
}
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
private void HandleTouchInput()
{
int touchCount = Input.touchCount;
// 필요한 손가락 수가 맞는지 확인
if (requiredFingers <= touchCount)
{
if (AreRequiredTouchesValid(touchCount))
{
currentHoldTimer += Time.unscaledDeltaTime;
if (requiredHoldTime <= currentHoldTimer && !isConsoleShown)
{
ShowLunarConsole();
}
}
else
{
ResetTimer();
}
}
else
{
ResetTimer();
}
}
private bool AreRequiredTouchesValid(int touchCount)
{
// 성능 최적화: 필요한 터치만 확인
int validTouchCount = 0;
for (int i = 0; i < touchCount && validTouchCount < requiredFingers; i++)
{
TouchPhase phase = Input.touches[i].phase;
if (IsTouchPhaseValid(phase))
{
validTouchCount++;
}
}
return requiredFingers <= validTouchCount;
}
private bool IsTouchPhaseValid(TouchPhase phase)
{
return phase == TouchPhase.Began ||
phase == TouchPhase.Stationary ||
phase == TouchPhase.Moved;
}
private void ShowLunarConsole()
{
try
{
LunarConsole.Show();
isConsoleShown = true;
if (enableDebugLog)
Debug.Log("[LunarConsoleAssist] Console activated!");
ResetTimer();
}
catch (System.Exception e)
{
if (enableDebugLog)
Debug.LogError($"[LunarConsoleAssist] Failed to show console: {e.Message}");
}
}
private void ResetTimer()
{
currentHoldTimer = 0f;
isConsoleShown = false;
}
#endif
#if UNITY_EDITOR
private void OnValidate()
{
// 에디터에서 값 검증
requiredFingers = Mathf.Clamp(requiredFingers, 2, 5);
requiredHoldTime = Mathf.Clamp(requiredHoldTime, 0.1f, 2.0f);
}
#endif
}
[출처] 지인
반응형
'Unity3D > Plugins' 카테고리의 다른 글
[github] Google Play Games plugin for Unity (0) | 2025.08.27 |
---|---|
[github] New Input System (0) | 2025.07.14 |
[링크] Anti Cheat Toolkit (0) | 2025.07.10 |
[링크] SPUM 최적화 처리 (드로우콜, 배칭) (0) | 2025.06.26 |
[링크] Unity에서 iOS/Android 앱 설정을 안전하게 처리하는 방법 (0) | 2025.04.21 |