GLTFImporter.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #if HAVE_GLTFAST || HAVE_UNITYGLTF
  2. #define ANOTHER_IMPORTER_HAS_HIGHER_PRIORITY
  3. #endif
  4. #if !ANOTHER_IMPORTER_HAS_HIGHER_PRIORITY && !GLTFUTILITY_FORCE_DEFAULT_IMPORTER_OFF
  5. #define ENABLE_DEFAULT_GLB_IMPORTER
  6. #endif
  7. #if GLTFUTILITY_FORCE_DEFAULT_IMPORTER_ON
  8. #define ENABLE_DEFAULT_GLB_IMPORTER
  9. #endif
  10. #if !UNITY_2020_2_OR_NEWER
  11. using UnityEditor.Experimental.AssetImporters;
  12. #else
  13. using UnityEditor.AssetImporters;
  14. #endif
  15. using UnityEngine;
  16. namespace Siccity.GLTFUtility {
  17. #if ENABLE_DEFAULT_GLB_IMPORTER
  18. [ScriptedImporter(1, "gltf")]
  19. #else
  20. [ScriptedImporter(1, null, overrideExts: new[] { "gltf" })]
  21. #endif
  22. public class GLTFImporter : ScriptedImporter {
  23. public ImportSettings importSettings;
  24. public override void OnImportAsset(AssetImportContext ctx) {
  25. // Load asset
  26. AnimationClip[] animations;
  27. if (importSettings == null) importSettings = new ImportSettings();
  28. GameObject root = Importer.LoadFromFile(ctx.assetPath, importSettings, out animations, Format.GLTF);
  29. // Save asset
  30. GLTFAssetUtility.SaveToAsset(root, animations, ctx, importSettings);
  31. }
  32. }
  33. }