UE4 安卓觸摸事件相關問題 | 您所在的位置:網(wǎng)站首頁 › 屬羊有幾個孩子女男孩 › UE4 安卓觸摸事件相關問題 |
UE4在安卓端獲取輸入信息時候,似乎會把觸摸事件和PC端的鼠標事件弄混在一起,導致出現(xiàn)一些奇怪的問題。 1. /* 安卓端會把觸摸事件讀取成PC端的鼠標事件,因為Turn和LookUp在PC端開發(fā)時候一般都綁定在鼠標X軸,Y軸上, * 所以這里要對安卓端做一些特殊處理。 */ #if !PLATFORM_ANDROID ? PlayerInputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput); ? PlayerInputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput); #endif? 2. 在列表中放置按鈕時候因為需要把按鈕的 ClickMethod設置為 PreciseClick,這樣才能在左鍵拖動鼠標時候滑動列表。對應的在移動端設備中則應該修改TouchMethod為 PreciseTap,這樣才能滑動列表,但是同理因為安卓端的問題,該處地方 ClickMethod 不能為PreciseClick,改為 DownAndUp就好。 如若不然,可能會導致個別奇怪問題,比如某個地方的按鈕不能接收到ClickEvent。 ? 3.在PlayerController的InputTouch函數(shù)中獲取到的TouchLocation時,TouchBegin和TouchMove消息獲取的位置比TouchEnd的位置大1.5倍。而且通過PlayerInputComponent綁定的TouchEnd消息不能觸發(fā)。 ? bool AMyPlayerController::InputTouch(uint32 Handle, ETouchType::Type Type, const FVector2D& TouchLocation, float Force, FDateTime DeviceTimestamp, uint32 TouchpadIndex) { #if PLATFORM_ANDROID FVector2D EndTouchLocation = TouchLocation; //end消息在android下存在問題,需要乘以1.5倍 if (Type == ETouchType::Ended) { EndTouchLocation *= 1.5f; } #endif ... }//本文為CSDN博主執(zhí)手畫眉彎原創(chuàng),未經(jīng)允許不得轉(zhuǎn)載! bool AMyCharacter::EnableTouchscreenMovement(class UInputComponent* PlayerInputComponent) { if (FPlatformMisc::SupportsTouchInput() || GetDefault()->bUseMouseForTouch) { PlayerInputComponent->BindTouch(EInputEvent::IE_Pressed, this, &AMyCharacter::BeginTouch); #if !PLATFORM_ANDROID //安卓設備接收不到結(jié)束點擊事件 PlayerInputComponent->BindTouch(EInputEvent::IE_Released, this, &AMyCharacter::EndTouch); #endif //Commenting this out to be more consistent with FPS BP template. PlayerInputComponent->BindTouch(EInputEvent::IE_Repeat, this, &AMyCharacter::TouchUpdate); return true; } return false; }//本文為CSDN博主執(zhí)手畫眉彎原創(chuàng),未經(jīng)允許不得轉(zhuǎn)載!注:EnableTouchscreenMovement函數(shù)在重載的SetupPlayerInputComponent函數(shù)中調(diào)用。 ? |
今日新聞 |
推薦新聞 |
專題文章 |
CopyRight 2018-2019 實驗室設備網(wǎng) 版權(quán)所有 |