BattlehubCode / RTE_Docs

This is a repository for Runtime Editor documentation, discussion and tracking features and issues.
https://assetstore.unity.com/packages/tools/modeling/runtime-editor-64806
11 stars 0 forks source link

Questions about asset management #132

Closed BattlehubCode closed 2 days ago

BattlehubCode commented 2 days ago
  1. 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?

  2. 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).

  3. 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)?

BattlehubCode commented 2 days ago
  1. You can use import/export projects in different apps using following methods https://github.com/BattlehubCode/RTE_Docs?tab=readme-ov-file#import-export-project In Runtime Editor 4.4.3 I added an example scene (Scene 34 - Edit & Play) that shows how to load a project without the runtime editor, just using AssetDatabaseModel.prefab. Screenshot 2024-10-11 at 12 47 00 AM

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:

Screenshot 2024-10-11 at 12 21 36 AM
using UnityEngine
using Battlehub.RTCommon;
using Battlehub.RTEditor.Models;

var assetDatabaseModel = IOC.Resolve<IAssetDatabaseModel>("AssetDatabaseModel");
var projectID = $"{Application.persistentDataPath}/Project";
await assetDatabaseModel.LoadProjectAsync(projectID);
  1. There are no additional description fields in meta file right now. As a workaround I think it is possible to write additional metadata as a text files with the same ID as your asset into the .Library folder inside your project. The .Library folder is not visible in Runtime Editor ui. For example, see the caching code in ImporterModel.cs, which creates a folder named assetID and places the .fbx or .gltf files and images of the imported model there. This cache folder will then be automatically deleted after deletion of corresponding asset.
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);
  1. Yes create type derived from UnityEngine.ScriptableObject for example class MyAsset : ScriptableObject {} . Then you can work with it just like with any other asset Material, Mesh etc. https://github.com/BattlehubCode/RTE_Docs?tab=readme-ov-file#serializer-extensions https://github.com/BattlehubCode/RTE_Docs?tab=readme-ov-file#dynamic-surrogates-preview