Unreal
ViveportApiDemo.h
#include "Components/ActorComponent.h"
#include "ViveportApiDemo.generated.h"
#include "ViveportApi.h"
UCLASS( ClassGroup=(Viveport), meta=(BlueprintSpawnableComponent) )
class VIVEPORTSDK_API UViveportApiDemo : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UViveportApiDemo();
// Called when the game starts
void BeginPlay() override;
// Called every frame
void TickComponent(
float DeltaTime,
ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction
) override;
/** The APP ID for auth verify */
FString VIVEPORT_ID = "content's VIVEPORT ID";
/** Public key for auth verify */
FString VIVEPORT_KEY = "content's VIVEPORT KEY";
private:
// callback interface
class MyLicenseChecker : public UViveportApi::LicenseChecker
{
public:
void OnSuccess(
long long issue_time,
long long expiration_time,
int latest_version,
bool update_required
) override;
void OnFailure(
int errorCode,
const FString& errorMessage
) override;
};
MyLicenseChecker myLicenseChecker;
};
ViveportApiDemo.cpp
#include "ViveportSDKPrivatePCH.h"
#include "ViveportApiDemo.h"
UViveportApiDemo::UViveportApiDemo()
{
bWantsBeginPlay = true;
PrimaryComponentTick.bCanEverTick = true;
}
// Called when the game starts
void UViveportApiDemo::BeginPlay()
{
Super::BeginPlay();
FString fstring = UViveportApi::Version();
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);
UViveportApi::GetLicense(&myLicenseChecker, VIVEPORT_ID, VIVEPORT_KEY);
}
// Called every frame
void UViveportApiDemo::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
}
void UViveportApiDemo::MyLicenseChecker::OnSuccess(long long issue_time, long long expiration_time,
int latest_version, bool update_required)
{
char result[256] = { '\0' };
sprintf_s(result, "Verify OK!\n issue_time=%lld,\n expiration_time=%lld,\n latest_version=%d,\n
update_required=%d", issue_time, expiration_time, latest_version, update_required);
FString fstring(result);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);
}
void UViveportApiDemo::MyLicenseChecker::OnFailure(int error_code, const FString& error_message)
{
char result[256] = { '\0' };
sprintf_s(result, "Verify failed!\n error_code=%d,\n error_message=%s", error_code,
TCHAR_TO_UTF8(*error_message));
FString fstring(result);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);
// DRM fail, close the content.
}