Unreal异步加载类

异步加载类:AsyncLoading.cpp。AsyncLoadingThread.h,使用FAsyncLoadingThread异步处理

int32 LoadPackageAsync(const FString& InName, const FGuid* InGuid /*= nullptr*/, const TCHAR* InPackageToLoadFrom /*= nullptr*/, FLoadPackageAsyncDelegate InCompletionDelegate /*= FLoadPackageAsyncDelegate()*/, EPackageFlags InPackageFlags /*= PKG_None*/, int32 InPIEInstanceID /*= INDEX_NONE*/, int32 InPackagePriority /*= 0*/)
{
	static bool bOnce = false;
	if (!bOnce && GEventDrivenLoaderEnabled)
	{
		bOnce = true;
		FGCObject::StaticInit(); // otherwise this thing is created during async loading, but not associated with a package
	}

	// The comments clearly state that it should be a package name but we also handle it being a filename as this function is not perf critical
	// and LoadPackage handles having a filename being passed in as well.
	FString PackageName;
	if (FPackageName::IsValidLongPackageName(InName, /*bIncludeReadOnlyRoots*/true))
	{
		PackageName = InName;
	}
	// PackageName got populated by the conditional function
	else if (!(FPackageName::IsPackageFilename(InName) && FPackageName::TryConvertFilenameToLongPackageName(InName, PackageName)))
	{
		// PackageName will get populated by the conditional function
		FString ClassName;
		if (!FPackageName::ParseExportTextPath(PackageName, &ClassName, &PackageName))
		{
			UE_LOG(LogStreaming, Fatal, TEXT("LoadPackageAsync failed to begin to load a package because the supplied package name was neither a valid long package name nor a filename of a map within a content folder: '%s'"), *PackageName);
		}
	}

	FString PackageNameToLoad(InPackageToLoadFrom);
	if (PackageNameToLoad.IsEmpty())
	{
		PackageNameToLoad = PackageName;
	}
	// Make sure long package name is passed to FAsyncPackage so that it doesn't attempt to 
	// create a package with short name.
	if (FPackageName::IsShortPackageName(PackageNameToLoad))
	{
		UE_LOG(LogStreaming, Fatal, TEXT("Async loading code requires long package names (%s)."), *PackageNameToLoad);
	}

	if ( FCoreDelegates::OnAsyncLoadPackage.IsBound() )
	{
		FCoreDelegates::OnAsyncLoadPackage.Broadcast(InName);
	}

	// Generate new request ID and add it immediately to the global request list (it needs to be there before we exit
	// this function, otherwise it would be added when the packages are being processed on the async thread).
	const int32 RequestID = GPackageRequestID.Increment();
	FAsyncLoadingThread::Get().AddPendingRequest(RequestID);

	// Allocate delegate on Game Thread, it is not safe to copy delegates by value on other threads
	TUniquePtr<FLoadPackageAsyncDelegate> CompletionDelegatePtr;
	if (InCompletionDelegate.IsBound())
	{
		CompletionDelegatePtr.Reset(new FLoadPackageAsyncDelegate(InCompletionDelegate));
	}

	// Add new package request
	FAsyncPackageDesc PackageDesc(RequestID, *PackageName, *PackageNameToLoad, InGuid ? *InGuid : FGuid(), MoveTemp(CompletionDelegatePtr), InPackageFlags, InPIEInstanceID, InPackagePriority);
	FAsyncLoadingThread::Get().QueuePackage(PackageDesc);

	return RequestID;
}

所有异步加载最后应该都在这里。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Unreal Engine中,可以通过使用一些内置的功能和加载本地图片。 要加载本地图片,首先需要将图片文件拷贝到你的Unreal项目目录中的合适位置,比如放在Content文件夹下的Images子文件夹中。 然后,我们需要创建一个引用来访问该图片。可以在Unreal编辑器中通过右键单击Content面板并选择“Import”来导入图片文件。然后,选择你刚刚拷贝到项目文件夹的图片,并点击“导入”。 导入完成后,你可以在Content面板中找到该图片,并且可以在Level编辑器中拖拽它来将其放置在场景中。 接下来,我们需要在蓝图或者代码中加载该图片。如果在蓝图中操作,可以使用Texture2D型的变量来存储加载的图片。首先,创建一个Texture2D型的变量并将其拖拽到场景中。 然后,使用“Create Texture 2D”节点来创建一个Texture2D实例,并通过“Load Texture 2D From File”节点来读取本地图片文件,最后将该Texture2D实例赋值给变量。 如果是在代码中加载图片,可以使用FTexture2DDynamicResource加载本地图片,设置其路径并调用Load()方法完成加载。 无论是在蓝图中还是在代码中加载图片,一旦加载完成,你就可以将其用于材质、UI、纹理等任何需要图片资源的地方了。 综上所述,通过上述步骤和方法,你可以在Unreal Engine中加载本地图片并在项目中使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值