UE4/C++: USaveData ç³»ã®ã»ã¼ããã¼ã¿ã® Slot 群ããã¹ã¦åå¾ããæ¹æ³
USaveData
æ´¾çåã®ã»ã¼ããã¼ã¿ãä½ã UGameplayStatics::SaveGameToSlot
, UGameplayStatics::LoadGameFromSlot
ãç¨ãã¦ã»ã¼ãã¨ãã¼ããå®è£
ããææ³ãç¨ããã¨ããèªä½ã®å®è£
å´åã¯ç¯ç´ã§ãã¦å¬ããããããããããã® API 㯠UE4 ããã¸ã§ã¯ãã®éçºæã«æåååã® Slot
ã確å®ãã¦ããåæã§è¨è¨ããã¦ããããããå®è¡æã«ã¦ã¼ã¶ã¼ãä»»æã® Slot
å称ãä¸ããã¦ã¼ã¹ã±ã¼ã¹ã§ã¯ãã®ä¸è¦§ã®åå¾ãè¡ãæ段ãç¡ãï¼UE4-4.21ç¾å¨ï¼ã
ãã®ããããã£ã¦ããä¸è¬çã«å¤ãã® UE4 ããã¸ã§ã¯ãã§ã¯ãSlot
ãéçºæã«å¹¾ã¤ãã®åºå®ã®å称ãããããã¯é£çªãæåååãã¦å¦çããä»çµã¿ãæ¡ç¨ãããä¾ãå¤ãããã«è¦ãããå®éã«ã²ã¼ã ã¨ãã¦æµéããã¢ããªã§ãã»ã¼ããã¼ã¿ãã¹ããã0çªããNçªã®ããã«é£çªã§ç¨æããã¦ããä¾ãå¤ãè¦ãããï¼å人ã®ææ³ã§ãï¼ãä¸è¬çã«å¹¾ã¤ãã®ã»ã¼ãã¹ããããç¨æããæ¹å¼ã§æ§ããªãã¢ããªã§ã¯ãããã対å¿ã§ãç°¡åãã¤ã¦ã¼ã¶ã¼ã«ã¨ã£ã¦ãååã§å®ç¨ã«ãåé¡ç¡ãå¿«é©ã«ä½¿ç¨ã§ããã
ããããããã§ã¯ãªããã¦ã¼ã¶ã¼ã«å¯è½ãªéãä»»ææ§ã®é«ã Slot
å称ãä¸ãããä»çµã¿ãå¿
è¦ãªã¢ããªãä½ãããå ´åãããããã®ãããªå ´åã«ã¯ã次ã®æ§ã«ãã¦å®è¡ä¸ã® UE4 ã¢ããªã®ã»ã¼ããã¼ã¿ã® Slot
ã®ä¸è¦§ãåå¾ããå®è£
ãããã¸ã§ã¯ãã¸å®è£
ãã:
// MySaveDataUtility.h #pragma once #include "CoreMinimal.h" #include "Kismet/BlueprintFunctionLibrary.h" #include "MySaveDataUtility.generated.h" UCLASS() class UMySaveDataUtility : public UBlueprintFunctionLibrary { GENERATED_BODY() public: UFUNCTION( BlueprintCallable, BlueprintPure ) static TArray< FString > GetSaveSlots(); };
// MySaveDataUtility.cpp #pragma once #include "MySaveDataUtility.h" #include "Runtime/Engine/Public/PlatformFeatures.h" #include "Runtime/Core/Public/HAL/PlatformFilemanager.h" #include "Runtime/Core/Public/Misc/LocalTimestampDirectoryVisitor.h" #include "Runtime/Engine/Classes/Kismet/GameplayStatics.h" DEFINE_LOG_CATEGORY_STATIC( MySaveDataUtility , Log, All ); TArray< FString > UMySaveDataUtility::GetSaveSlots() { TArray< FString > Slots; if ( ! IPlatformFeaturesModule::Get().GetSaveGameSystem() ) { UE_LOG( MySaveDataUtility, Error, TEXT( "GetSaveSlots: GetSaveGameSystem was failed." ) return { }; } TArray< FString > Empty; IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); FLocalTimestampDirectoryVisitor Visitor( PlatformFile, Empty, Empty, false ); PlatformFile.IterateDirectory( *( FPaths::ProjectSavedDir() / TEXT( "SaveGames" ) ), Visitor ); for ( TMap< FString, FDateTime >::TIterator i( Visitor.FileTimes ); i; ++i) { const FString FilePath = i.Key(); const FString FileName = FPaths::GetCleanFilename( FilePath ); if ( FPaths::GetExtension( FileName, false ).Equals( TEXT( "sav" ), ESearchCase::IgnoreCase) ) Slots.Emplace( FPaths::GetBaseFilename( FileName ) ); } return Slots; }
ã»ã¼ããã¼ã¿ã®ãã£ã¬ã¯ããªã¼ãæµãã .sav
æ¡å¼µåã®ãã¡ã¤ã«ãã¼ã¹åé¨åã Slot
å称ã¨ãã¦ååãã¦ã»ã¼ããã¼ã¿ç¾¤ã® Slot
ã®ä¸è¦§ãåå¾ãã¦ãããæ³¥èã(´ã»Ïã»ï½)
å¥æ³ã¨ãã¦ã¯ãããã Slot
ã使ããã« UGameplayStatics::SaveGameFromMemory
, UGameplayStatics::LoadGameFromMemory
ã使ãã UE4 ãç¨æãã Saved/SaveGames
ã¸ã®ãã¡ã¤ã«ä¿åã®ä»çµã¿ã使ããã«ããã°ã©ãã¼ãç´æ¥ãã¡ã¤ã«ã·ã¹ãã ãªãä¿åå
ã®ãã¼ã¿ãã¼ã¹ãªããªã³ã©ã¤ã³ã®ã¹ãã¬ã¼ã¸ãªãä½ãªãã®å¶å¾¡ãå®è£
ãã¦ã»ã¼ããã¼ã¿ãã·ãªã¢ã©ã¤ãºããæ¹æ³ããããã¨ãè¨ã£ã¦ãããã®ãããªå¿
è¦ãªå¿
è¦ãããå ´åã¯ããããã USaveData
ã使ããã« UE4 ã¨ã¯ç¬ç«ããã»ã¼ããã¼ã¿ã®ã·ãªã¢ã©ã¤ã¶ã¼ãå®è£
ããæ¹ãåãå ´åãå¤ããããããªãã