Closed BattlehubCode closed 1 month ago
See PlayViewModel.cs for details, but essentially you only need the AssetDatabaseModel prefab in the scene, and you need to call the LoadProject method like this:
using UnityEngine
using Battlehub.RTCommon;
using Battlehub.RTEditor.Models;
var assetDatabaseModel = IOC.Resolve<IAssetDatabaseModel>("AssetDatabaseModel");
var projectID = $"{Application.persistentDataPath}/Project";
await assetDatabaseModel.LoadProjectAsync(projectID);
protected async Task<string> AddFileToLibraryAsync(string basePath, string relativePath, Guid desiredAssetID)
{
string filePath = $"{basePath}/{relativePath}";
string libraryFolder = Editor.GetFolderInLibrary(desiredAssetID);
string libraryFolderFullPath = $"{Editor.LibraryRootFolder}/{libraryFolder}";
if (!Directory.Exists(libraryFolderFullPath))
{
Directory.CreateDirectory(libraryFolderFullPath);
}
string targetPath = $"{libraryFolderFullPath}/{relativePath}";
string targetDir = Path.GetDirectoryName(targetPath);
if (!Directory.Exists(targetDir))
{
Directory.CreateDirectory(targetDir);
}
if (IsUrl(filePath))
{
var bytes = await DownloadBytesAsync(filePath);
File.WriteAllBytes(targetPath, bytes);
}
else
{
File.Copy(filePath, targetPath, true);
}
string externalAssetKey = $"{libraryFolder}/{relativePath}";
return externalAssetKey;
}
Another possible approach is to use the following IAssetDatabaseModel methods. These methods write data to a key/value store inside the .Library folder. You can use any serializable type with the [ProtoContract] attribute as T or string or byte[] if you prefer.
Task<T> GetValueAsync<T>(string key);
Task SetValueAsync<T>(string key, T obj);
Task DeleteValueAsync<T>(string key);
I'm using the app to export the scene root, which is then imported into another application that uses the same surrogate files and the runtime asset database. I tried to save the scene root as an asset and import it with the .meta file into the other app, but some content was missing, like the textures I imported externally and some materials. I also tried setting the same project folder for both apps, and the textures were showing up, but some materials were still missing. Do you have any suggestions on the best approach to handle this task?
Is there a possibility to add additional information to a given asset, perhaps in the form of a metafile? I was wondering if it's possible to extend the metafiles already created by the Runtime Editor, so I can add information to certain types of assets, maybe during the import or creation process (for example, for a texture or a 3D model).
Is it possible to create and save other types of assets that are beyond textures, prefabs, etc.? For instance, would it be possible to create texts and give the option to save those texts in the editor so they can be reused in other scenes (just as an example)?