39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using JetBrains.Annotations;
|
|
using Needle.Cloud.Runtime;
|
|
using Needle.Engine.Gltf;
|
|
using UnityEngine;
|
|
|
|
namespace Needle.Cloud.Editor
|
|
{
|
|
[UsedImplicitly]
|
|
public class CloudExportHandler : GltfExtensionHandlerBase
|
|
{
|
|
private readonly List<Object> tempObjects = new List<Object>();
|
|
|
|
public override void OnBeforeExport(GltfExportContext context)
|
|
{
|
|
base.OnBeforeExport(context);
|
|
var cloudAssets = context.Root.GetComponentsInChildren<NeedleCloudAsset>();
|
|
foreach (var cloud in cloudAssets)
|
|
{
|
|
OnHandleCloudAsset(cloud.transform, cloud);
|
|
}
|
|
}
|
|
|
|
private void OnHandleCloudAsset(Transform t, NeedleCloudAsset asset)
|
|
{
|
|
var ng = t.gameObject.AddComponent<NestedGltf>();
|
|
ng.hideFlags = HideFlags.DontSave;
|
|
ng.LoadAssetInParent = false;
|
|
tempObjects.Add(ng);
|
|
ng.FilePath = asset.Url;
|
|
}
|
|
|
|
public override void OnExportFinished(GltfExportContext context)
|
|
{
|
|
base.OnExportFinished(context);
|
|
tempObjects.ForEach(Object.DestroyImmediate);
|
|
}
|
|
}
|
|
} |