public bool HasAssetChanged(FAssetData asset, string assetFileName) { FileInfo fileInfo = new FileInfo(assetFileName); DateTime cachedlastModified; if (fileInfo.Exists && (!Assets.TryGetValue(assetFileName, out cachedlastModified) || fileInfo.LastWriteTime != cachedlastModified)) { Assets[assetFileName] = fileInfo.LastWriteTime; return(true); } return(false); }
public void GenerateCodeForBlueprints(AssetLoadMode loadMode, bool clearAssetCache, bool skipLevels) { BeginGenerateModules(); string projectPath = FPaths.ProjectFilePath; string projectName = FPaths.GetBaseFilename(projectPath); UnrealModuleInfo module = new UnrealModuleInfo(null, projectName, projectPath); BeginGenerateModule(module); UClass worldClass = GCHelper.Find <UClass>(Classes.UWorld); AssetCache assetCache = new AssetCache(this); if (!clearAssetCache) { assetCache.Load(); } List <string> assetBlacklist = LoadAssetBlacklist(); AssetLogClear(); AssetLogLine("Load assets {0}", DateTime.Now); bool registeredCrashHandler = false; if (Settings.CatchCrashOnAssetLoading) { FCoreDelegates.OnHandleSystemError.Bind(OnAssetLoadingCrash); registeredCrashHandler = true; } using (FARFilter filter = new FARFilter()) { filter.RecursiveClasses = true; filter.ClassNames.Add(UClass.GetClass <UBlueprint>().GetFName()); filter.ClassNames.Add(UClass.GetClass <UBlueprintGeneratedClass>().GetFName()); filter.ClassNames.Add(UClass.GetClass <UUserDefinedStruct>().GetFName()); filter.ClassNames.Add(UClass.GetClass <UUserDefinedEnum>().GetFName()); if (!skipLevels && worldClass != null) { filter.ClassNames.Add(worldClass.GetFName()); } List <FAssetData> assets = FAssetData.Load(filter); SlowTaskSetModuleCount(1); SlowTaskBeginModule("Blueprints", assets.Count); foreach (FAssetData asset in assets) { SlowTaskStep(null); string assetFileName, assetFileNameError; if (!asset.TryGetFilename(out assetFileName, out assetFileNameError)) { FMessage.Log(string.Format("FAssetData.TryGetFilename failed. ObjectPath:'{0}' reason:'{1}'", asset.ObjectPath.ToString(), assetFileNameError)); continue; } bool isEngineAsset = FPaths.IsSameOrSubDirectory(FPaths.EngineContentDir, FPaths.GetPath(assetFileName)); if (loadMode != AssetLoadMode.All) { if ((isEngineAsset && loadMode != AssetLoadMode.Engine) || (!isEngineAsset && loadMode != AssetLoadMode.Game)) { continue; } } if (!assetCache.HasAssetChanged(asset, assetFileName)) { if (Settings.LogAssetLoadingVerbose) { AssetLogLine("'{0}' unchanged", assetFileName); } continue; } // Log that we are loading this asset so we know which assets crash on load AssetLog("'{0}' - ", asset.ObjectPath.ToString()); if (assetBlacklist.Contains(asset.ObjectPath.ToString())) { AssetLogLine("blacklisted"); continue; } loadingAsset = asset.ObjectPath.ToString(); UObject obj = asset.GetAsset(); loadingAsset = null; UClass unrealClass = asset.GetClass(); if (obj == null || unrealClass == null) { AssetLogLine("null"); continue; } AssetLogLine("done"); if (unrealClass.IsChildOf <UBlueprint>()) { UBlueprint blueprint = obj as UBlueprint; if (blueprint != null) { UBlueprintGeneratedClass blueprintGeneratedClass = blueprint.GeneratedClass as UBlueprintGeneratedClass; if (blueprintGeneratedClass != null) { GenerateCodeForStruct(module, blueprintGeneratedClass); } } } else if (unrealClass.IsChildOf <UBlueprintGeneratedClass>()) { UBlueprintGeneratedClass blueprintGeneratedClass = obj as UBlueprintGeneratedClass; if (blueprintGeneratedClass != null) { GenerateCodeForStruct(module, blueprintGeneratedClass); } } else if (unrealClass.IsChildOf <UUserDefinedStruct>()) { UUserDefinedStruct unrealStruct = obj as UUserDefinedStruct; if (unrealStruct != null) { GenerateCodeForStruct(module, unrealStruct); } } else if (unrealClass.IsChildOf <UUserDefinedEnum>()) { UUserDefinedEnum unrealEnum = obj as UUserDefinedEnum; if (unrealEnum != null) { GenerateCodeForEnum(module, unrealEnum); } } else if (unrealClass.IsChildOf(worldClass)) { TArrayUnsafeRef <UObject> levels = new TArrayUnsafeRef <UObject>(Native.Native_UWorld.GetLevels(obj.Address)); foreach (UObject level in levels) { using (TArrayUnsafe <UBlueprint> levelBlueprints = new TArrayUnsafe <UBlueprint>()) { Native.Native_ULevel.GetLevelBlueprints(level.Address, levelBlueprints.Address); foreach (UBlueprint blueprint in levelBlueprints) { UBlueprintGeneratedClass blueprintGeneratedClass = blueprint.GeneratedClass as UBlueprintGeneratedClass; if (blueprintGeneratedClass != null) { //GenerateCodeForStruct(blueprintGeneratedClass); } } } } } } } if (registeredCrashHandler) { FCoreDelegates.OnHandleSystemError.Unbind(OnAssetLoadingCrash); } assetCache.Save(); EndGenerateModule(module); EndGenerateModules(); }
public static List <FAssetData> Load(FARFilter filter) { List <FAssetData> assets = new List <FAssetData>(); IntPtr assetsArrayPtr = Native_FAssetRegistryModule.GetAssets(filter.GetAddress()); TArrayUnsafeRef <FAssetDataNative> nativeAssets = new TArrayUnsafeRef <FAssetDataNative>(assetsArrayPtr); for (int i = 0; i < nativeAssets.Count; i++) { FAssetDataNative nativeAsset = nativeAssets[i]; FAssetData asset = new FAssetData(); asset.ObjectPath = nativeAsset.ObjectPath; asset.PackageName = nativeAsset.PackageName; asset.PackagePath = nativeAsset.PackagePath; asset.AssetName = nativeAsset.AssetName; asset.AssetClass = nativeAsset.AssetClass; asset.IsValid = Native_FAssetData.IsValid(ref nativeAsset); asset.IsUAsset = Native_FAssetData.IsUAsset(ref nativeAsset); asset.IsRedirector = Native_FAssetData.IsRedirector(ref nativeAsset); using (FStringUnsafe fullNameUnsafe = new FStringUnsafe()) { Native_FAssetData.GetFullName(ref nativeAsset, ref fullNameUnsafe.Array); asset.FullName = fullNameUnsafe.Value; } using (FStringUnsafe exportTextNameUnsafe = new FStringUnsafe()) { Native_FAssetData.GetExportTextName(ref nativeAsset, ref exportTextNameUnsafe.Array); asset.ExportTextName = exportTextNameUnsafe.Value; } FName[] tags = null; string[] values = null; using (TArrayUnsafe <FName> tagsUnsafe = new TArrayUnsafe <FName>()) using (TArrayUnsafe <string> valuesUnsafe = new TArrayUnsafe <string>()) { Native_FAssetData.Get_TagsAndValues(ref nativeAsset, tagsUnsafe.Address, valuesUnsafe.Address); tags = tagsUnsafe.ToArray(); values = valuesUnsafe.ToArray(); } if (tags != null && values != null && tags.Length == values.Length) { for (int j = 0; j < tags.Length; j++) { asset.TagsAndValues[tags[j]] = values[j]; } } using (TArrayUnsafe <int> chunkIdsUnsafe = new TArrayUnsafe <int>(nativeAsset.ChunkIDs)) { asset.ChunkIDs.AddRange(chunkIdsUnsafe.ToArray()); } assets.Add(asset); } Native_FAssetRegistryModule.DeleteAssetsArray(assetsArrayPtr); return(assets); }