Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Runtime/Scripts/GLTFSceneImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void Dispose()
// TODO check where the right place is to call OnBeforeImport as early as possible
foreach (var plugin in Context.Plugins)
{
plugin.OnBeforeImport();
await plugin.OnBeforeImportAsync();
}

if (_options.ThrowOnLowMemory)
Expand Down Expand Up @@ -458,14 +458,14 @@ public void Dispose()
if (_gltfRoot == null)
{
foreach (var plugin in Context.Plugins)
plugin.OnBeforeImportRoot();
await plugin.OnBeforeImportRootAsync();
await LoadJson(_gltfFileName);
progressStatus.IsDownloaded = true;
}

foreach (var plugin in Context.Plugins)
{
plugin.OnAfterImportRoot(_gltfRoot);
await plugin.OnAfterImportRootAsync(_gltfRoot);
}

cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -683,7 +683,7 @@ private void InitializeGltfTopLevelObject()
try
{
foreach (var plugin in Context.Plugins)
plugin.OnBeforeImportScene(scene);
await plugin.OnBeforeImportSceneAsync(scene);
}
catch (Exception e)
{
Expand Down Expand Up @@ -731,7 +731,7 @@ private void InitializeGltfTopLevelObject()
try
{
foreach (var plugin in Context.Plugins)
plugin.OnAfterImportScene(scene, sceneIndex, CreatedObject);
await plugin.OnAfterImportSceneAsync(scene, sceneIndex, CreatedObject);
}
catch (Exception e)
{
Expand Down Expand Up @@ -821,7 +821,7 @@ private async Task<GameObject> GetNode(int nodeId, CancellationToken cancellatio
try
{
foreach (var plugin in Context.Plugins)
plugin.OnAfterImportNode(node, nodeId, _assetCache.NodeCache[nodeId]);
await plugin.OnAfterImportNodeAsync(node, nodeId, _assetCache.NodeCache[nodeId]);
}
catch (Exception ex)
{
Expand Down
47 changes: 47 additions & 0 deletions Runtime/Scripts/Plugins/Core/GltfImportPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using GLTF.Schema;
using UnityEngine;

Expand Down Expand Up @@ -61,5 +62,51 @@ public virtual void OnAfterImport()
{

}

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously.
// These methods can be overridden if an importer needs to call async functions.
// These are provided for backwards compatibility and by default, will call the
// synchronous version.

public virtual async Task OnBeforeImportAsync()
{
OnBeforeImport();
}

public virtual async Task OnBeforeImportRootAsync()
{
OnBeforeImportRoot();
}

public virtual async Task OnAfterImportRootAsync(GLTFRoot gltfRoot)
{
OnAfterImportRoot(gltfRoot);
}

public virtual async Task OnBeforeImportSceneAsync(GLTFScene scene)
{
OnBeforeImportScene(scene);
}

public virtual async Task OnAfterImportNodeAsync(Node node, int nodeIndex, GameObject nodeObject)
{
OnAfterImportNode(node, nodeIndex, nodeObject);
}

public virtual async Task OnAfterImportMaterialAsync(GLTFMaterial material, int materialIndex, Material materialObject)
{
OnAfterImportMaterial(material, materialIndex, materialObject);
}

public virtual async Task OnAfterImportTextureAsync(GLTFTexture texture, int textureIndex, Texture textureObject)
{
OnAfterImportTexture(texture, textureIndex, textureObject);
}

public virtual async Task OnAfterImportSceneAsync(GLTFScene scene, int sceneIndex, GameObject sceneObject)
{
OnAfterImportScene(scene, sceneIndex, sceneObject);
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously.
}
}
2 changes: 1 addition & 1 deletion Runtime/Scripts/SceneImporter/ImporterMaterials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ void SetTransformKeyword()

foreach (var plugin in Context.Plugins)
{
plugin.OnAfterImportMaterial(def, materialIndex, mapper.Material);
await plugin.OnAfterImportMaterialAsync(def, materialIndex, mapper.Material);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/SceneImporter/ImporterTextures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ TextureWrapMode UnityWrapMode(GLTF.Schema.WrapMode gltfWrapMode)

foreach (var plugin in Context.Plugins)
{
plugin.OnAfterImportTexture(texture, textureIndex, tex);
await plugin.OnAfterImportTextureAsync(texture, textureIndex, tex);
}
}
catch (Exception ex)
Expand Down