Files
AR-Menu/Library/PackageCache/com.unity.cloud.gltfast@db5a82ec0b47/DocExamples/SimpleExport.cs
2025-11-30 08:35:03 +02:00

39 lines
1015 B
C#

// SPDX-FileCopyrightText: 2024 Unity Technologies and the glTFast authors
// SPDX-License-Identifier: Apache-2.0
namespace GLTFast.Documentation.Examples
{
#region SimpleExport
using UnityEngine;
using Export;
class SimpleExport : MonoBehaviour
{
[SerializeField]
string destinationFilePath;
async void Start()
{
// Example of gathering GameObjects to be exported (recursively)
var rootLevelNodes = GameObject.FindGameObjectsWithTag("ExportMe");
// GameObjectExport lets you create glTF files from GameObject hierarchies
var export = new GameObjectExport();
// Add a scene
export.AddScene(rootLevelNodes);
// Async glTF export
var success = await export.SaveToFileAndDispose(destinationFilePath);
if (!success)
{
Debug.LogError("Something went wrong exporting a glTF");
}
}
}
#endregion
}