105 lines
3.0 KiB
C++
105 lines
3.0 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Components/ActorComponent.h"
|
|
#include "MosisPhoneComponent.generated.h"
|
|
|
|
class UMaterialInstanceDynamic;
|
|
class UMosisPhoneTexture;
|
|
|
|
/**
|
|
* Touch event type for phone interactions.
|
|
*/
|
|
UENUM(BlueprintType)
|
|
enum class EMosisTouchType : uint8
|
|
{
|
|
Down,
|
|
Move,
|
|
Up
|
|
};
|
|
|
|
/**
|
|
* UMosisPhoneComponent - Component for displaying Mosis phone screen in UE5.
|
|
* Handles texture updates from the service and touch input forwarding.
|
|
*/
|
|
UCLASS(ClassGroup=(Mosis), meta=(BlueprintSpawnableComponent))
|
|
class MOSISSDK_API UMosisPhoneComponent : public UActorComponent
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UMosisPhoneComponent();
|
|
|
|
// UActorComponent interface
|
|
virtual void BeginPlay() override;
|
|
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
|
|
|
/**
|
|
* Send a touch event to the phone.
|
|
* @param NormalizedUV Touch position in UV coordinates (0-1)
|
|
* @param TouchType Type of touch event (Down, Move, Up)
|
|
*/
|
|
UFUNCTION(BlueprintCallable, Category = "Mosis")
|
|
void SendTouch(FVector2D NormalizedUV, EMosisTouchType TouchType);
|
|
|
|
/**
|
|
* Get the phone texture for rendering.
|
|
* @return The texture showing the phone screen, or nullptr if not ready
|
|
*/
|
|
UFUNCTION(BlueprintCallable, Category = "Mosis")
|
|
UTexture* GetPhoneTexture() const;
|
|
|
|
/**
|
|
* Check if the phone is connected and ready.
|
|
*/
|
|
UFUNCTION(BlueprintCallable, Category = "Mosis")
|
|
bool IsConnected() const;
|
|
|
|
/**
|
|
* Get the phone screen dimensions.
|
|
*/
|
|
UFUNCTION(BlueprintCallable, Category = "Mosis")
|
|
FIntPoint GetScreenSize() const { return FIntPoint(ScreenWidth, ScreenHeight); }
|
|
|
|
/**
|
|
* Material instance to apply the phone texture to.
|
|
* Set this to the material on your phone mesh.
|
|
*/
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Mosis")
|
|
UMaterialInstanceDynamic* PhoneMaterial;
|
|
|
|
/**
|
|
* Parameter name in the material for the phone texture.
|
|
*/
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Mosis")
|
|
FName TextureParameterName = TEXT("PhoneScreen");
|
|
|
|
protected:
|
|
/** Called when a new hardware buffer is received from the service. */
|
|
void OnBufferAvailable();
|
|
|
|
/** Called when a new frame is available for display. */
|
|
void OnFrameAvailable();
|
|
|
|
/** Update the texture on the render thread. */
|
|
void UpdateTextureOnRenderThread();
|
|
|
|
private:
|
|
/** Phone screen texture */
|
|
UPROPERTY()
|
|
TObjectPtr<UMosisPhoneTexture> PhoneTexture;
|
|
|
|
/** Screen dimensions from service */
|
|
int32 ScreenWidth = 0;
|
|
int32 ScreenHeight = 0;
|
|
|
|
/** Flag to track pending texture updates */
|
|
TAtomic<bool> bPendingTextureUpdate{false};
|
|
|
|
/** Flag to track if we need to recreate the texture */
|
|
TAtomic<bool> bNeedsTextureCreate{false};
|
|
};
|