October3d55/M/PICOXRPlugin/Source/PICOXRMR/Private/PXR_AnchorComponent.cpp

57 lines
1.7 KiB
C++
Raw Normal View History

2025-07-29 14:53:32 +08:00
// Copyright PICO Technology Co., Ltd. All rights reserved.
// This plugin incorporates portions of the Unreal® Engine. Unreal® is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere.
// Copyright Epic Games, Inc. All Rights Reserved.
#include "PXR_AnchorComponent.h"
#include "PXR_ProviderManager.h"
UPICOAnchorComponent::UPICOAnchorComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
AnchorHandle = 0;
PrimaryComponentTick.bCanEverTick = true;
PrimaryComponentTick.bStartWithTickEnabled = true;
PrimaryComponentTick.TickGroup = TG_PostUpdateWork;
}
void UPICOAnchorComponent::BeginPlay()
{
Super::BeginPlay();
}
void UPICOAnchorComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (IsAnchorValid()&&IsValid(GetOwner()) && IsValid(GetWorld()))
{
EPICOResult OutResult=EPICOResult::PXR_Error_Unknow;
PXR_AnchorProvider::GetInstance()->UpdateAnchor(this,OutResult);
PXR_LOGV(PxrMR, "UpdateAnchor Result:%d", OutResult);
}
}
void UPICOAnchorComponent::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
if (IsAnchorValid())
{
if(FPICOProviderManager::ShouldUseLegacyMR())
{
PXR_AnchorProvider::GetInstance()->DestroyAnchorByHandleLegacy(AnchorHandle);
}
else
{
EPICOResult OutResult=EPICOResult::PXR_Error_Unknow;
PXR_AnchorProvider::GetInstance()->DestroyAnchorByHandle(AnchorHandle,OutResult);
PXR_LOGV(PxrMR, "DestroyAnchorByHandle Result:%d", OutResult);
}
ResetAnchorHandle();
}
}
void UPICOAnchorComponent::ResetAnchorHandle()
{
AnchorHandle.Reset();
}