[UE4]为UStaticMeshComponent添加点击事件


BlockMesh->OnClicked.AddDynamic(this, &APuzzleBlock::BlockClicked);   //鼠标点击事件
BlockMesh->OnInputTouchBegin.AddDynamic(this, &APuzzleBlock::OnFingerPressedBlock);   //触摸屏点击事件

void APuzzleBlock::BlockClicked(UPrimitiveComponent* ClickedComp)
{
    bIsActive = !bIsActive; // flip the value of bIsActive
                            // (if it was true, it becomes false, or vice versa)
    if (bIsActive)
    {
        BlockMesh->SetMaterial(0, OrangeMaterial);
    }
    else
    {
        BlockMesh->SetMaterial(0, BlueMaterial);
    }
    // Tell the Grid
    if (OwningGrid != NULL)
    {
        OwningGrid->AddScore();
    }
    // --TO HERE--
}


void APuzzleBlock::OnFingerPressedBlock(ETouchIndex::Type FingerIndex, UPrimitiveComponent* TouchedComponent)
{
    BlockClicked(TouchedComponent);
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM