instanceID | The instance ID of the Instant Asset table to serialize. |
outputPath | WriteInstantAssetTable(int instanceID, string outputPath). |
bool True on successful completion, WriteInstantAssetTable(int instanceID, string outputPath).
Writes an Instant Asset table to the specified output path. This method serializes the asset table data associated with the given instance ID.
This method is primarily used to save modified asset tables after operations like merging or subtracting tables. The resulting file can be loaded at runtime by the Instant Asset system.
using UnityEditor; using UnityEngine; using System.IO;
public class MergeTablesExample { [MenuItem("InstantAsset/Merge Instant Tables")] static void MergeInstantTables() { // Set the root path for InstantAsset operations InstantAsset.SetInstantAssetRootPath(Application.streamingAssetsPath); // Define table paths string mainTablePath = "Assets/StreamingAssets/assets_prefabs"; string mergeTablePath = "Assets/StreamingAssets/assets_prefabs01"; string resultPath = "Assets/StreamingAssets/merged_table";
// Load the asset tables InstantAssetTable mainTable = InstantAsset.ReadAssetTable(mainTablePath) as InstantAssetTable; InstantAssetTable mergeTable = InstantAsset.ReadAssetTable(mergeTablePath) as InstantAssetTable;
if (mainTable != null && mergeTable != null) { // Perform merge operation mainTable.MergeFrom(mergeTable); // Write the merged result to output file bool success = InstantAssetEditorUtility.WriteInstantAssetTable( mainTable.GetInstanceID(), resultPath);
if (success) { Debug.Log($"Successfully merged and wrote table to: {resultPath}"); } else { Debug.LogError($"Failed to write merged table to: {resultPath}"); }
// Clean up loaded tables InstantAsset.UnloadAssetTable(mainTable); InstantAsset.UnloadAssetTable(mergeTable); } else { Debug.LogError("Failed to load one or both asset tables"); } } }