From 0665439dbecbf2d31507848eb73c061b8f9f21d3 Mon Sep 17 00:00:00 2001 From: Robert Dorn Date: Wed, 4 Sep 2024 15:01:36 +0200 Subject: [PATCH] added Asset.ToString methods, added gltf.Asset string to importer and extend the Importer Inspector with new Info tab --- Editor/Scripts/GLTFImporter.cs | 4 +-- Editor/Scripts/GLTFImporterInspector.cs | 23 ++++++++++++ .../Plugins/GLTFSerialization/Schema/Asset.cs | 35 +++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Editor/Scripts/GLTFImporter.cs b/Editor/Scripts/GLTFImporter.cs index 080872f31..9476fe477 100644 --- a/Editor/Scripts/GLTFImporter.cs +++ b/Editor/Scripts/GLTFImporter.cs @@ -110,7 +110,7 @@ private static void EnsureShadersAreLoaded() [SerializeField] internal bool _useSceneNameIdentifier = false; [Tooltip("Compress textures after import using the platform default settings. If you need more control, use a .gltf file instead.")] [SerializeField] internal GLTFImporterTextureCompressionQuality _textureCompression = GLTFImporterTextureCompressionQuality.None; - + [SerializeField, Multiline] internal string _gltfAsset = default; // for humanoid importer [SerializeField] internal bool m_OptimizeGameObjects = false; [SerializeField] internal HumanDescription m_HumanDescription = new HumanDescription(); @@ -959,7 +959,7 @@ private void CreateGLTFScene(GLTFImportContext context, out GameObject scene, scene = loader.LastLoadedScene; animationClips = loader.CreatedAnimationClips; - + _gltfAsset = loader.Root.Asset.ToString(true); importer = loader; } } diff --git a/Editor/Scripts/GLTFImporterInspector.cs b/Editor/Scripts/GLTFImporterInspector.cs index 34544ed22..72b879092 100644 --- a/Editor/Scripts/GLTFImporterInspector.cs +++ b/Editor/Scripts/GLTFImporterInspector.cs @@ -40,6 +40,7 @@ public override void OnEnable() AddTab(new GLTFAssetImporterTab(this, "Materials", MaterialInspectorGUI)); AddTab(new GLTFAssetImporterTab(this, "Used Extensions", ExtensionInspectorGUI)); + AddTab(new GLTFAssetImporterTab(this, "Info", AssetInfoInspectorGUI)); base.OnEnable(); } @@ -362,6 +363,28 @@ void ExtractAsset(T subAsset, bool importImmediately) EditorGUILayout.EndFoldoutHeaderGroup(); } + private void AssetInfoInspectorGUI() + { + var t = target as GLTFImporter; + if (!t) return; + var assetProp = serializedObject.FindProperty(nameof(GLTFImporter._gltfAsset)); + if (assetProp == null) + return; + + if (string.IsNullOrEmpty(t._gltfAsset)) + { + EditorGUILayout.LabelField("[ No informations included ]"); + return; + } + GUIStyle style = new GUIStyle(GUI.skin.label); + style.richText = true; + style.wordWrap = true; + EditorGUILayout.Space(); + + var rect = GUILayoutUtility.GetRect(new GUIContent(t._gltfAsset), style); + EditorGUI.SelectableLabel(rect, t._gltfAsset, style); + } + private void ExtensionInspectorGUI() { var t = target as GLTFImporter; diff --git a/Runtime/Plugins/GLTFSerialization/Schema/Asset.cs b/Runtime/Plugins/GLTFSerialization/Schema/Asset.cs index f855dc16d..62815d57d 100644 --- a/Runtime/Plugins/GLTFSerialization/Schema/Asset.cs +++ b/Runtime/Plugins/GLTFSerialization/Schema/Asset.cs @@ -1,4 +1,5 @@ using System; +using System.Text; using Newtonsoft.Json; namespace GLTF.Schema @@ -101,5 +102,39 @@ public override void Serialize(JsonWriter writer) writer.WriteEndObject(); } + + public override string ToString() + { + return ToString(false); + } + + public string ToString(bool richFormat) + { + string bStart = richFormat ? "" : ""; + string bEnd = richFormat ? "" : ""; + + var sb = new StringBuilder(); + if (!string.IsNullOrEmpty(Generator)) + sb.AppendLine($"{bStart}{nameof(Generator)}: {bEnd}{Generator}"); + + if (!string.IsNullOrEmpty(Version)) + sb.AppendLine($"{bStart}{nameof(Version)}: {bEnd}{Version}"); + + if (!string.IsNullOrEmpty(MinVersion)) + sb.AppendLine($"{bStart}{nameof(MinVersion)}: {bEnd}{MinVersion}"); + + if (!string.IsNullOrEmpty(Copyright)) + sb.AppendLine($"{bStart}{nameof(Copyright)}: {bEnd}{Copyright}"); + + if (Extras != null) + { + sb.AppendLine(""); + sb.AppendLine($"{bStart}Extras: {bEnd}"); + foreach (var extra in Extras) + sb.AppendLine(extra.ToString()); + } + + return sb.ToString(); + } } }